Skip to content

Choosing the Right Element ​

This page sets out which HTML element to use for each kind of component. With the right element, keyboard operation, screen reader announcements, and autofill work through the browser's built-in behavior.

The "Check" IDs on each rule are items in the Quality Checklist; select one to open its reference figure. Code examples are collapsed. The text is written so that you can decide without opening them.

Elements by Purpose ​

Elements to use for each purpose
PurposeElement to use
Go to another page or another place on the page<a href="…">
Make something happen on the same page (open, close, switch)<button type="button">
Submit a form<button type="submit">
A section that opens and closes (accordion)<details> and <summary>
Modal dialog<dialog> (open with showModal(); focus containment and closing with Esc come built in)
A set of items<ul> when order does not matter, <ol> for steps or rankings, <dl> for name–value pairs
Data table<table> (never for layout)

Choose between a link and a button by what happens when it is pressed. Even if it looks like a button, it is a link if it goes to another page.

Links and buttons compared
LinkButton
Link: activating the text moves to another page, Plans, at a different URLButton: activating Filter opens a panel of options on the same page
Goes to another page (URL)Something happens on this page
Can be opened in a new tab or have its URL copiedCan be pressed with Enter and Space
Do not attach click handlers to <div> or <span> MUST NOTPQ-R26
Use <a> or <button>. They work with the keyboard and are announced as something you can press.
Check: LNK-01LNK-01 Use the button element✕ NGA div posing as a buttonA clickable "Save" control is built from a divNo Tab stop, no Enter✓ OKBuilt with buttonThe "Save" control is a button elementWorks by keyboard
Do not use <a> without href as a button MUST NOTPQ-R27
Use <button> for button behavior. It receives keyboard focus and is announced as a button.
Check: LNK-02LNK-02 No a without href✕ NGAn a with no hrefAn a element without href is used as a buttonNo href: not focusable✓ OKButtons are buttonsThe action is built with a button element
Make each link's purpose clear from its text or its surrounding context MUSTPQ-R28
Surrounding context means the same paragraph, the same list item, or the preceding heading. Text such as "See pricing plans" lets users know where the link goes before pressing it (WCAG 2.4.4 Level A).
Check: LNK-03LNK-03 Link purpose✕ NG"Click here" says nothingLinks read "Click here" and "More", so their destinations are unclear✓ OKThe text names the destinationLink text names the destination, such as "Pricing details"
Mark the current page in navigation with aria-current="page" MUSTPQ-R29
This applies to global navigation and breadcrumbs. Screen readers announce "current page", not just a color change.
Check: LNK-04LNK-04 Current page✕ NGCurrent page not announcedThe nav marks the current page "Pricing" by color only; a screen reader hears a plain linkCurrent page shown visually only✓ OKaria-current announces itThe current nav item has aria-current="page" and is announced as current page
Open links in the same tab, without target="_blank" SHOULDPQ-R30
Users then choose for themselves whether to open a new tab, and keep their browsing flow.
When a requirement makes it unavoidable, include "opens in a new tab" in the link's name ("new window" is not wrong, since settings can open a window instead). Whether the text is visible or screen-reader-only is a design decision. An icon alone needs a text alternative.
Check: LNK-06LNK-06 Links opening a new tab✕ NGNew tab without noticeThe link uses target="_blank" without saying it opens a new tab✓ OKSays it opens a new tabThe link has an icon and "opens in a new tab" text
Code example: a link that opens a new tab, and the current page link
html
<!-- A link that opens in a new tab -->
<a href="https://example.com/annual-report.pdf" target="_blank">
  2026 Annual Report (PDF)
  <span class="visually-hidden"> (opens in a new tab)</span>
</a>

<!-- The current page in navigation -->
<a href="/news/" aria-current="page">News</a>

Images ​

How to write an image's alt (alternative text) depends on the image's role.

How to write alt by image role
Image roleHow to write altExample
Image that conveys informationWhat the image conveysalt="Revenue trend: up 20% year over year"
Decoration or backgroundLeave it empty (keep the attribute)alt=""
Image link with no textThe destination or functionalt="Back to home"
Image containing textAll the text in the imagealt="50th anniversary campaign"
Give every <img> an alt attribute MUSTPQ-R31
With it, screen readers read out what you wrote instead of the file name.
Check: IMG-01IMG-01 Image alt text✕ NGNo alt attributeThe chart img has no alt attribute✓ OKHas an alt attributeThe chart img has an alt attribute
Use alt="" for decorative images and describe the content of meaningful ones MUSTPQ-R32
Screen readers skip the decoration, so users hear only the information they need.
Check: IMG-02IMG-02 Image alt text✕ NGMissing alt; noisy alt on decorationThe chart image has no alt, and a decorative line has alt="line"✓ OKMeaningful alt; empty alt for decorationThe chart alt describes its content; the decorative line has alt=""
Give each <source> in <picture> its own width and height MUSTPQ-R33
Space is reserved at the right aspect ratio when the screen width switches, so the layout does not shift.
Check: IMG-03IMG-03 Image width / height✕ NGLayout shifts after loadThe img has no width or height, so text shifts down when it loads✓ OKDimensions reserve the spaceThe img has width and height, so its space is reserved before loading

Use <picture> only to change the crop or aspect ratio by screen width. Different resolutions of the same image only need srcset on <img>. Browsers pick the first matching <source>, so list them from the widest screen down, and put alt on the <img> only.

Code example: a standard image, and switching with <picture>
html
<img
  src="/assets/images/hero-visual.jpg"
  width="1200"
  height="630"
  alt="Development team discussing blueprints around a table"
