HTML Attributes
HTML Attributes Complete Reference
This is an alphabetical quick-reference of the most common HTML attributes and the elements they apply to.
HTML Attributes Reference
The table below lists frequently used HTML attributes along with the elements they belong to and a short description of what each does. Global attributes such as id, class and style apply to all elements, while others are specific to particular tags.
Use this as a lookup table. For a deeper explanation of any single attribute, see its dedicated topic in the Learn HTML attributes section.
| Attribute | Belongs to | Description |
|---|---|---|
| accept | <input> | File types a file-upload control should accept |
| accept-charset | <form> | Character encodings the server accepts on submit |
| accesskey | Global | Keyboard shortcut to focus or activate the element |
| action | <form> | URL that processes the submitted form data |
| alt | <img>, <area>, <input> | Alternative text describing an image |
| async | <script> | Load an external script asynchronously |
| autocomplete | <form>, <input>, <select>, <textarea> | Whether the browser may autofill the field |
| autofocus | <button>, <input>, <select>, <textarea> | Focus the element automatically on load |
| autoplay | <audio>, <video> | Start playing media as soon as it can |
| charset | <meta>, <script> | Character encoding of the document or script |
| checked | <input> | Pre-select a checkbox or radio button |
| class | Global | Class names used by CSS and JavaScript |
| cols | <textarea> | Visible width of a textarea in characters |
| colspan | <td>, <th> | Number of columns a table cell spans |
| contenteditable | Global | Whether the element's content is editable |
| controls | <audio>, <video> | Show default media playback controls |
| data-* | Global | Custom author-defined data attributes |
| dir | Global | Text direction: ltr, rtl or auto |
| disabled | Form elements | Disable the control so it cannot be used |
| draggable | Global | Whether the element can be dragged |
| for | <label>, <output> | Associates a label with a form control's id |
| href | <a>, <link>, <area>, <base> | URL of a linked resource |
| hidden | Global | Hide the element from rendering |
| id | Global | Unique identifier for the element |
| lang | Global | Language of the element's content |
| loading | <img>, <iframe> | Lazy or eager loading of the resource |
| max | <input>, <meter>, <progress> | Maximum allowed value |
| maxlength | <input>, <textarea> | Maximum number of characters allowed |
| method | <form> | HTTP method used to submit the form (get or post) |
| min | <input>, <meter> | Minimum allowed value |
| multiple | <input>, <select> | Allow selecting or entering multiple values |
| name | Form elements, <meta>, etc. | Name of the control, used when submitting data |
| pattern | <input> | Regular expression the value must match |
| placeholder | <input>, <textarea> | Hint text shown when the field is empty |
| readonly | <input>, <textarea> | Make the field read-only |
| rel | <a>, <link>, <area> | Relationship of the linked resource |
| required | Form elements | Field must be filled before submitting |
| rows | <textarea> | Visible number of text lines |
| rowspan | <td>, <th> | Number of rows a table cell spans |
| selected | <option> | Pre-select an option in a dropdown |
| src | <img>, <script>, <iframe>, <audio>, <video> | URL of the embedded resource |
| style | Global | Inline CSS applied to the element |
| tabindex | Global | Keyboard tab order and focusability |
| target | <a>, <form>, <base> | Where to open the linked document, e.g. _blank |
| title | Global | Advisory tooltip text |
| type | <input>, <button>, <script>, etc. | The type of control, script or media |
| value | <input>, <option>, <button> | The current or initial value of the element |
| width | <img>, <canvas>, <video>, etc. | Intrinsic width of the element in pixels |
Attributes marked Global can be used on any element. Prefer semantic HTML and use these attributes to enhance behaviour and accessibility rather than replacing proper element choice.
