HTML Attributes
HTML Global Attributes
Global attributes are attributes that can be applied to any HTML element to set common properties.
What Are Global Attributes?
Global attributes are a group of attributes that are valid on every HTML element, regardless of the element's specific purpose. They handle universal concerns like identification, styling, language and interactivity, so you can use the same attribute names consistently across your markup.
Example
<div id="hero" class="banner" lang="en"
title="Welcome" data-role="intro" tabindex="0">
Welcome to MyInternships.in
</div>Common Global Attributes
| Attribute | Description |
|---|---|
| id | A document-unique identifier for the element |
| class | Space-separated list of class names for CSS and scripting |
| style | Inline CSS declarations applied to the element |
| title | Advisory information shown as a tooltip on hover |
| lang | Language of the element's content, e.g. en, hi, mr |
| dir | Text direction: ltr, rtl or auto |
| hidden | Boolean attribute that hides the element from rendering |
| tabindex | Controls keyboard tab order and focusability |
| contenteditable | Whether the element's content can be edited by the user |
| draggable | Whether the element can be dragged (true or false) |
| data-* | Custom author-defined attributes for storing extra data |
| accesskey | Keyboard shortcut hint to focus or activate the element |
| spellcheck | Whether the browser should check spelling and grammar |
💡
Use data-* attributes to attach custom information to elements for JavaScript, e.g. data-job-id="42". Access them in script via the element's dataset property (element.dataset.jobId).
