# Native-First & ARIA

> ARIA gives names, roles, and state to things the browser cannot infer on its own. But native HTML elements already carry their role and keyboard behavior built in, so the first rule of ARIA is: reach for a native element first, and use ARIA only for what HTML cannot express.

Subject: HTML | Lesson 34 of 42 | 7 min read
Interactive lesson: https://codewithanimation.in/html/native-first-and-aria
Previous: [article, section, aside & address](https://codewithanimation.in/html/article-section-aside-address.md) | Next: [Keyboard, Focus & Skip Links](https://codewithanimation.in/html/keyboard-and-focus.md)

## What ARIA is

ARIA (Accessible Rich Internet Applications) is a set of HTML attributes that modify what the browser communicates to assistive technology through the accessibility tree. There are three kinds: roles (`role="dialog"`), properties (`aria-label="Close"`), and states (`aria-expanded="true"`). ARIA does not add keyboard behavior, visual styles, or DOM structure. It only changes what AT hears. If you add `role="button"` to a `<div>`, the AT hears "button" but Tab still skips the element and Enter still does nothing. You have added the label without the substance.

The W3C First Rule of ARIA is: if you can use a native HTML element or attribute with the required semantics and behavior already built in, do so. A `<button>` is focusable with Tab, activatable with Enter and Space, and communicates `role="button"` automatically. A `<div role="button">` needs `tabindex="0"`, a `keydown` handler for Enter and Space, an `onclick` handler, and every ARIA state wired up manually. Native HTML buys you all of that for free.

## Why it matters

WCAG 4.1.2 (Name, Role, Value, Level A) requires that every user interface component exposes its name, its role, and any state or property that changes over time. Native HTML satisfies this automatically for interactive elements. ARIA lets you satisfy it for custom widget patterns that have no native equivalent: a tab panel, an autocomplete listbox, a tree view, a custom toggle button that is not a `<button>` for layout reasons.

Getting ARIA wrong is worse than using no ARIA at all. Incorrect roles confuse AT users who navigate by landmark or widget type. Stale state attributes (an `aria-expanded` that never updates from `false` to `true`) give false information. An `aria-hidden="true"` on a focused element removes it from the AT view while keyboard users can still reach it, creating a ghost interaction. The accessibility tree tells you what AT actually hears and is the ground truth for auditing ARIA.

## How to apply each ARIA category

**Roles** fill widget gaps. Use `role="tab"` + `role="tabpanel"` for tab interfaces, `role="dialog"` for a custom modal (paired with `aria-modal="true"` and focus trapping), `role="alert"` for urgent messages, `role="tooltip"` for hover descriptions. Do not override native roles: `<button role="link">` is contradictory.

**Properties** name and describe. Use `aria-label` for controls with no visible text label (an icon-only close button: `aria-label="Close"`). Prefer `aria-labelledby` when a visible heading already names the region, because the label stays in sync with visible text automatically. Use `aria-describedby` for supplemental hint text (a password requirement note tied to a password input). Properties do not change during interaction.

**States** reflect live conditions. Add `aria-expanded="false"` to an accordion trigger button and flip it to `true` with JavaScript when the panel opens. Add `aria-pressed` to a toggle button. Add `aria-checked` to a custom checkbox. If you do not update the state with JavaScript on every interaction, AT users see a permanently static state that does not match reality.

For dynamic content announcements, use `role="status"` (equivalent to `aria-live="polite"`) for non-urgent updates (form saved, item added to cart). Use `role="alert"` (equivalent to `aria-live="assertive"`) only for errors or urgent messages. Assertive live regions interrupt whatever AT is currently reading, so overusing them is disruptive.

## Common mistake: Adding role="button" without keyboard support

The most common ARIA mistake is making a `<div>` or `<span>` look like a button with `role="button"` and an `onclick` handler, then stopping there. Mouse users can click it. AT users hear "button". But keyboard users who press Tab skip it (no `tabindex`), and those who find it with arrow keys cannot activate it (no Enter or Space handler). The element passes a quick screen-reader skim but fails real keyboard navigation. The fix is always the same: use `<button>`. Its keyboard handling, focus management, and implicit role are battle-tested and require zero extra code.

## Tip: Audit ARIA with the browser accessibility tree, not the DOM

Open DevTools, find any element, and open the Accessibility panel. It shows the computed accessible name, role, and all states as AT sees them, not as you wrote them. This is the ground truth. Common discoveries: `aria-label` silently overriding a visible label you thought was being used; `aria-hidden` set on a parent that accidentally hides interactive children; `aria-expanded` stuck at `false` because the JavaScript that should flip it is broken. Five minutes in the accessibility tree finds bugs that hours of HTML reading misses.

## Try it: Try it

See what a native `<button>` provides for free versus what a `<div role="button">` still needs, and watch the three ARIA attribute categories in action.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/html/native-first-and-aria

## Check yourself

### Question 1

A <div role="button" onclick="..."> is clickable. What is still missing for full accessibility?

- A. tabindex="0" and a keydown handler for Enter and Space
- B. aria-label to name the button
- C. aria-pressed to track its state

Correct answer: A

A `<div>` is not focusable by default and responds to no keyboard events. Adding `role="button"` names it for AT but does nothing for keyboard users. You need `tabindex="0"` to put it in the tab order and a `keydown` handler for Enter and Space to activate it. A `<button>` provides all of this for free.

- Why not B: A name is important but is not what role="button" alone misses. The critical gap is keyboard operability: the div is not in the tab order and does not respond to keyboard activation.
- Why not C: aria-pressed is needed for a toggle button, but it is not the primary missing piece for a basic div+role=button. The gap is focusability (tabindex) and keyboard activation (Enter/Space).

### Question 2

A dialog has a visible h2 heading. Should you use aria-label or aria-labelledby to name it?

- A. aria-labelledby referencing the h2's id
- B. aria-label with the same text as the h2
- C. Neither; the h2 automatically names the dialog

Correct answer: A

Use `aria-labelledby` when a visible text element already names the widget. It references the element by `id`, so the accessible name stays in sync with the visible label automatically. `aria-label` is for when there is no visible label at all.

- Why not B: aria-label duplicates the visible text as an inline string that can get out of sync with the heading. aria-labelledby references the actual element, so the accessible name always matches what is on screen.
- Why not C: A heading inside a dialog does not automatically become the dialog's accessible name. You must explicitly link them with aria-labelledby pointing to the heading's id.

### Question 3

What is wrong with applying aria-hidden="true" to a focused <button>?

- A. The button is removed from the AT view but keyboard users can still reach and activate it
- B. aria-hidden only works on div elements, not buttons
- C. The button becomes invisible to sighted users as well

Correct answer: A

`aria-hidden="true"` removes an element from the accessibility tree, but it does NOT remove it from the tab order. A keyboard user can still Tab to the button and activate it, while AT hears nothing. The W3C Fourth Rule of ARIA prohibits using `aria-hidden` on focusable elements.

- Why not B: aria-hidden works on any element. The problem is not about which element it is applied to, but that hiding a focusable element creates a conflict between keyboard navigation and the AT view.
- Why not C: aria-hidden only affects the accessibility tree, not visual rendering or the DOM. The button remains visible and keyboard-focusable while being hidden from AT.

## Remember this

- Use native HTML elements first. `<button>` gives keyboard support, focus, and `role="button"` for free.
- `<div role="button">` requires `tabindex="0"`, Enter/Space `keydown` handlers, and every state update: all manual.
- Prefer `aria-labelledby` over `aria-label` when a visible text element already names the widget.
- Never put `aria-hidden="true"` on a focusable element: AT hides it but keyboard users can still reach it.
- `role="status"` = polite live region; `role="alert"` = assertive (interrupts AT immediately, use only for errors).
