KodingKaro
HTML · Intermediate · Accessible HTML

Keyboard behavior and when to use ARIA

Native HTML controls already support many keyboard and assistive-technology behaviors; ARIA should fill real gaps rather than replace them.

✓ What you will learn in this topic

  • Explain the purpose of Keyboard behavior and when to use ARIA in a real HTML document.
  • Choose and apply the elements shown in both examples.
  • Recognize the specific mistake described in this lesson.

Concept explanation

Links navigate; buttons perform actions. Inputs and selects expose their own interaction patterns. Replacing them with clickable div elements means recreating focus, keyboard activation, disabled states, and semantics. ARIA can add a name, role, or state to custom widgets, but it does not implement behavior. Use aria-label only when a visible label is unavailable or unsuitable, and keep it consistent with visible text.

Syntax

Prefer native a, button, input, and select elements; use ARIA to communicate missing semantics, not to simulate behavior.

Example 1: a small page

The anchor navigates and the button performs an action, each using its native purpose.

<a href=\"/schedule\">View the schedule</a>
<button type=\"button\">Add reminder</button>

Expected result: Both controls can be reached and activated with standard keyboard interaction.

Example 2: a practical page

ARIA communicates the current disclosure state and relationship; application behavior must still update the state and visibility.

<button type=\"button\" aria-expanded=\"false\" aria-controls=\"faq-answer\">How do refunds work?</button>
<div id=\"faq-answer\" hidden>Refunds are available within 14 days.</div>

Expected result: Assistive technology can learn that the button controls a collapsed answer; custom interaction must change aria-expanded and hidden together.

Common mistakes

Do not use ARIA roles to imitate a native link or button when the native element already supplies the behavior.

Best practices

Prefer native HTML, visible labels, descriptive link text, logical headings, and keyboard testing before adding ARIA.

Practice exercise

Review an existing page using only the keyboard. Improve its heading order, form labels, link text, and button behavior; add ARIA only if a native element cannot express a required name or state.

Lesson summary

  • Native controls include behavior; ARIA communicates semantics and state but does not create interaction.
  • Prefer native HTML, visible labels, descriptive link text, logical headings, and keyboard testing before adding ARIA.

Knowledge check

Does role=\"button\" make a div keyboard-operable by itself?

Show the explanation

No. A role communicates a semantic role but does not add button focus and keyboard activation behavior.

Practical example

html
<a href=\"/schedule\">View the schedule</a>
<button type=\"button\">Add reminder</button>

Expected result:

Both controls can be reached and activated with standard keyboard interaction.

Hands-on practice task

Review an existing page using only the keyboard. Improve its heading order, form labels, link text, and button behavior; add ARIA only if a native element cannot express a required name or state.

In this section

Other lessons in Accessible HTML

Broaden your knowledge

Related learning topics