/>

<picture>
  <source
    media="(min-width: 48em)"
    srcset="/assets/images/banner-wide.jpg"
    width="1200"
    height="480"
  />
  <img
    src="/assets/images/banner-square.jpg"
    width="800"
    height="800"
    alt="Spring membership campaign"
  />
</picture>

Lists and Tables ​

Mark up sets of parallel items as lists MUSTPQ-R34
This covers navigation, article card lists, tags, and breadcrumbs. Screen readers announce "list, 5 items", so users know how much there is. Put only <li> directly inside <ul> and <ol>.
Check: STR-09STR-09 List markup✕ NGA list in looks onlyItems are laid out with div and bullet charactersNot exposed as a list of 3✓ OKMarked up with ul / liItems are marked up with ul and li
Give data tables a <caption> and header cells <th> with scope MUSTPQ-R35
Screen readers then convey the table's subject and which header each cell belongs to.
Check: QA-23QA-23 Table caption and headers✕ NGNo caption, no header cellsThe table has no caption and its header cells are td✓ OKcaption and th scope expose structureThe table has a caption and header cells use th scope="col"

When a table too wide for the screen goes in a horizontal scroll container, give the container tabindex="0" and a name so it can be scrolled with the keyboard.

Code example: a data table
html
<table>
  <caption>Features by plan</caption>
  <thead>
    <tr>
      <th scope="col">Plan</th>
      <th scope="col">Storage</th>
      <th scope="col">Monthly price</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Standard</th>
      <td>100 GB</td>
      <td>$10</td>
    </tr>
  </tbody>
</table>

Forms ​

Associate a <label> with every input MUSTPQ-R36
Connect <label for="…"> to the input's id, or nest the input inside the <label>. Either way, clicking the label focuses the input. A placeholder disappears once typing starts, so use it for an example and give the field name in the label.
Check: FRM-01FRM-01 Label association✕ NGLabel and field are not linkedThe label and input are not tied together with for and iddoes nothing✓ OKfor/id link the labelThe label for matches the input id, so clicking the label focuses the fieldfocuses the field FRM-02FRM-02 Not placeholder alone✕ NGThe placeholder is the only nameThe field has no visible label; only the placeholder "Email address" names it✓ OKA label provides the nameAn "Email address" label sits above the field; the placeholder is just an example
Set a type that matches the input MUSTPQ-R37
Use email, tel, url, number, date, and so on. Phones then show a keyboard suited to the input.
Check: FRM-03FRM-03 Input type✕ NGWrong keyboard appearsThe email field is type="text", so phones show a keyboard without @✓ OKtype matches the inputThe email field is type="email", so phones show a keyboard with @
Set autocomplete on name, email, phone, and address fields MUSTPQ-R38
Browser autofill then works, which cuts effort and mistakes.
Check: FRM-04FRM-04 autocomplete attribute✕ NGAutofill does not workThe phone input has no autocomplete attributeEverything typed by hand✓ OKautocomplete states the purposeThe phone input has autocomplete="tel", so the browser suggests a valueBrowser offers autofill
Wrap groups of radio buttons or checkboxes in <fieldset> with a <legend> MUSTPQ-R39
Screen reader users hearing only an option still learn which question it answers. Use it too for sets of fields that form one unit, such as an address.
Check: FRM-05FRM-05 fieldset and legend✕ NGQuestion and options not linkedThe question for the radio buttons is a p element, not grouped with them✓ OKGrouped with fieldset / legendThe radio buttons are wrapped in fieldset with the question in legend
Associate error messages and hints with the input through aria-describedby MUSTPQ-R40
The error is then read out when the input receives focus.
Check: FRM-06FRM-06 Link error messages✕ NGThe field does not expose the errorThe error message is not tied to the field with aria-describedby✓ OKTied with aria-describedbyThe field’s aria-describedby points to the error message id
Code example: an input with a label and a hint
html
<div class="form-field">
  <label for="user-email">Email address</label>
  <input
    type="email"
    id="user-email"
    name="email"
    autocomplete="email"
    required
    aria-describedby="email-hint"
  />
  <p id="email-hint">We will send a confirmation email to this address.</p>
</div>

Elements That Give Text Meaning ​

Choose elements by meaning, not looks. If you only want bold or italics, use CSS.

Elements that give text meaning
MeaningElement to useIncorrect use
Important words<strong><b> just for bold
Verbal emphasis<em><i> just for italics
Date or time<time datetime="2026-04-01">A plain <span>
Contact information<address>Every postal address on the page
Quotation<blockquote cite="…">, <q><blockquote> just for indentation
Program code<code> (<pre><code> for multiple lines)A <div> with a monospace font
Meaningful line break (verse, addresses)<br><br> to create space
Do not stack <br> to create space MUST NOTPQ-R41
Create space with CSS margin or gap. The space then holds when the screen width or text size changes.

WAI-ARIA ​

The principle is to let HTML elements do whatever they can do on their own. For not repeating an element's own role, see Page Structure Basics; for how visible text relates to the name, see Names of Controls.

Do not use role to turn an element into a different role MUST NOTPQ-R42
Choose the element that matches the role, such as <a> for a link. The look, the behavior, and the announcement then agree (no <button role="link">).
Do not put aria-hidden="true" on elements that can receive keyboard focus MUST NOTPQ-R43
Remove hidden elements from the focus order too, and keep focusable elements announced. Keyboard and screen reader users then get the same thing.