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
| Purpose | Element 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) |
Links and Buttons
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.
| Link | Button |
|---|---|
| Goes to another page (URL) | Something happens on this page |
| Can be opened in a new tab or have its URL copied | Can 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-01Use the button element✕ NGA div posing as a buttonNo Tab stop, no Enter✓ OKBuilt with button
Works by keyboard
- Do not use
<a>withouthrefas a button MUST NOTPQ-R27 - Use
<button>for button behavior. It receives keyboard focus and is announced as a button. - Check:
LNK-02LNK-02No a without href✕ NGAn a with no hrefNo href: not focusable✓ OKButtons are buttons
- 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-03Link purpose✕ NG"Click here" says nothing✓ OKThe text names the destination
- 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-04Current page✕ NGCurrent page not announcedCurrent page shown visually only✓ OKaria-current announces it
- 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-06Links opening a new tab✕ NGNew tab without notice✓ OKSays it opens a new tab
Code example: a link that opens a new tab, and the current page link
<!-- 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.
| Image role | How to write alt | Example |
|---|---|---|
| Image that conveys information | What the image conveys | alt="Revenue trend: up 20% year over year" |
| Decoration or background | Leave it empty (keep the attribute) | alt="" |
| Image link with no text | The destination or function | alt="Back to home" |
| Image containing text | All the text in the image | alt="50th anniversary campaign" |
- Give every
<img>analtattribute MUSTPQ-R31 - With it, screen readers read out what you wrote instead of the file name.
- Check:
IMG-01IMG-01Image alt text✕ NGNo alt attribute✓ OKHas 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-02Image alt text✕ NGMissing alt; noisy alt on decoration✓ OKMeaningful alt; empty alt for decoration
- Give each
<source>in<picture>its ownwidthandheightMUSTPQ-R33 - Space is reserved at the right aspect ratio when the screen width switches, so the layout does not shift.
- Check:
IMG-03IMG-03Image width / height✕ NGLayout shifts after load✓ OKDimensions reserve the space
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>
<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-09List markup✕ NGA list in looks onlyNot exposed as a list of 3✓ OKMarked up with ul / li
- Give data tables a
<caption>and header cells<th>withscopeMUSTPQ-R35 - Screen readers then convey the table's subject and which header each cell belongs to.
- Check:
QA-23QA-23Table caption and headers✕ NGNo caption, no header cells✓ OKcaption and th scope expose structure
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
<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'sid, or nest the input inside the<label>. Either way, clicking the label focuses the input. Aplaceholderdisappears once typing starts, so use it for an example and give the field name in the label. - Check:
FRM-01FRM-01Label association✕ NGLabel and field are not linkeddoes nothing✓ OKfor/id link the label
focuses the field
FRM-02FRM-02Not placeholder alone✕ NGThe placeholder is the only name✓ OKA label provides the name
- Set a
typethat 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-03Input type✕ NGWrong keyboard appears✓ OKtype matches the input
- Set
autocompleteon name, email, phone, and address fields MUSTPQ-R38 - Browser autofill then works, which cuts effort and mistakes.
- Check:
FRM-04FRM-04autocomplete attribute✕ NGAutofill does not workEverything typed by hand✓ OKautocomplete states the purpose
Browser 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-05fieldset and legend✕ NGQuestion and options not linked✓ OKGrouped with fieldset / legend
- Associate error messages and hints with the input through
aria-describedbyMUSTPQ-R40 - The error is then read out when the input receives focus.
- Check:
FRM-06FRM-06Link error messages✕ NGThe field does not expose the error✓ OKTied with aria-describedby
Code example: an input with a label and a hint
<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.
| Meaning | Element to use | Incorrect 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
marginorgap. 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
roleto 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.