HTML Attributes
Common HTML attributes, the elements they apply to, and what they do.
54 of 54
| Attribute | Applies to | Description |
|---|---|---|
| alt | img, area, input | Alternative text for an image, for people who cannot see it. |
| href | a, area, link, base | The address a link points to. |
| src | img, script, audio, video, iframe, source | The address of an external file: image, script, media. |
| id | all elements | A unique identifier for an element. |
| class | all elements | One or more class names, for CSS and JavaScript. |
| style | all elements | Inline CSS for one element. |
| title | all elements | Extra information, shown as a tooltip. |
| lang | all elements | The language of the content. |
| hidden | all elements | Hides an element. |
| tabindex | all elements | Controls the keyboard tab order. |
| contenteditable | all elements | Makes content editable by the user. |
| draggable | all elements | Whether an element can be dragged. |
| data-* | all elements | Custom data stored on an element. |
| target | a, form, area | Where to open a link. |
| rel | a, link | Relationship of the linked file to this page. |
| download | a, area | Downloads the linked file instead of opening it. |
| width | img, canvas, video, iframe, table | The width of an element. |
| height | img, canvas, video, iframe | The height of an element. |
| loading | img, iframe | Lazy-load images or iframes. |
| controls | audio, video | Shows playback controls. |
| autoplay | audio, video | Starts playing automatically. |
| loop | audio, video | Repeats the media. |
| type | input, button, script, source | The type of an input or a file. |
| name | input, select, textarea, button, form | The name of a form field, sent with the form. |
| value | input, button, option, li | The value of a form control. |
| placeholder | input, textarea | A hint shown in an empty field. |
| required | input, select, textarea | The field must be filled in. |
| disabled | input, button, select, textarea | Disables a control. |
| readonly | input, textarea | The value cannot be edited. |
| checked | input | Pre-selects a checkbox or radio button. |
| selected | option | Pre-selects an option. |
| multiple | input, select | Allows several values. |
| maxlength | input, textarea | The maximum number of characters. |
| min | input, meter, progress | The minimum value. |
| max | input, meter, progress | The maximum value. |
| step | input | The step between valid numbers. |
| pattern | input | A regular expression the value must match. |
| autofocus | input, button, select, textarea | Focuses the element when the page loads. |
| autocomplete | input, form, select, textarea | Lets the browser fill the field in. |
| for | label, output | Connects a label to a control by id. |
| action | form | Where a form is sent. |
| method | form | How a form is sent: get or post. |
| colspan | td, th | How many columns a cell spans. |
| rowspan | td, th | How many rows a cell spans. |
| charset | meta, script | The character encoding. |
| async | script | Loads a script without blocking the page. |
| defer | script | Runs a script after the page is parsed. |
| sandbox | iframe | Restricts what an iframe may do. |
| srcdoc | iframe | HTML content for an iframe. |
| open | details, dialog | Whether a details or dialog is open. |
| role | all elements | The ARIA role, for accessibility. |
| aria-label | all elements | An accessible name for an element. |
| dir | all elements | The text direction. |
| spellcheck | all elements | Turns spell checking on or off. |