Accessible HTML & ARIA Basics

Beginner · 11 min

Why semantic HTML is the first accessibility tool, and how to use ARIA only for the gaps native markup genuinely can't cover.

Before thisSemantic HTML & Document Structure

Fullstack Academy · 11 min

Accessible HTML & ARIA Basics

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Fullstack AcademyReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Accessibility isn't a separate feature bolted on at the end — it's a property of how correctly the underlying HTML describes the page.
  • The First Rule of ARIA is: if a native HTML element or attribute already gives you the behavior and semantics you need, use it instead of adding an ARIA role to a generic element.
  • Every meaningful image needs an alt attribute; decorative images should get alt='' so screen readers skip them instead of reading a useless filename.
  • Landmark roles (nav, main, banner, contentinfo) are what semantic elements already give you for free — ARIA roles only need to be added by hand when you're forced to build on a non-semantic element.
  • If every interactive element on your page can be reached and operated with only a keyboard, you've covered most of what makes a page usable for people who can't use a mouse.

Who you’re actually building for

It’s tempting to think of accessibility as a checklist for a specific minority of users — people using screen readers. That’s true but incomplete. Accessibility also covers someone navigating with only a keyboard because their mouse is broken, someone with low vision who’s zoomed the page to 300%, someone with a temporary injury who can’t grip a trackpad, and someone using voice control software to fill out a form by speaking field names aloud. The common thread isn’t a specific disability — it’s that each of these people is interacting with your page through something other than “look at it and click precisely where a sighted mouse user would.” Accessible HTML is markup that keeps working under all of those interaction styles, not just the one you tested in your own browser with your own mouse.

Semantic HTML is already most of the work

Here’s the thing that gets missed most often: if you wrote clean semantic HTML — the subject of this group’s first lesson — you’ve already done the bulk of accessibility work without thinking about it as “accessibility” at all. A real <button> is automatically keyboard-focusable, automatically responds to Enter and Space, and is automatically announced as “button” by a screen reader. A <nav> is automatically findable as a navigation landmark. A <label> connected to an <input> is automatically read aloud when that input gets focus. None of this required an ARIA attribute. It required using the element whose entire job is to be the thing you needed.

The failure mode to watch for is reaching for a generic element and recreating a native one’s appearance with CSS and a click handler — <div onclick="submit()">Submit</div> styled to look exactly like a button. Visually it’s identical. Functionally it’s broken: it’s not in the tab order, Enter and Space do nothing, and a screen reader announces it as plain, uninteresting text. This is why the first and most important accessibility rule is sometimes called the First Rule of ARIA, even though it’s really about avoiding ARIA: use the native element. A <button> costs nothing extra and gives you all of this behavior automatically.

Alt text: the first thing to get right

Every <img> needs an alt attribute, and the content of that attribute depends on what the image is doing. If the image conveys information — a chart, a product photo, an icon that’s the only label for a button — the alt text should describe what it conveys, concisely, as if you were describing it over the phone. If the image is purely decorative — a background flourish, a spacer, a stock photo with no informational content — the correct alt text is an empty string, alt="", which tells a screen reader to skip the image entirely rather than reading its filename or announcing “image” with no further context. Omitting alt altogether is the worst of both options: many screen readers fall back to reading the file path aloud, which is actively worse than silence.

Landmark roles and when ARIA actually earns its keep

ARIA stands for Accessible Rich Internet Applications, and it’s a set of HTML attributes — role, and attributes prefixed aria-, like aria-label and aria-expanded — that tell assistive technology about elements whose native semantics don’t cover what you need. The landmark roles (navigation, main, banner, contentinfo, and others) are the clearest illustration of why ARIA is a last resort rather than a first choice: <nav> already has the navigation role built in. <main> already has the main role built in. You only need to write role="navigation" by hand on a <div> if you’re stuck without the semantic element for some reason — and if you’re not stuck, writing the ARIA role instead of just using <nav> is strictly worse, because you still don’t get the native keyboard and focus behavior that comes bundled with the real element.

ARIA earns its keep for things HTML genuinely has no native equivalent for — a tab panel, a custom autocomplete combobox, a toast notification — where you’re building new interactive behavior that no single native tag covers. Even there, it’s additive on top of a sensibly chosen base element, not a replacement for choosing one.

Keyboard navigability as a litmus test

A fast way to sanity-check a page’s accessibility without any specialized tooling: unplug your mouse, or just put it aside, and try to use the whole page with Tab, Shift+Tab, Enter, and Space alone. Can you reach every link, button, and form field? Can you tell, just from looking at the screen, which element currently has focus? Can you operate a dropdown or a modal dialog without a pointer? If the answer to any of these is no, you’ve found a real accessibility gap — and in a large fraction of cases, the fix is simply swapping a non-semantic element for the semantic one that would have handled it automatically.

Check yourself

  1. 01What is the 'First Rule of ARIA,' and why does it exist?

    Use a native HTML element or attribute instead of ARIA whenever one already provides the semantics and behavior you need, because ARIA only changes what assistive tech is told about an element — it never adds the keyboard behavior, focus handling, or built-in logic that native elements already come with for free.

  2. 02What's the difference between alt text on a meaningful image and on a decorative one?

    A meaningful image needs alt text describing what it conveys, since a screen reader user otherwise misses that information entirely; a purely decorative image should get alt='' so the screen reader skips it rather than reading a meaningless filename or 'image' aloud.

  3. 03Why does <div onclick=...> fail as a button even if it looks and behaves like one visually?

    A <div> isn't in the keyboard tab order, doesn't respond to Enter or Space, and isn't announced as a button to a screen reader, so a keyboard or screen-reader user can't discover or activate it even though a mouse user sees something that looks clickable.

  4. 04When should you actually reach for an ARIA attribute?

    Only when you're building a custom interactive widget — like a custom dropdown or tab panel — that has no native HTML equivalent, and you need to manually supply the role, state, and keyboard behavior that a native element would otherwise give you automatically.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark