HTML Attributes Reference
Here is a list of all the HTML attributes.
Attribute | Description | Belongs To | Category | HTML5 | HTML4 | XHTML |
accept | Specifies the types of files that the server accepts (only for type="file") | <input> | Yes | |||
accept-charset | Specifies the character encodings that are to be used for the form submission | <form> | Yes | |||
accesskey | Specifies a shortcut key to activate/focus an element | Global Attributes | Global Attributes | Yes | ||
action | Specifies where to send the form data when a form is submitted | <form> | Yes | |||
align | Specifies the alignment according to surrounding elements. Use CSS instead | Not supported in HTML 5. | No | |||
alt | Specifies an alternate text when the original element fails to display | <area>, <img>, <input> | Yes | |||
async | Specifies that the script is executed asynchronously (only for external scripts) | <script> | Yes | |||
autocomplete | Specifies whether the <form> or the <input> element should have autocomplete enabled | <form>, <input> | Yes | |||
autofocus | Specifies that the element should automatically get focus when the page loads | Yes | ||||
autoplay | Specifies that the audio/video will start playing as soon as it is ready | <audio>, <video> | Yes | |||
bgcolor | Specifies the background color of an element. Use CSS instead | Not supported in HTML 5. | No | |||
border | Specifies the width of the border of an element. Use CSS instead | Not supported in HTML 5. | No | |||
charset | Specifies the character encoding | <meta>, <script> | Yes | |||
checked | Specifies that an <input> element should be pre-selected when the page loads (for type="checkbox" or type="radio") | <input> | Yes | |||
cite | Specifies a URL which explains the quote/deleted/inserted text | Yes | ||||
class | Specifies one or more class names for an element (refers to a class in a style sheet) | Global Attributes | Global Attributes | Yes | ||
color | Specifies the text color of an element. Use CSS instead | Not supported in HTML 5. | No | |||
cols | Specifies the visible width of a text area | <textarea> | Yes | |||
colspan | Specifies the number of columns a table cell should span | <td>, <th> | Yes | |||
content | Gives the value associated with the http-equiv or name attribute | <meta> | Yes | |||
contenteditable | Specifies whether the content of an element is editable or not | Global Attributes | Global Attributes | Yes | ||
controls | Specifies that audio/video controls should be displayed (such as a play/pause button etc) | <audio>, <video> | Yes | |||
coords | Specifies the coordinates of the area | <area> | Yes | |||
data | Specifies the URL of the resource to be used by the object | <object> | Yes | |||
data-* | Used to store custom data private to the page or application | Global Attributes | Global Attributes | Yes | ||
datetime | Specifies the date and time | <del>, <ins>, <time> | Yes | |||
default | Specifies that the track is to be enabled if the users preferences do not indicate that another track would be more appropriate | <track> | Yes | |||
defer | Specifies that the script is executed when the page has finished parsing (only for external scripts) | <script> | Yes | |||
dir | Specifies the text direction for the content in an element | Global Attributes | Global Attributes | Yes | ||
dirname | Specifies that the text direction will be submitted | <input>, <textarea> | Yes | |||
disabled | Specifies that the specified element/group of elements should be disabled | Yes | ||||
download | Specifies that the target will be downloaded when a user clicks on the hyperlink | <a>, <area> | Yes | |||
draggable | Specifies whether an element is draggable or not | Global Attributes | Global Attributes | Yes | ||
enctype | Specifies how the form-data should be encoded when submitting it to the server (only for method="post") | <form> | Yes | |||
for | Specifies which form element(s) a label/calculation is bound to | <label>, <output> | Yes | |||
form | Specifies the name of the form the element belongs to | Yes | ||||
formaction | Specifies where to send the form-data when a form is submitted. Only for type="submit" | <button>, <input> | Yes | |||
headers | Specifies one or more headers cells a cell is related to | <td>, <th> | Yes | |||
height | Specifies the height of the element | Yes | ||||
hidden | Specifies that an element is not yet, or is no longer, relevant | Global Attributes | Global Attributes | Yes | ||
high | Specifies the range that is considered to be a high value | <meter> | Yes | |||
href | Specifies the URL of the page the link goes to | Yes | ||||
hreflang | Specifies the language of the linked document | Yes | ||||
http-equiv | Provides an HTTP header for the information/value of the content attribute | <meta> | Yes | |||
id | Specifies a unique id for an element | Global Attributes | Global Attributes | Yes | ||
ismap | Specifies an image as a server-side image map | <img> | Yes | |||
kind | Specifies the kind of text track | <track> | Yes | |||
label | Specifies the title of the text track | Yes | ||||
lang | Specifies the language of the element content | Global Attributes | Global Attributes | Yes | ||
list | Refers to a <datalist> element that contains pre-defined options for an <input> element | <input> | Yes | |||
loop | Specifies that the audio/video will start over again, every time it is finished | <audio>, <video> | Yes | |||
low | Specifies the range that is considered to be a low value | <meter> | Yes | |||
max | Specifies the maximum value | Yes | ||||
maxlength | Specifies the maximum number of characters allowed in an element | <input>, <textarea> | Yes | |||
media | Specifies what media/device the linked document is optimized for | Yes | ||||
method | Specifies the HTTP method to use when sending form-data | <form> | Yes | |||
min | Specifies a minimum value | <input>, <meter> | Yes | |||
multiple | Specifies that a user can enter more than one value | <input>, <select> | Yes | |||
muted | Specifies that the audio output of the video should be muted | <video>, <audio> | Yes | |||
name | Specifies the name of the element | Yes | ||||
novalidate | Specifies that the form should not be validated when submitted | <form> | Yes | |||
onabort | Script to be run on abort | Event Attributes | Yes | |||
onafterprint | Script to be run after the document is printed | <body> | Event Attributes | Yes | ||
onbeforeprint | Script to be run before the document is printed | <body> | Event Attributes | Yes | ||
onbeforeunload | Script to be run when the document is about to be unloaded | <body> | Event Attributes | Yes | ||
onblur | Script to be run when the element loses focus | All visible elements. | Event Attributes | Yes | ||
oncanplay | Script to be run when a file is ready to start playing (when it has buffered enough to begin) | Event Attributes | Yes | |||
oncanplaythrough | Script to be run when a file can be played all the way to the end without pausing for buffering | <audio>, <video> | Event Attributes | Yes | ||
onchange | Script to be run when the value of the element is changed | All visible elements. | Event Attributes | Yes | ||
onclick | Script to be run when the element is being clicked | All visible elements. | Event Attributes | Yes | ||
oncontextmenu | Script to be run when a context menu is triggered | All visible elements. | Event Attributes | Yes | ||
oncopy | Script to be run when the content of the element is being copied | All visible elements. | Event Attributes | Yes | ||
oncuechange | Script to be run when the cue changes in a <track> element | <track> | Event Attributes | Yes | ||
oncut | Script to be run when the content of the element is being cut | All visible elements. | Event Attributes | Yes | ||
ondblclick | Script to be run when the element is being double-clicked | All visible elements. | Event Attributes | Yes | ||
ondrag | Script to be run when the element is being dragged | All visible elements. | Event Attributes | Yes | ||
ondragend | Script to be run at the end of a drag operation | All visible elements. | Event Attributes | Yes | ||
ondragenter | Script to be run when an element has been dragged to a valid drop target | All visible elements. | Event Attributes | Yes | ||
ondragleave | Script to be run when an element leaves a valid drop target | All visible elements. | Event Attributes | Yes | ||
ondragover | Script to be run when an element is being dragged over a valid drop target | All visible elements. | Event Attributes | Yes | ||
ondragstart | Script to be run at the start of a drag operation | All visible elements. | Event Attributes | Yes | ||
ondrop | Script to be run when dragged element is being dropped | All visible elements. | Event Attributes | Yes | ||
ondurationchange | Script to be run when the length of the media changes | <audio>, <video> | Event Attributes | Yes | ||
onemptied | Script to be run when something bad happens and the file is suddenly unavailable (like unexpectedly disconnects) | <audio>, <video> | Event Attributes | Yes | ||
onended | Script to be run when the media has reach the end (a useful event for messages like "thanks for listening") | <audio>, <video> | Event Attributes | Yes | ||
onerror | Script to be run when an error occurs | Event Attributes | Yes | |||
onfocus | Script to be run when the element gets focus | All visible elements. | Event Attributes | Yes | ||
onhashchange | Script to be run when there has been changes to the anchor part of the a URL | <body> | Event Attributes | Yes | ||
oninput | Script to be run when the element gets user input | All visible elements. | Event Attributes | Yes | ||
oninvalid | Script to be run when the element is invalid | All visible elements. | Event Attributes | Yes | ||
onkeydown | Script to be run when a user is pressing a key | All visible elements. | Event Attributes | Yes | ||
onkeypress | Script to be run when a user presses a key | All visible elements. | Event Attributes | Yes | ||
onkeyup | Script to be run when a user releases a key | All visible elements. | Event Attributes | Yes | ||
onload | Script to be run when the element is finished loading | Event Attributes | Yes | |||
onloadeddata | Script to be run when media data is loaded | <audio>, <video> | Event Attributes | Yes | ||
onloadedmetadata | Script to be run when meta data (like dimensions and duration) are loaded | <audio>, <video> | Event Attributes | Yes | ||
onloadstart | Script to be run just as the file begins to load before anything is actually loaded | <audio>, <video> | Event Attributes | Yes | ||
onmousedown | Script to be run when a mouse button is pressed down on an element | All visible elements. | Event Attributes | Yes | ||
onmousemove | Script to be run as long as the mouse pointer is moving over an element | All visible elements. | Event Attributes | Yes | ||
onmouseout | Script to be run when a mouse pointer moves out of an element | All visible elements. | Event Attributes | Yes | ||
onmouseover | Script to be run when a mouse pointer moves over an element | All visible elements. | Event Attributes | Yes | ||
onmouseup | Script to be run when a mouse button is released over an element | All visible elements. | Event Attributes | Yes | ||
onmousewheel | Script to be run when a mouse wheel is being scrolled over an element | All visible elements. | Event Attributes | Yes | ||
onoffline | Script to be run when the browser starts to work offline | <body> | Event Attributes | Yes | ||
ononline | Script to be run when the browser starts to work online | <body> | Event Attributes | Yes | ||
onpagehide | Script to be run when a user navigates away from a page | <body> | Event Attributes | Yes | ||
onpageshow | Script to be run when a user navigates to a page | <body> | Event Attributes | Yes | ||
onpaste | Script to be run when the user pastes some content in an element | All visible elements. | Event Attributes | Yes | ||
onpause | Script to be run when the media is paused either by the user or programmatically | <audio>, <video> | Event Attributes | Yes | ||
onplay | Script to be run when the media has started playing | <audio>, <video> | Event Attributes | Yes | ||
onplaying | Script to be run when the media has started playing | <audio>, <video> | Event Attributes | Yes | ||
onpopstate | Script to be run when the window history changes. | <body> | Event Attributes | Yes | ||
onprogress | Script to be run when the browser is in the process of getting the media data | <audio>, <video> | Event Attributes | Yes | ||
onratechange | Script to be run each time the playback rate changes (like when a user switches to a slow motion or fast forward mode). | <audio>, <video> | Event Attributes | Yes | ||
onreset | Script to be run when a reset button in a form is clicked. | <form> | Event Attributes | Yes | ||
onresize | Script to be run when the browser window is being resized. | <body> | Event Attributes | Yes | ||
onscroll | Script to be run when an element scrollbar is being scrolled | All visible elements. | Event Attributes | Yes | ||
onsearch | Script to be run when the user writes something in a search field (for <input="search">) | <input> | Event Attributes | Yes | ||
onseeked | Script to be run when the seeking attribute is set to false indicating that seeking has ended | <audio>, <video> | Event Attributes | Yes | ||
onseeking | Script to be run when the seeking attribute is set to true indicating that seeking is active | <audio>, <video> | Event Attributes | Yes | ||
onselect | Script to be run when the element gets selected | All visible elements. | Event Attributes | Yes | ||
onstalled | Script to be run when the browser is unable to fetch the media data for whatever reason | <audio>, <video> | Event Attributes | Yes | ||
onstorage | Script to be run when a Web Storage area is updated | <body> | Event Attributes | Yes | ||
onsubmit | Script to be run when a form is submitted | <form> | Event Attributes | Yes | ||
onsuspend | Script to be run when fetching the media data is stopped before it is completely loaded for whatever reason | <audio>, <video> | Event Attributes | Yes | ||
ontimeupdate | Script to be run when the playing position has changed (like when the user fast forwards to a different point in the media) | <audio>, <video> | Event Attributes | Yes | ||
ontoggle | Script to be run when the user opens or closes the <details> element | <details> | Event Attributes | Yes | ||
onunload | Script to be run when a page has unloaded (or the browser window has been closed) | <body> | Event Attributes | Yes | ||
onvolumechange | Script to be run each time the volume of a video/audio has been changed | <audio>, <video> | Event Attributes | Yes | ||
onwaiting | Script to be run when the media has paused but is expected to resume (like when the media pauses to buffer more data) | <audio>, <video> | Event Attributes | Yes | ||
onwheel | Script to be run when the mouse wheel rolls up or down over an element | All visible elements. | Event Attributes | Yes | ||
open | Specifies that the details should be visible (open) to the user | <details> | Yes | |||
optimum | Specifies what value is the optimal value for the gauge | <meter> | Yes | |||
pattern | Specifies a regular expression that an <input> element value is checked against | <input> | Yes | |||
placeholder | Specifies a short hint that describes the expected value of the element | <input>, <textarea> | Yes | |||
poster | Specifies an image to be shown while the video is downloading, or until the user hits the play button | <video> | Yes | |||
preload | Specifies if and how the author thinks the audio/video should be loaded when the page loads | <audio>, <video> | Yes | |||
readonly | Specifies that the element is read-only | <input>, <textarea> | Yes | |||
rel | Specifies the relationship between the current document and the linked document | Yes | ||||
required | Specifies that the element must be filled out before submitting the form | Yes | ||||
reversed | Specifies that the list order should be descending (9,8,7...) | <ol> | Yes | |||
rows | Specifies the visible number of lines in a text area | <textarea> | Yes | |||
rowspan | Specifies the number of rows a table cell should span | <td>, <th> | Yes | |||
sandbox | Enables an extra set of restrictions for the content in an <iframe> | <iframe> | Yes | |||
scope | Specifies whether a header cell is a header for a column, row, or group of columns or rows | <th> | Yes | |||
selected | Specifies that an option should be pre-selected when the page loads | <option> | Yes | |||
shape | Specifies the shape of the area | <area> | Yes | |||
size | Specifies the width, in characters (for <input>) or specifies the number of visible options (for <select>) | <input>, <select> | Yes | |||
sizes | Specifies the size of the linked resource | Yes | ||||
span | Specifies the number of columns to span | <col>, <colgroup> | Yes | |||
spellcheck | Specifies whether the element is to have its spelling and grammar checked or not | Global Attributes | Global Attributes | Yes | ||
src | Specifies the URL of the media file | Yes | ||||
srcdoc | Specifies the HTML content of the page to show in the <iframe> | <iframe> | Yes | |||
srclang | Specifies the language of the track text data (required if kind="subtitles") | <track> | Yes | |||
srcset | Specifies the URL of the image to use in different situations | <img>, <source> | Yes | |||
start | Specifies the start value of an ordered list | <ol> | Yes | |||
step | Specifies the legal number intervals for an input field | <input> | Yes | |||
style | Specifies an inline CSS style for an element | Global Attributes | Global Attributes | Yes | ||
tabindex | Specifies the tabbing order of an element | Global Attributes | Global Attributes | Yes | ||
target | Specifies the target for where to open the linked document or where to submit the form | Yes | ||||
title | Specifies extra information about an element | Global Attributes | Global Attributes | Yes | ||
translate | Specifies whether the content of an element should be translated or not | Global Attributes | Global Attributes | Yes | ||
type | Specifies the type of element | Yes | ||||
usemap | Specifies an image as a client-side image map | <img>, <object> | Yes | |||
value | Specifies the value of the element | Yes | ||||
width | Specifies the width of the element | Yes | ||||
wrap | Specifies how the text in a text area is to be wrapped when submitted in a form | <textarea> | Yes |
Examples
Overall
We now know the complete list of all HTML attributes.