Attributes
HTML attributes define an element’s behavior and appearance, using a key-value structure (e.g., attribute="value"). They enhance customization, making web pages more interactive and accessible.
HTML Attribute Reference
The table below lists HTML attributes and the elements they can be used with:
| Attribute | Belongs to | Description |
|---|---|---|
accept | <input> | Specifies the file types accepted by the server (only for type="file"). |
accept-charset | <form> | Specifies the character encoding used for form submission. |
accesskey | *Global Attributes* | Defines a shortcut key for activating an element. |
action | <form> | Specifies the URL to send form data when a form is submitted. |
align | Not supported in HTML5 | Aligns text according to surrounding elements. |
alt | <img>, <area> | Provides alternative text for an image. |
async | <script> | Specifies that the script runs asynchronously. |
autocapitalize | *Global Attributes* | Controls automatic capitalization. |
autocomplete | <form>, <input> | Enables or disables form autofill. |
autofocus | <button>, <input>, <select>, <textarea> | Automatically focuses an element when the page loads. |
autoplay | <audio>, <video> | Specifies whether audio/video starts playing automatically. |
border | Not supported in HTML5 | Defines a border around an element. |
charset | <meta> | Specifies character encoding. |
checked | <input> | Pre-selects an input field (for checkboxes or radio buttons). |
cite | <blockquote>, <q>, <del>, <ins> | Specifies a URL for a quote or reference. |
class | *Global Attributes* | Assigns one or more class names to an element. |
color | Not supported in HTML5 | Sets text color. |
cols | <textarea> | Defines the number of text columns. |
colspan | <th>, <td> | Specifies the number of columns a cell should span. |
content | <meta> | Defines metadata content. |
contenteditable | *Global Attributes* | Indicates whether an element is editable. |
controls | <audio>, <video> | Displays playback controls. |
coords | <area> | Specifies the coordinates for an image map. |
data | <object> | Defines the URL of an embedded resource. |
datetime | <del>, <ins>, <time> | Specifies date and time. |
default | <track> | Indicates the default track in a media file. |
defer | <script> | Defers script execution until after the document loads. |
dir | *Global Attributes* | Specifies text direction. |
dirname | <input>, <textarea> | Sends text direction in form submission. |
disabled | <button>, <fieldset>, <input>, <optgroup>, <option>, <select>, <textarea> | Disables an input field. |
download | <a> | Specifies that a file should be downloaded when clicking a link. |
draggable | *Global Attributes* | Defines whether an element is draggable. |
enctype | <form> | Specifies encoding type for form submission. |
for | <label>, <output> | Associates an element with a control. |
form | <button>, <fieldset>, <input>, <label>, <meter>, <object>, <output>, <progress>, <select>, <textarea> | Associates an element with a form. |