HTML reference
Every element, attribute and accessibility pattern you reach for, with runnable examples.
HTML describes the meaning of content. Use the smallest element that carries the right meaning, keep the document outline readable, and add ARIA only when native semantics cannot do the job.
Work through the guided lesson, then test yourself with a challenge.
Open courseDocument structure
<!doctype html>
<!doctype html>Declares standards mode. It must be the very first thing in the document, before <html>.
Open entrybase
<base href="https://example.com/">Sets a base URL for every relative link and resource in the document. Use it once, at most.
Open entrybody
<body>…</body>All visible page content lives here. A page should have exactly one body.
Open entryhead
<head>…</head>Holds metadata: the title, character encoding, styles, scripts and social preview tags. Nothing here is rendered directly.
Open entryhtml
<html lang="en">…</html>The document root. The lang attribute tells screen readers, search engines and translators which language the content is in.
Open entrylink
<link rel="stylesheet" href="styles.css">Connects the document to an external resource: stylesheets, icons, font preloads, canonical URLs and alternate feeds.
Open entrymeta charset
<meta charset="utf-8">Declares the character encoding. UTF-8 covers every language and emoji; it should appear in the first 1024 bytes of the document.
Open entrymeta description
<meta name="description" content="…">A short summary search engines may show under the title. It does not affect ranking directly but affects click-through.
Open entrymeta robots
<meta name="robots" content="noindex">Controls indexing and link following for a page. Use it to keep private or duplicate pages out of search results.
Open entrymeta viewport
<meta name="viewport" content="width=device-width, initial-scale=1">Makes the layout match the device width on mobile. Without it phones render the page at a desktop width and shrink it.
Open entrynoscript
<noscript>…</noscript>Content shown when JavaScript is disabled or fails. Use it for a short explanation, not for duplicating the whole app.
Open entryscript
<script src="app.js" defer></script>Loads or embeds JavaScript. Use defer for scripts that depend on the DOM and type="module" for modern module code.
Open entrystyle (element)
<style>…</style>Embeds CSS directly in the document. Fine for a single page or a demo; link a stylesheet when styles are shared.
Open entrytitle
<title>Page name</title>The page title shown in the tab, search results and screen-reader announcements. Use one per page and make it specific.
Open entryForm and input attributes
accept
accept="image/*"Filters the file types a file input offers.
Open entryaccept-charset
accept-charset="UTF-8"The character encodings the server accepts for the form.
Open entryaction
action="/subscribe"The URL that receives a submitted form.
Open entryautocomplete
autocomplete="email"Tells the browser what kind of data the field expects so autofill works correctly.
Open entrycapture
capture="environment"Asks a mobile device to capture a new photo or video directly.
Open entrychecked
checkedPreselects a checkbox or radio button.
Open entrycols
cols="40"The visible width of a textarea in characters.
Open entrydirname
dirname="direction"Submits the text direction of an input or textarea with its value.
Open entrydisabled
disabledTurns off a control. Disabled controls are not submitted and are removed from the tab order.
Open entryenctype
enctype="multipart/form-data"The encoding for form data. File uploads require multipart/form-data.
Open entryform (attribute)
form="signup"Associates a control with a form elsewhere in the document.
Open entryformaction
formaction="/preview"Overrides the form action for the button that submits it.
Open entryformmethod
formmethod="get"Overrides the form method for one submit button.
Open entryformnovalidate
formnovalidateSkips validation for a specific submit button, such as a save-draft action.
Open entryformtarget
formtarget="_blank"Opens the form response in a new browsing context for one button.
Open entrylist (attribute)
list="languages"Connects an input to a datalist of suggested values.
Open entrymax
max="10"The maximum value for number, range and date inputs. It also caps the latest selectable date.
Open entrymaxlength
maxlength="280"The maximum number of characters for text inputs and textareas.
Open entrymethod
method="post"The HTTP method for form submission. Use post for changes and get for searches.
Open entrymin
min="0"The minimum value for number, range and date inputs.
Open entryminlength
minlength="8"The minimum number of characters for text inputs and textareas.
Open entrymultiple
multipleAllows more than one value in a select or more than one file in a file input.
Open entryname (attribute)
name="email"The field name sent to the server. A control without a name is not submitted.
Open entrynovalidate
novalidateDisables the browser’s built-in form validation when submitting.
Open entrypattern
pattern="[A-Za-z]+"A regular expression the field value must match. Always pair it with a visible hint.
Open entryplaceholder
placeholder="you@example.com"A format hint inside an empty field. It is not a label and disappears on input.
Open entryreadonly
readonlyPrevents editing but still submits the value and keeps it focusable.
Open entryrequired
requiredRejects submission while the field is empty.
Open entryrows
rows="4"The visible number of text lines in a textarea.
Open entryselected
selectedPreselects an option in a select element.
Open entrysize
size="20"The visible width of a text input in characters.
Open entrystep
step="0.5"The increment used by number and range inputs.
Open entryvalue
value="Ada"The initial or current value of a form control.
Open entrywrap
wrap="hard"Whether textarea line breaks are submitted: soft or hard.
Open entryForms and controls
button
<button type="button">…</button>A clickable control. Set type explicitly: submit inside a form, button everywhere else.
Open entrydatalist
<datalist id="…">…</datalist>Provides suggested values for an input while still allowing free text.
Open entryfieldset
<fieldset>…</fieldset>Groups related controls, especially radio buttons.
Open entryform
<form action="…" method="post">…</form>Collects user input and submits it. Always pair inputs with labels and choose the right input type.
Open entryinput
<input type="…" name="…" id="…">A single-line control. The type decides validation, keyboard and autofill behaviour.
Open entryinput types
type="email | password | number | date | checkbox"Choosing the correct type gives free validation, mobile keyboards and better autofill.
Open entrylabel
<label for="…">…</label>An accessible caption for a form control. Clicking the label focuses the control.
Open entrylegend
<legend>…</legend>The caption for a fieldset. It must be the first child.
Open entrymeter
<meter value="…" min="…" max="…">Shows a scalar measurement in a known range, such as disk usage or a score.
Open entryoptgroup
<optgroup label="…">…</optgroup>Groups related options inside a select with a label.
Open entryoption
<option value="…">…</option>One choice inside a select or datalist.
Open entryoutput
<output for="…">…</output>The result of a calculation or user action. Associate it with the controls that produced it.
Open entryprogress
<progress value="…" max="…">Shows completion of a task. Without a value it becomes indeterminate.
Open entryselect
<select>…</select>A drop-down list of options. Add multiple to allow more than one selection.
Open entrytextarea
<textarea rows="…">…</textarea>A multi-line text control. Set rows and cols, and let users resize when possible.
Open entryGlobal attributes
accesskey
accesskey="k"Defines a keyboard shortcut for an element. Shortcuts vary by browser and platform, so always show them in the UI.
Open entryaria-atomic
aria-atomic="true"Tells assistive technology to announce the whole live region instead of only the changed node.
Open entryaria-controls
aria-controls="panel"Identifies the element controlled by a button or input.
Open entryaria-current
aria-current="page"Marks the current item in a set, such as the active navigation link.
Open entryaria-describedby
aria-describedby="hint"Points to the element that provides an accessible description.
Open entryaria-disabled
aria-disabled="true"Announces that a custom control is disabled. It does not block interaction by itself.
Open entryaria-expanded
aria-expanded="false"Communicates whether a disclosure or menu is open.
Open entryaria-hidden
aria-hidden="true"Removes an element from the accessibility tree. Do not hide focusable content.
Open entryaria-invalid
aria-invalid="true"Marks a control whose value failed validation.
Open entryaria-label
aria-label="…"An accessible name used when visible text is missing or insufficient. Prefer a real label or visible heading.
Open entryaria-labelledby
aria-labelledby="title"Uses another element’s text as the accessible name.
Open entryaria-live
aria-live="polite"Announces changes inside a region: polite waits, assertive interrupts.
Open entryaria-pressed
aria-pressed="true"Marks a toggle button as pressed or not pressed.
Open entryaria-required
aria-required="true"Announces that a custom form control is required.
Open entryaria-selected
aria-selected="true"Marks the selected item in a tab list, grid or listbox.
Open entryaria-valuenow
aria-valuenow="40"The current value of a custom range widget, paired with aria-valuemin and aria-valuemax.
Open entryautocapitalize
autocapitalize="sentences"Controls automatic capitalisation on virtual keyboards: none, sentences, words or characters.
Open entryautofocus
autofocusFocuses one element when the page loads. Use it on the primary field of a focused flow, not everywhere.
Open entryclass
class="a b"One or more reusable class names used by CSS and JavaScript. Space-separated.
Open entrycontenteditable
contenteditable="true"Makes an element’s content editable by the user. Add role="textbox" and a label for custom editors.
Open entrydata-*
data-id="42"A custom data attribute that stores extra information on an element without inventing non-standard attributes.
Open entrydir
dir="rtl"Sets text direction: ltr, rtl or auto. Use it on the html element for right-to-left languages.
Open entrydraggable
draggable="true"Marks an element as draggable. You still need dragstart and drop event handlers.
Open entryenterkeyhint
enterkeyhint="search"Changes the virtual keyboard’s Enter key label: go, done, next, previous, search, send.
Open entryexportparts
exportparts="label: tab-label"Re-exports shadow parts with renamed public names.
Open entryhidden
hiddenHides an element from rendering and from assistive technology. Prefer it over display:none when toggled by script.
Open entryid
id="unique-name"A unique identifier for one element in the document. Used by CSS, labels, anchors and JavaScript.
Open entryinert
inertMakes an element and its descendants non-interactive and hidden from assistive technology. Useful for background content behind a modal.
Open entryinputmode
inputmode="numeric"Hints the kind of virtual keyboard to show: none, text, decimal, numeric, tel, email, url, search.
Open entryis
is="custom-element"Upgrades a built-in element to a customized built-in custom element.
Open entryitemid
itemid="https://example.com/#course"A unique identifier for an item described with microdata.
Open entryitemprop
itemprop="name"Names a property in a microdata item.
Open entryitemref
itemref="extra"References additional elements that belong to a microdata item.
Open entryitemscope
itemscopeDeclares that the element is a microdata item with properties.
Open entryitemtype
itemtype="https://schema.org/Course"The vocabulary URL that describes the item.
Open entrylang
lang="en"Declares the content language. Helps screen readers pronounce text and helps search engines.
Open entrynonce
nonce="random-value"A one-time value that allows an inline script or style under a Content-Security-Policy.
Open entrypart
part="label"Exposes an element inside a shadow tree so outside CSS can style it with ::part().
Open entryrole
role="…"Overrides the accessibility role of an element. Use native elements first; roles cannot add keyboard behaviour.
Open entryslot (attribute)
slot="title"Assigns content to a named slot inside a web component.
Open entryspellcheck
spellcheck="true"Enables or disables spelling and grammar checking on editable content.
Open entrystyle (attribute)
style="color: red"Applies inline CSS to one element. Prefer classes because inline styles beat stylesheet rules and are hard to theme.
Open entrytabindex
tabindex="0"Changes keyboard focus order. Use 0 to include an element in the natural order; avoid positive numbers.
Open entrytitle (attribute)
title="…"Advisory information shown as a tooltip. Do not put required instructions here because touch users never see it.
Open entrytranslate
translate="no"Tells translation tools to leave content alone, such as brand names or code identifiers.
Open entryvirtualkeyboardpolicy
virtualkeyboardpolicy="manual"Controls whether the virtual keyboard shows automatically for editable elements.
Open entrywritingsuggestions
writingsuggestions="false"Disables browser writing suggestions for an editable element or the whole page.
Open entryImage and media attributes
allow
allow="fullscreen; clipboard-write"A permissions policy for an iframe’s features.
Open entryallowfullscreen
allowfullscreenAllows an iframe to enter fullscreen. Prefer allow="fullscreen".
Open entryalt
alt="A short description"The text alternative for an image. Empty alt marks the image as decorative.
Open entryautoplay
autoplayStarts playback automatically. Browsers usually require muted media to allow it.
Open entrycontrols
controlsShows the browser’s native audio or video controls.
Open entrydecoding
decoding="async"Hints whether image decoding should happen synchronously or asynchronously.
Open entrydefault
defaultSelects a text track or option by default.
Open entryheight
height="80"Intrinsic height in pixels. CSS can still scale the element responsively.
Open entryismap
ismapSends click coordinates to the server when the image is inside a link. Requires server handling.
Open entrykind
kind="captions"The type of a text track: subtitles, captions, descriptions, chapters or metadata.
Open entrylabel (attribute)
label="English"A user-visible name for a text track or option group.
Open entryloading
loading="lazy"Defers offscreen images and iframes until they approach the viewport.
Open entryloop
loopRestarts media when it reaches the end.
Open entrymuted
mutedStarts media with the audio muted.
Open entryplaysinline
playsinlineAllows video to play inline on iOS instead of entering fullscreen.
Open entryposter
poster="/cover.jpg"The image shown before a video starts playing.
Open entrypreload
preload="metadata"Hints how much media to load before playback: none, metadata or auto.
Open entrysandbox
sandbox="allow-scripts"Restricts what an iframe may do. Omit tokens for maximum restriction.
Open entrysrc
src="/images/cover.png"The URL of the embedded image, script, iframe or media file.
Open entrysrcdoc
srcdoc="<p>Hello</p>"Embeds an HTML document directly in an iframe instead of loading a URL.
Open entrysrclang
srclang="en"The language of a subtitle or caption track.
Open entrysrcset
srcset="small.jpg 480w, large.jpg 960w"Lists responsive image candidates with width or density descriptors.
Open entryusemap
usemap="#zones"Associates an image with a client-side image map.
Open entrywidth
width="120"Intrinsic width in pixels. Set it with height to reserve space and avoid layout shift.
Open entryInteractive widgets
details
<details>…</details>A native disclosure widget that expands and collapses with no JavaScript.
Open entrydialog
<dialog>…</dialog>A native modal or non-modal dialog. showModal() adds a backdrop and focus trapping.
Open entrypopover
popoverA global attribute that turns an element into a lightweight popover toggled by popovertarget.
Open entrysummary
<summary>…</summary>The always-visible label that toggles a details element. It must be the first child.
Open entryLinks and media
a
<a href="…">…</a>Creates a hyperlink. Use real href values so links work with keyboards, middle-click and crawlers.
Open entryarea
<area shape="…" coords="…" href="…">A clickable region inside an image map. It needs an alt attribute.
Open entryaudio
<audio controls>…</audio>Embeds an audio player. Provide a transcript for anything important.
Open entrycanvas
<canvas id="…"></canvas>A bitmap drawing surface controlled by JavaScript. Provide fallback text and an accessible alternative.
Open entryembed
<embed src="…" type="…">Embeds external content handled by a plugin. Prefer video, audio, img or iframe.
Open entryfigcaption
<figcaption>…</figcaption>The caption for a figure. It must be the first or last child.
Open entryfigure
<figure>…</figure>Self-contained media with an optional caption that stays with it.
Open entryiframe
<iframe src="…" title="…">Embeds another browsing context, such as a map or video. Always give it a descriptive title.
Open entryimg
<img src="…" alt="…">Embeds an image. alt describes the image for people who cannot see it and for search engines.
Open entrymap
<map name="…">…</map>Defines a client-side image map with clickable regions.
Open entryobject
<object data="…" type="…">…</object>Embeds an external resource with fallback content. Historically used for plugins.
Open entrypicture
<picture>…</picture>Chooses between image sources based on media conditions or format support.
Open entryslot
<slot name="…"></slot>A placeholder inside a web component where the parent supplies content.
Open entrysource
<source src="…" type="…">Supplies alternative media for picture, video or audio.
Open entrysvg
<svg>…</svg>Inline scalable vector graphics. SVG scales without blurring and can be styled with CSS.
Open entrytemplate
<template>…</template>Holds inert markup that is not rendered until JavaScript clones it. Useful for reusable fragments.
Open entrytrack
<track kind="captions" …>Adds timed text tracks such as captions, subtitles and descriptions to video or audio.
Open entryvideo
<video controls>…</video>Embeds a video player with native controls, captions and multiple sources.
Open entryLists
dd
<dd>…</dd>The description or definition of the preceding term.
Open entrydl
<dl>…</dl>A description list of term and definition pairs.
Open entrydt
<dt>…</dt>A term in a description list.
Open entryli
<li>…</li>A list item inside ul, ol or menu.
Open entrymenu
<menu>…</menu>A semantic list of commands or actions. Most browsers render it like ul.
Open entryol
<ol>…</ol>An ordered list where sequence matters. Use start and reversed to change numbering.
Open entryul
<ul>…</ul>An unordered list for items where order does not matter.
Open entryMetadata and script attributes
async
asyncRuns a script as soon as it downloads. Order is not guaranteed; use it for independent analytics.
Open entryblocking
blocking="render"Allows scripts, styles and images to block rendering explicitly when they must run first.
Open entrycharset
charset="utf-8"Declares the document encoding in the meta element or a linked script.
Open entrycontent
content="width=device-width, initial-scale=1"Provides the value for a meta element such as viewport, description or theme-color.
Open entrydefer
deferRuns a classic script after parsing, in document order. The right default for most scripts.
Open entryhttp-equiv
http-equiv="refresh"Emulates an HTTP response header in a document, such as refresh or content-security-policy.
Open entrynomodule
nomoduleRuns a fallback script only in browsers that do not support modules.
Open entryproperty
property="og:title"Declares an Open Graph property for social previews.
Open entryPage structure
address
<address>…</address>Contact information for the nearest article or the page author. It is not a generic postal-address element.
Open entryarticle
<article>…</article>Self-contained content that makes sense on its own: a blog post, a card, a forum reply or a lesson.
Open entryaside
<aside aria-label="…">…</aside>Content tangential to the main flow: a sidebar, pull quote, related links or advertising.
Open entrydiv
<div>…</div>A generic block container with no meaning. Use it for layout only when no semantic element fits.
Open entryfooter
<footer>…</footer>Closing content for a page or section: copyright, contact links, related documents.
Open entryh1–h6
<h1>…</h1> to <h6>…</h6>Heading levels express document outline. Do not skip levels for visual size; style the heading instead.
Open entryheader
<header>…</header>Introductory content for a page or a section: a heading, logo, search and navigation. A page and each article can have one.
Open entryhgroup
<hgroup>…</hgroup>Groups a heading with its subtitle or tagline so assistive technology treats them as one heading.
Open entrymain
<main>…</main>The unique, central content of the page. There should be exactly one main element and it must not include repeated site chrome.
Open entrynav
<nav aria-label="Main">…</nav>A block of major navigation links. Label multiple nav landmarks so screen-reader users can tell them apart.
Open entrysearch
<search>…</search>A landmark for site search. It signals to assistive technology that the region contains search controls.
Open entrysection
<section aria-labelledby="…">…</section>A thematic grouping, usually with a heading. If it has no heading it is probably a div.
Open entryspan
<span>…</span>A generic inline container. Useful for styling part of a sentence or carrying a data attribute.
Open entryTable and list attributes
abbr (attribute)
abbr="HyperText Markup Language"An abbreviated header label for screen readers in complex tables.
Open entrycolspan
colspan="2"Makes a table cell span several columns.
Open entryheaders
headers="h1 h2"Associates a data cell with the header cells that describe it. Complex tables only.
Open entryreversed
reversedNumbers an ordered list in descending order.
Open entryrowspan
rowspan="2"Makes a table cell span several rows.
Open entryscope
scope="col"Declares whether a header cell labels a row, column or group.
Open entryspan (table attribute)
span="2"Makes a col or colgroup span several columns.
Open entrystart
start="5"Sets the starting number of an ordered list.
Open entryTables
caption
<caption>…</caption>A table title. It must be the first child and describes the table to everyone.
Open entrycol
<col span="…">Defines properties for one or more columns inside colgroup.
Open entrycolgroup
<colgroup>…</colgroup>Groups columns so you can style them together. Place it before thead.
Open entrytable
<table>…</table>Tabular data arranged in rows and columns. Never use tables for layout.
Open entrytbody
<tbody>…</tbody>Groups the body rows of a table.
Open entrytd
<td>…</td>A data cell in a table row.
Open entrytfoot
<tfoot>…</tfoot>Groups summary rows, such as totals, at the end of a table.
Open entryth
<th scope="col">…</th>A header cell. The scope attribute tells assistive technology whether it labels a row or a column.
Open entrythead
<thead>…</thead>Groups the header rows of a table.
Open entrytr
<tr>…</tr>A table row containing th or td cells.
Open entryText and inline semantics
abbr
<abbr title="…">…</abbr>An abbreviation or acronym with its expanded form in the title attribute.
Open entryb
<b>…</b>Visually offset text without implying importance, such as a product name in a review.
Open entrybdi
<bdi>…</bdi>Isolates text whose direction may differ from the surrounding content, such as a username.
Open entrybdo
<bdo dir="rtl">…</bdo>Overrides the text direction of its content.
Open entryblockquote
<blockquote cite="…">…</blockquote>An extended quotation from another source. Use the cite attribute for the source URL.
Open entrybr
Line one<br>Line twoA line break inside the same paragraph, as in a postal address or a poem.
Open entrycite
<cite>…</cite>The title of a creative work: a book, song, film or article. It is not for the author’s name.
Open entrycode
<code>…</code>A fragment of computer code. Use it inline; wrap longer blocks in pre.
Open entrydata (element)
<data value="…">…</data>Links human-readable content to a machine-readable value.
Open entrydel
<del>…</del>Content that has been removed from the document. Pair it with ins to show edits.
Open entryem
<em>…</em>Stress emphasis that changes the meaning of the sentence.
Open entryhr
<hr>A thematic break between sections of content. It is not a decorative line.
Open entryi
<i>…</i>Text in an alternate voice or mood: a technical term, a foreign phrase or a thought.
Open entryins
<ins>…</ins>Content that has been inserted into the document.
Open entrykbd
<kbd>…</kbd>Text the user should type or a key they should press.
Open entrymark
<mark>…</mark>Text highlighted for reference in the current context, such as a search match.
Open entryp
<p>…</p>A paragraph of prose. Browsers add space before and after it; do not use it just to create gaps.
Open entrypre
<pre>…</pre>Preformatted text that preserves spaces and line breaks. Ideal for ASCII art, terminal output and code without markup.
Open entryq
<q>…</q>A short inline quotation. Browsers add quotation marks automatically based on the language.
Open entryrp
<rp>(</rp>Fallback parentheses for browsers that do not support ruby annotations.
Open entryrt
<rt>…</rt>The pronunciation annotation inside a ruby element.
Open entryruby
<ruby>漢<rt>kan</rt></ruby>Adds pronunciation annotations above East Asian characters.
Open entrys
<s>…</s>Content that is no longer accurate or relevant, without implying a document edit.
Open entrysamp
<samp>…</samp>Sample output from a program or system.
Open entrysmall
<small>…</small>Side comments and fine print, such as legal text.
Open entrystrong
<strong>…</strong>Strong importance. Screen readers may change emphasis, and it is not merely bold text.
Open entrysub
<sub>…</sub>Subscript text for chemical formulas or mathematical indices.
Open entrysup
<sup>…</sup>Superscript text for exponents, ordinals or footnote markers.
Open entrytime
<time datetime="2026-11-01">…</time>A machine-readable date or time. The datetime attribute lets browsers and search engines parse it.
Open entryvar
<var>…</var>A variable in a mathematical expression or programming context.
Open entrywbr
super<wbr>califragilisticAn optional line-break opportunity inside a long word or URL.
Open entryTurn the reference into recall.
Read the full lesson, then solve the challenge without looking. That is where the knowledge sticks.