HTML Attributes

Attributes for HTML elements define additional meaning about the elements.

Attribute Belongs to Purpose
accept <input> Defines the type of files that the server accepts. This can be used when input type is file.
accept-charset <form> Defines character encoding to be used for the form submission.
accesskey Global Attributes Defines a shortcut key to focus an element. The shortcut can be triggered by pressing Alt and the shortcut key.
action <form> Defines URL to send the form data when the form is submitted
align Not supported in HTML 5. Defines the alignment according to surrounding elements. Use CSS instead
alt <area>, <img>, <input> Defines an alternate text for the element. This is displayed when the content of the element cannot be displayed.
async <Defines the script> Defines that the javaDefines the script to be executed asynchronously (only for external Defines the scripts).
autocomplete <form>, <input> Defines whether autocomplete be enabled for <form> or the <input> elements.
autofocus <button>, <input>, <keygen>, <select>, <textarea> Defines if the element should automatically get focus after page loads.
autoplay <audio>, <video> Defines whether audio/video will start playing after page loads.
bgcolor Not supported in HTML 5. Defines the background color of an element. Use CSS instead
border Not supported in HTML 5. Defines the width of the border of an element. Use CSS instead
challenge <keygen> Submit a challenge string to validate the <keygen> element.
charset <meta>, <Defines the script> Defines character encoding of the page or Defines the script.
checked <input>, <command> Defines that an <input> element (checkbox or radio) should be pre-selected when the page loads.
cite <blockquote>, <del>, <ins>, <q> Defines a URL that explains the quote or change.
class Global Attributes Defines single or multiple class names for the element. Class names are used to define styling of the element.
color Not supported in HTML 5. Defines the text color of an element. Use CSS instead
cols <textarea> Defines the number of columns of a text area.
colspan <td>, <th> Defines the number of columns a table cell should span.
content <meta> Defines a value associated with the http-equiv or name attribute.
contenteditable Global Attributes Defines whether the content of an element is editable or not
contextmenu Global Attributes Defines a context menu for an element. The context menu appears when a user right-clicks on the element.
controls <audio>, <video> Defines that default audio/video controls (play/pause) should be displayed.
coords <area> Defines a set of coordinates of the area.
data <object> Defines the URL of the resource.
data-* Global Attributes Defines custom data for an element. An element can contain one or more custom data.
datetime <del>, <ins>, <time> Defines the date and time associated with the element.
default <track> Defines that the track is to be enabled if the user's preferences do not indicate that another track would be more appropriate.
defer <Defines the script> Defines that the (external) Defines the script is executed when the page has finished loading.
dir Global Attributes Defines the direction of text for the content in an element.
dirname <input>, <textarea> Defines that the text direction will be submitted in the form.
disabled <button>, <fieldset>, <input>, <keygen>, <optgroup>, <option>, <select>, <textarea> Defines that the specified element/group of elements should be disabled.
download <a>, <area> Defines that the URL will be downloaded when a user clicks on the hyperlink.
draggable Global Attributes Defines whether an element can be dragged or not.
dropzone Global Attributes Defines what happens to the dragged data. The dragged data can be copied, moved, linked.
enctype <form> Defines encoding of the form data when the form (method = "POST") is submitted.
for <label>, <output> Defines the form element(s) a label/calculation is bound to.
form <button>, <fieldset>, <input>, <keygen>, <label>, <meter>, <object>, <output>, <select>, <textarea> Defines the form the element belongs to.
formaction <button>, <input> Defines URL of the form-data when a form is submitted. Only for type="submit".
headers <td>, <th> Defines the header cells a cell is related to.
height <canvas>, <embed>, <iframe>, <img>, <input>, <object>, <video> Defines the height of the element.
hidden Global Attributes Defines whether the element should be hidden or not. It could be the content within the element is written but is not relevant at the moment.
high <meter> Defines the range that is considered to be a high value.
href <a>, <area>, <base>, <link> Defines the URL the link is linking to.
hreflang <a>, <area>, <link> Defines the language of the URL of the link.
http-equiv <meta> Defines an HTTP header for the information/value of the content attribute.
id Global Attributes Defines a unique identifier for the element.
ismap <img> Defines an image as a server-side image-map.
keytype <keygen> Defines the type of key.
kind <track> Defines the kind of text track.
label <track>, <option>, <optgroup> Defines the title of the text track.
lang Global Attributes Defines the language of the content for the element.
list <input> Defines pre-defined options for an <input> element to suggest to the user.
loop <audio>, <video> Defines that the audio/video will repeat itself when finished.
low <meter> Defines the range that is considered to be a low value
manifest <html> Defines the address of the document's cache manifest for offline browsing.
max <input>, <meter>, <progress> Defines the maximum value.
maxlength <input>, <textarea> Defines the maximum character length allowed in an element.
media <a>, <area>, <link>, <source>, <style> Defines what media/device the linked document is optimized for.
method <form> Defines the HTTP method to use when sending form-data.
min <input>, <meter> Defines a minimum value.
multiple <input>, <select> Defines whether multiple values can be entered for email of file.
muted <video>, <audio> Defines that the audio output of the audio or video should be muted
name <button>, <fieldset>, <form>, <iframe>, <input>, <keygen>, <map>, <meta>, <object>, <output>, <param>, <select>, <textarea> Defines the name of the element.
novalidate <form> Defines that the form should not be validated when submitted.
onabort <audio>, <embed>, <img>, <object>, <video> Defines the Defines the script to run on abort.
onafterprint <body> Defines the script to run after the document is printed.
onbeforeprint <body> Defines the script to run before the document is printed.
onbeforeunload <body> Defines the script to run when the document is about to be unloaded.
onblur All visible elements. Defines the script to run when the element loses focus.
oncanplay <audio>, <embed>, <object>, <video> Defines the script to run when a file is ready to start playing (when it has buffered enough to begin).
oncanplaythrough <audio>, <video> Defines the script to run when a file can be played all the way to the end without pausing for buffering.
onchange All visible elements. Defines the script to run when the value of the element is changed.
onclick All visible elements. Defines the script to run when the element is being clicked.
oncontextmenu All visible elements. Defines the script to run when a context menu is triggered.
oncopy All visible elements. Defines the script to run when the content of the element is being copied.
oncuechange <track> Defines the script to run when the cue changes in a <track> element.
oncut All visible elements. Defines the script to run when the content of the element is being cut.
ondblclick All visible elements. Defines the script to run when the element is being double-clicked.
ondrag All visible elements. Defines the script to run at the end of a drag operation.
ondragend All visible elements. Defines the Defines the script to run at the end of a drag operation.
ondragenter All visible elements. Defines the script to run when an element has been dragged to a valid drop target
ondragleave All visible elements. Defines the script to run when an element leaves a valid drop target
ondragover All visible elements. Defines the script to run when an element is being dragged over a valid drop target
ondragstart All visible elements. Defines the script to run at the start of a drag operation
ondrop All visible elements. Defines the script to run when dragged element is being dropped
ondurationchange <audio>, <video> Defines the script to run when the length of the media changes
onemptied <audio>, <video> Defines the script to run when something bad happens and the file is suddenly disconnects.
onended <audio>, <video> Defines the script to run when the media has reach the end.
onerror <audio>, <body>, <embed>, <img>, <object>, <Defines the script>, <style>, <video> Defines the script to run when an error occurs.
onfocus All visible elements. Defines the script to run when the element gets focus.
onhashchange <body> Defines the script to run when there has been changes to the anchor part of the a URL.
oninput All visible elements. Defines the script to run when the element gets user input.
oninvalid All visible elements. Defines the script to run when the element is invalid.
onkeydown All visible elements. Defines the script to run when a user is pressing a key.
onkeypress All visible elements. Defines the script to run when a user presses a key.
onkeyup All visible elements. Defines the script to run when a user releases a key.
onload <body>, <iframe>, <img>, <input>, <link>, <script>, <style> Defines the script to run when the element is finished loading
onloadeddata <audio>, <video> Defines the script to run when media data is loaded.
onloadedmetadata <audio>, <video> Defines the script to run when meta data (like dimensions and duration) are loaded.
onloadstart <audio>, <video> Defines the script to run just as the file begins to load before anything is actually loaded.
onmousedown All visible elements. Defines the script to run when a mouse button is pressed down on an element.
onmousemove All visible elements. Defines the script to run as long as the  mouse pointer is moving over an element.
onmouseout All visible elements Defines the script to run when a mouse pointer moves ot of an element.
onmouseover All visible elements Defines the script to run when a mouse pointer moves over an element.
onmouseup All visible elements Defines the script to run when a mouse button is released over an element.
onmousewheel All visible elements Defines the script to run when a mouse wheel is being scrolled over an element.
onoffline <body> Defines the script to run when the browser starts to work offline.
ononline <body> Defines the script to run when the browser starts to work online.
onpagehide <body> Defines the script to run when a user navigates away from a page.
onpageshow <body> Defines the script to run when a user navigates to a page.
onpaste All visible elements Defines the script to run when the user pastes some content in an element.
onpause <audio>, <video> Defines the script to run when the media is paused either by the user or programmatically.
onplay <audio>, <video> Defines the script to run when the media is ready to start playing
onplaying <audio>, <video> Defines the script to run when the media actually has started playing.
onpopstate <body> Defines the script to run when the window's history changes.
onprogress <audio>, <video> Defines the script to run when the browser is in the process of getting the media data
onratechange <audio>, <video> Defines the script to run each time the playback rate changes (like when a user switches to a slow motion or fast forward mode).
onreset <form> Defines the script to run when a reset button in a form is clicked.
onresize <body> Defines the script to run when the browser window is being resized.
onscroll All visible elements Defines the script to run when an element's scrollbar is being scrolled.
onsearch <input> Defines the script to run when the user writes something in a search field.
onseeked <audio>, <video> Defines the script to run when the seeking attribute is set to false indicating that seeking has ended.
onseeking <audio>, <video> Defines the script to run when the seeking attribute is set to true indicating that seeking is active.
onselect All visible elements Defines the script to run when the element gets selected.
onshow <menu> Defines the script to run when a <menu> element is shown as a context menu.
onstalled <audio>, <video> Defines the script to run when the browser is unable to fetch the media data for whatever reason.
onstorage <body> Defines the script to run when a Web Storage area is updated.
onsubmit <form> Defines the script to run when a form is submitted
onsuspend <audio>, <video> Defines the script to run when fetching the media data is stopped before it is completely loaded for whatever reason.
ontimeupdate <audio>, <video> Defines the script to run when the playing position has changed (like when the user fast forwards to a different point in the media)
ontoggle <details> Defines the script to run when the user opens or closes the <details> element.
onunload <body> Defines the script to run when a page has unloaded.
onvolumechange <audio>, <video> Defines the script to run each time the volume is changed.
onwaiting <audio>, <video> Defines the script to run when the media has paused but is expected to resume.
onwheel All visible elements. Defines the script to run when the mouse wheel rolls up or down over an element.
open <details> Defines that the details should be visible (open) to the user.
optimum <meter> Defines what value is the optimal value for the gauge.
pattern <input> Defines a regular expression that an <input> element's value is checked against.
placeholder <input>, <textarea> Defines a short hint that describes the expected value of the element.
poster <video> Defines an image to be shown while the video is downloading, or until the user hits the play button.
preload <audio>, <video> Defines if and how the author thinks the audio/video should be loaded when the page loads.
readonly <input>, <textarea> Defines that the element is read-only
rel <a>, <area>, <link> Defines the relationship between the current document and the linked document.
required <input>, <select>, <textarea> Defines that the element must be filled out before submitting the form
reversed <ol> Defines that the list order should be reversed (5,4,3,...).
rows <textarea> Defines the visible number of lines in a text area.
rowspan <td>, <th> Defines the number of rows a table cell should span.
sandbox <iframe> Enables an extra set of restrictions for the content in an <iframe>.
scope <th> Defines whether a header cell is a header for a column, row, or group of columns or rows.
scoped <style> Defines that the styles only apply to this element's parent element and that element's child elements.
selected <option> Defines that an option should be pre-selected when the page loads.
shape <area> Defines the shape of the area
size <input>, <select> Defines the width, in characters (for <input>) or Defines the number of visible options (for <select>).
sizes <link> Defines the size of the linked resource
span <col>, <colgroup> Defines the number of columns to span
spellcheck Global Attributes Defines whether the element is to have its spelling and grammar checked or not.
src <audio>, <embed>, <iframe>, <img>, <input>, <Defines the script>, <source>, <track>, <video> Defines the URL of the media file
srcdoc <iframe> Defines the HTML content of the page to show in the <iframe>.
srclang <track> Defines the language of the track text data (required if kind="subtitles").
start <ol> Defines the start value of an ordered list.
step <input> Defines the legal number intervals for an input field.
style Global Attributes Defines an inline CSS style for an element.
tabindex Global Attributes Defines the tabbing order of an element.
target <a>, <area>, <base>, <form> Defines the target for where to open the linked document or where to submit the form.
title Global Attributes Defines extra information about an element.
translate Global Attributes Defines whether the content of an element should be translated or not.
type <button>, <embed>, <input>, <link>, <menu>, <object>, <script>, <source>, <style> Defines the type of element.
usemap <img>, <object> Defines an image as a client-side image-map.
value <button>, <input>, <li>, <option>, <meter>, <progress>, <param> Defines the value of the element.
width <canvas>, <embed>, <iframe>, <img>, <input>, <object>, <video> Defines the width of the element.
wrap <textarea> Defines whether newline characters in a text area should be submitted in a form.