Quick reference

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.

Read the full explanationHTML Foundations

Work through the guided lesson, then test yourself with a challenge.

Open course
249 entries

Document structure

<!doctype html>

<!doctype html>

Declares standards mode. It must be the very first thing in the document, before <html>.

Open entry

base

<base href="https://example.com/">

Sets a base URL for every relative link and resource in the document. Use it once, at most.

Open entry

body

<body>…</body>

All visible page content lives here. A page should have exactly one body.

Open entry

head

<head>…</head>

Holds metadata: the title, character encoding, styles, scripts and social preview tags. Nothing here is rendered directly.

Open entry

html

<html lang="en">…</html>

The document root. The lang attribute tells screen readers, search engines and translators which language the content is in.

Open entry

link

<link rel="stylesheet" href="styles.css">

Connects the document to an external resource: stylesheets, icons, font preloads, canonical URLs and alternate feeds.

Open entry

meta 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 entry

meta 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 entry

meta 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 entry

meta 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 entry

noscript

<noscript>…</noscript>

Content shown when JavaScript is disabled or fails. Use it for a short explanation, not for duplicating the whole app.

Open entry

script

<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 entry

style (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 entry

title

<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 entry

Form and input attributes

accept

accept="image/*"

Filters the file types a file input offers.

Open entry

accept-charset

accept-charset="UTF-8"

The character encodings the server accepts for the form.

Open entry

action

action="/subscribe"

The URL that receives a submitted form.

Open entry

autocomplete

autocomplete="email"

Tells the browser what kind of data the field expects so autofill works correctly.

Open entry

capture

capture="environment"

Asks a mobile device to capture a new photo or video directly.

Open entry

checked

checked

Preselects a checkbox or radio button.

Open entry

cols

cols="40"

The visible width of a textarea in characters.

Open entry

dirname

dirname="direction"

Submits the text direction of an input or textarea with its value.

Open entry

disabled

disabled

Turns off a control. Disabled controls are not submitted and are removed from the tab order.

Open entry

enctype

enctype="multipart/form-data"

The encoding for form data. File uploads require multipart/form-data.

Open entry

form (attribute)

form="signup"

Associates a control with a form elsewhere in the document.

Open entry

formaction

formaction="/preview"

Overrides the form action for the button that submits it.

Open entry

formmethod

formmethod="get"

Overrides the form method for one submit button.

Open entry

formnovalidate

formnovalidate

Skips validation for a specific submit button, such as a save-draft action.

Open entry

formtarget

formtarget="_blank"

Opens the form response in a new browsing context for one button.

Open entry

list (attribute)

list="languages"

Connects an input to a datalist of suggested values.

Open entry

max

max="10"

The maximum value for number, range and date inputs. It also caps the latest selectable date.

Open entry

maxlength

maxlength="280"

The maximum number of characters for text inputs and textareas.

Open entry

method

method="post"

The HTTP method for form submission. Use post for changes and get for searches.

Open entry

min

min="0"

The minimum value for number, range and date inputs.

Open entry

minlength

minlength="8"

The minimum number of characters for text inputs and textareas.

Open entry

multiple

multiple

Allows more than one value in a select or more than one file in a file input.

Open entry

name (attribute)

name="email"

The field name sent to the server. A control without a name is not submitted.

Open entry

novalidate

novalidate

Disables the browser’s built-in form validation when submitting.

Open entry

pattern

pattern="[A-Za-z]+"

A regular expression the field value must match. Always pair it with a visible hint.

Open entry

placeholder

placeholder="you@example.com"

A format hint inside an empty field. It is not a label and disappears on input.

Open entry

readonly

readonly

Prevents editing but still submits the value and keeps it focusable.

Open entry

required

required

Rejects submission while the field is empty.

Open entry

rows

rows="4"

The visible number of text lines in a textarea.

Open entry

selected

selected

Preselects an option in a select element.

Open entry

size

size="20"

The visible width of a text input in characters.

Open entry

step

step="0.5"

The increment used by number and range inputs.

Open entry

value

value="Ada"

The initial or current value of a form control.

Open entry

wrap

wrap="hard"

Whether textarea line breaks are submitted: soft or hard.

Open entry

Forms and controls

button

<button type="button">…</button>

A clickable control. Set type explicitly: submit inside a form, button everywhere else.

Open entry

datalist

<datalist id="…">…</datalist>

Provides suggested values for an input while still allowing free text.

Open entry

fieldset

<fieldset>…</fieldset>

Groups related controls, especially radio buttons.

Open entry

form

<form action="…" method="post">…</form>

Collects user input and submits it. Always pair inputs with labels and choose the right input type.

Open entry

input

<input type="…" name="…" id="…">

A single-line control. The type decides validation, keyboard and autofill behaviour.

Open entry

input types

type="email | password | number | date | checkbox"

Choosing the correct type gives free validation, mobile keyboards and better autofill.

Open entry

label

<label for="…">…</label>

An accessible caption for a form control. Clicking the label focuses the control.

Open entry

legend

<legend>…</legend>

The caption for a fieldset. It must be the first child.

Open entry

meter

<meter value="…" min="…" max="…">

Shows a scalar measurement in a known range, such as disk usage or a score.

Open entry

optgroup

<optgroup label="…">…</optgroup>

Groups related options inside a select with a label.

Open entry

option

<option value="…">…</option>

One choice inside a select or datalist.

Open entry

output

<output for="…">…</output>

The result of a calculation or user action. Associate it with the controls that produced it.

Open entry

progress

<progress value="…" max="…">

Shows completion of a task. Without a value it becomes indeterminate.

Open entry

select

<select>…</select>

A drop-down list of options. Add multiple to allow more than one selection.

Open entry

textarea

<textarea rows="…">…</textarea>

A multi-line text control. Set rows and cols, and let users resize when possible.

Open entry

Global 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 entry

aria-atomic

aria-atomic="true"

Tells assistive technology to announce the whole live region instead of only the changed node.

Open entry

aria-controls

aria-controls="panel"

Identifies the element controlled by a button or input.

Open entry

aria-current

aria-current="page"

Marks the current item in a set, such as the active navigation link.

Open entry

aria-describedby

aria-describedby="hint"

Points to the element that provides an accessible description.

Open entry

aria-disabled

aria-disabled="true"

Announces that a custom control is disabled. It does not block interaction by itself.

Open entry

aria-expanded

aria-expanded="false"

Communicates whether a disclosure or menu is open.

Open entry

aria-hidden

aria-hidden="true"

Removes an element from the accessibility tree. Do not hide focusable content.

Open entry

aria-invalid

aria-invalid="true"

Marks a control whose value failed validation.

Open entry

aria-label

aria-label="…"

An accessible name used when visible text is missing or insufficient. Prefer a real label or visible heading.

Open entry

aria-labelledby

aria-labelledby="title"

Uses another element’s text as the accessible name.

Open entry

aria-live

aria-live="polite"

Announces changes inside a region: polite waits, assertive interrupts.

Open entry

aria-pressed

aria-pressed="true"

Marks a toggle button as pressed or not pressed.

Open entry

aria-required

aria-required="true"

Announces that a custom form control is required.

Open entry

aria-selected

aria-selected="true"

Marks the selected item in a tab list, grid or listbox.

Open entry

aria-valuenow

aria-valuenow="40"

The current value of a custom range widget, paired with aria-valuemin and aria-valuemax.

Open entry

autocapitalize

autocapitalize="sentences"

Controls automatic capitalisation on virtual keyboards: none, sentences, words or characters.

Open entry

autofocus

autofocus

Focuses one element when the page loads. Use it on the primary field of a focused flow, not everywhere.

Open entry

class

class="a b"

One or more reusable class names used by CSS and JavaScript. Space-separated.

Open entry

contenteditable

contenteditable="true"

Makes an element’s content editable by the user. Add role="textbox" and a label for custom editors.

Open entry

data-*

data-id="42"

A custom data attribute that stores extra information on an element without inventing non-standard attributes.

Open entry

dir

dir="rtl"

Sets text direction: ltr, rtl or auto. Use it on the html element for right-to-left languages.

Open entry

draggable

draggable="true"

Marks an element as draggable. You still need dragstart and drop event handlers.

Open entry

enterkeyhint

enterkeyhint="search"

Changes the virtual keyboard’s Enter key label: go, done, next, previous, search, send.

Open entry

exportparts

exportparts="label: tab-label"

Re-exports shadow parts with renamed public names.

Open entry

hidden

hidden

Hides an element from rendering and from assistive technology. Prefer it over display:none when toggled by script.

Open entry

id

id="unique-name"

A unique identifier for one element in the document. Used by CSS, labels, anchors and JavaScript.

Open entry

inert

inert

Makes an element and its descendants non-interactive and hidden from assistive technology. Useful for background content behind a modal.

Open entry

inputmode

inputmode="numeric"

Hints the kind of virtual keyboard to show: none, text, decimal, numeric, tel, email, url, search.

Open entry

is

is="custom-element"

Upgrades a built-in element to a customized built-in custom element.

Open entry

itemid

itemid="https://example.com/#course"

A unique identifier for an item described with microdata.

Open entry

itemprop

itemprop="name"

Names a property in a microdata item.

Open entry

itemref

itemref="extra"

References additional elements that belong to a microdata item.

Open entry

itemscope

itemscope

Declares that the element is a microdata item with properties.

Open entry

itemtype

itemtype="https://schema.org/Course"

The vocabulary URL that describes the item.

Open entry

lang

lang="en"

Declares the content language. Helps screen readers pronounce text and helps search engines.

Open entry

nonce

nonce="random-value"

A one-time value that allows an inline script or style under a Content-Security-Policy.

Open entry

part

part="label"

Exposes an element inside a shadow tree so outside CSS can style it with ::part().

Open entry

role

role="…"

Overrides the accessibility role of an element. Use native elements first; roles cannot add keyboard behaviour.

Open entry

slot (attribute)

slot="title"

Assigns content to a named slot inside a web component.

Open entry

spellcheck

spellcheck="true"

Enables or disables spelling and grammar checking on editable content.

Open entry

style (attribute)

style="color: red"

Applies inline CSS to one element. Prefer classes because inline styles beat stylesheet rules and are hard to theme.

Open entry

tabindex

tabindex="0"

Changes keyboard focus order. Use 0 to include an element in the natural order; avoid positive numbers.

Open entry

title (attribute)

title="…"

Advisory information shown as a tooltip. Do not put required instructions here because touch users never see it.

Open entry

translate

translate="no"

Tells translation tools to leave content alone, such as brand names or code identifiers.

Open entry

virtualkeyboardpolicy

virtualkeyboardpolicy="manual"

Controls whether the virtual keyboard shows automatically for editable elements.

Open entry

writingsuggestions

writingsuggestions="false"

Disables browser writing suggestions for an editable element or the whole page.

Open entry

Image and media attributes

allow

allow="fullscreen; clipboard-write"

A permissions policy for an iframe’s features.

Open entry

allowfullscreen

allowfullscreen

Allows an iframe to enter fullscreen. Prefer allow="fullscreen".

Open entry

alt

alt="A short description"

The text alternative for an image. Empty alt marks the image as decorative.

Open entry

autoplay

autoplay

Starts playback automatically. Browsers usually require muted media to allow it.

Open entry

controls

controls

Shows the browser’s native audio or video controls.

Open entry

decoding

decoding="async"

Hints whether image decoding should happen synchronously or asynchronously.

Open entry

default

default

Selects a text track or option by default.

Open entry

height

height="80"

Intrinsic height in pixels. CSS can still scale the element responsively.

Open entry

ismap

ismap

Sends click coordinates to the server when the image is inside a link. Requires server handling.

Open entry

kind

kind="captions"

The type of a text track: subtitles, captions, descriptions, chapters or metadata.

Open entry

label (attribute)

label="English"

A user-visible name for a text track or option group.

Open entry

loading

loading="lazy"

Defers offscreen images and iframes until they approach the viewport.

Open entry

loop

loop

Restarts media when it reaches the end.

Open entry

muted

muted

Starts media with the audio muted.

Open entry

playsinline

playsinline

Allows video to play inline on iOS instead of entering fullscreen.

Open entry

poster

poster="/cover.jpg"

The image shown before a video starts playing.

Open entry

preload

preload="metadata"

Hints how much media to load before playback: none, metadata or auto.

Open entry

sandbox

sandbox="allow-scripts"

Restricts what an iframe may do. Omit tokens for maximum restriction.

Open entry

src

src="/images/cover.png"

The URL of the embedded image, script, iframe or media file.

Open entry

srcdoc

srcdoc="<p>Hello</p>"

Embeds an HTML document directly in an iframe instead of loading a URL.

Open entry

srclang

srclang="en"

The language of a subtitle or caption track.

Open entry

srcset

srcset="small.jpg 480w, large.jpg 960w"

Lists responsive image candidates with width or density descriptors.

Open entry

usemap

usemap="#zones"

Associates an image with a client-side image map.

Open entry

width

width="120"

Intrinsic width in pixels. Set it with height to reserve space and avoid layout shift.

Open entry

Interactive widgets

Lists

Metadata and script attributes

Page structure

address

<address>…</address>

Contact information for the nearest article or the page author. It is not a generic postal-address element.

Open entry

article

<article>…</article>

Self-contained content that makes sense on its own: a blog post, a card, a forum reply or a lesson.

Open entry

aside

<aside aria-label="…">…</aside>

Content tangential to the main flow: a sidebar, pull quote, related links or advertising.

Open entry

div

<div>…</div>

A generic block container with no meaning. Use it for layout only when no semantic element fits.

Open entry

footer

<footer>…</footer>

Closing content for a page or section: copyright, contact links, related documents.

Open entry

h1–h6

<h1>…</h1> to <h6>…</h6>

Heading levels express document outline. Do not skip levels for visual size; style the heading instead.

Open entry

header

<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 entry

hgroup

<hgroup>…</hgroup>

Groups a heading with its subtitle or tagline so assistive technology treats them as one heading.

Open entry

main

<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 entry

nav

<nav aria-label="Main">…</nav>

A block of major navigation links. Label multiple nav landmarks so screen-reader users can tell them apart.

Open entry

search

<search>…</search>

A landmark for site search. It signals to assistive technology that the region contains search controls.

Open entry

section

<section aria-labelledby="…">…</section>

A thematic grouping, usually with a heading. If it has no heading it is probably a div.

Open entry

span

<span>…</span>

A generic inline container. Useful for styling part of a sentence or carrying a data attribute.

Open entry

Table and list attributes

Tables

Text and inline semantics

abbr

<abbr title="…">…</abbr>

An abbreviation or acronym with its expanded form in the title attribute.

Open entry

b

<b>…</b>

Visually offset text without implying importance, such as a product name in a review.

Open entry

bdi

<bdi>…</bdi>

Isolates text whose direction may differ from the surrounding content, such as a username.

Open entry

bdo

<bdo dir="rtl">…</bdo>

Overrides the text direction of its content.

Open entry

blockquote

<blockquote cite="…">…</blockquote>

An extended quotation from another source. Use the cite attribute for the source URL.

Open entry

br

Line one<br>Line two

A line break inside the same paragraph, as in a postal address or a poem.

Open entry

cite

<cite>…</cite>

The title of a creative work: a book, song, film or article. It is not for the author’s name.

Open entry

code

<code>…</code>

A fragment of computer code. Use it inline; wrap longer blocks in pre.

Open entry

data (element)

<data value="…">…</data>

Links human-readable content to a machine-readable value.

Open entry

del

<del>…</del>

Content that has been removed from the document. Pair it with ins to show edits.

Open entry

em

<em>…</em>

Stress emphasis that changes the meaning of the sentence.

Open entry

hr

<hr>

A thematic break between sections of content. It is not a decorative line.

Open entry

i

<i>…</i>

Text in an alternate voice or mood: a technical term, a foreign phrase or a thought.

Open entry

ins

<ins>…</ins>

Content that has been inserted into the document.

Open entry

kbd

<kbd>…</kbd>

Text the user should type or a key they should press.

Open entry

mark

<mark>…</mark>

Text highlighted for reference in the current context, such as a search match.

Open entry

p

<p>…</p>

A paragraph of prose. Browsers add space before and after it; do not use it just to create gaps.

Open entry

pre

<pre>…</pre>

Preformatted text that preserves spaces and line breaks. Ideal for ASCII art, terminal output and code without markup.

Open entry

q

<q>…</q>

A short inline quotation. Browsers add quotation marks automatically based on the language.

Open entry

rp

<rp>(</rp>

Fallback parentheses for browsers that do not support ruby annotations.

Open entry

rt

<rt>…</rt>

The pronunciation annotation inside a ruby element.

Open entry

ruby

<ruby>漢<rt>kan</rt></ruby>

Adds pronunciation annotations above East Asian characters.

Open entry

s

<s>…</s>

Content that is no longer accurate or relevant, without implying a document edit.

Open entry

samp

<samp>…</samp>

Sample output from a program or system.

Open entry

small

<small>…</small>

Side comments and fine print, such as legal text.

Open entry

strong

<strong>…</strong>

Strong importance. Screen readers may change emphasis, and it is not merely bold text.

Open entry

sub

<sub>…</sub>

Subscript text for chemical formulas or mathematical indices.

Open entry

sup

<sup>…</sup>

Superscript text for exponents, ordinals or footnote markers.

Open entry

time

<time datetime="2026-11-01">…</time>

A machine-readable date or time. The datetime attribute lets browsers and search engines parse it.

Open entry

var

<var>…</var>

A variable in a mathematical expression or programming context.

Open entry

wbr

super<wbr>califragilistic

An optional line-break opportunity inside a long word or URL.

Open entry
Keep going

Turn the reference into recall.

Read the full lesson, then solve the challenge without looking. That is where the knowledge sticks.