WeCodeAcademy

HTML Attributes

Common HTML attributes, the elements they apply to, and what they do.

54 of 54
AttributeApplies toDescription
altimg, area, inputAlternative text for an image, for people who cannot see it.
hrefa, area, link, baseThe address a link points to.
srcimg, script, audio, video, iframe, sourceThe address of an external file: image, script, media.
idall elementsA unique identifier for an element.
classall elementsOne or more class names, for CSS and JavaScript.
styleall elementsInline CSS for one element.
titleall elementsExtra information, shown as a tooltip.
langall elementsThe language of the content.
hiddenall elementsHides an element.
tabindexall elementsControls the keyboard tab order.
contenteditableall elementsMakes content editable by the user.
draggableall elementsWhether an element can be dragged.
data-*all elementsCustom data stored on an element.
targeta, form, areaWhere to open a link.
rela, linkRelationship of the linked file to this page.
downloada, areaDownloads the linked file instead of opening it.
widthimg, canvas, video, iframe, tableThe width of an element.
heightimg, canvas, video, iframeThe height of an element.
loadingimg, iframeLazy-load images or iframes.
controlsaudio, videoShows playback controls.
autoplayaudio, videoStarts playing automatically.
loopaudio, videoRepeats the media.
typeinput, button, script, sourceThe type of an input or a file.
nameinput, select, textarea, button, formThe name of a form field, sent with the form.
valueinput, button, option, liThe value of a form control.
placeholderinput, textareaA hint shown in an empty field.
requiredinput, select, textareaThe field must be filled in.
disabledinput, button, select, textareaDisables a control.
readonlyinput, textareaThe value cannot be edited.
checkedinputPre-selects a checkbox or radio button.
selectedoptionPre-selects an option.
multipleinput, selectAllows several values.
maxlengthinput, textareaThe maximum number of characters.
mininput, meter, progressThe minimum value.
maxinput, meter, progressThe maximum value.
stepinputThe step between valid numbers.
patterninputA regular expression the value must match.
autofocusinput, button, select, textareaFocuses the element when the page loads.
autocompleteinput, form, select, textareaLets the browser fill the field in.
forlabel, outputConnects a label to a control by id.
actionformWhere a form is sent.
methodformHow a form is sent: get or post.
colspantd, thHow many columns a cell spans.
rowspantd, thHow many rows a cell spans.
charsetmeta, scriptThe character encoding.
asyncscriptLoads a script without blocking the page.
deferscriptRuns a script after the page is parsed.
sandboxiframeRestricts what an iframe may do.
srcdociframeHTML content for an iframe.
opendetails, dialogWhether a details or dialog is open.
roleall elementsThe ARIA role, for accessibility.
aria-labelall elementsAn accessible name for an element.
dirall elementsThe text direction.
spellcheckall elementsTurns spell checking on or off.