Standard Button
Learn the difference between a real button and a fake one. The <button> element is the foundation of accessible interactivity.
The Bad (Inaccessible)
<div class="btn" onclick="submitForm()">
Submit
</div>
Accessibility-Ready Code
<button type="submit" class="btn-primary">
Submit
</button>
button(type="submit" class="btn-primary") Submit
<button
type="submit"
className="btn-primary"
onClick={handleSubmit}
>
Submit
</button>
<button
type="submit"
class="btn-primary"
@click="handleSubmit"
>
Submit
</button>
<button
type="submit"
class="bg-indigo-600 px-6 py-3 text-white font-semibold rounded-md shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-indigo-600 transition-colors"
>
Submit
</button>
The Standard
The <button> element is the single most important interactive element in HTML. Using it correctly grants you free keyboard support, focus management, and screen reader clarity.
WCAG Criteria
- 2.1.1 Keyboard (Level A): All functionality must be operable via keyboard.
- 4.1.2 Name, Role, Value (Level A): The elementβs name, role, and state must be programmatically determinable.
β The Bad (Inaccessible)
Whatβs Wrong?
- No Keyboard Access: You cannot
Tabto a<div>. - No Role Announced: A screen reader just says βSubmitβ with no context. Is it a link? A heading?
- No Enter/Space Support: Pressing Enter does nothing.
β The Good (Accessibility-Ready Code)
Why This Works
- Native Keyboard: The browser automatically handles
Tab,Enter, andSpace. - Clear Role: Screen readers announce: βSubmit, buttonβ.
- Focus Ring: The browser provides a default
:focusoutline automatically.
Accessibility Checklist
- Use a
<button>element for all click actions. - Include a visible text label OR an
aria-labelfor icon-only buttons. - Ensure a clear
:focus-visiblestyle is always present. - Do NOT use
<div>or<span>withonclickfor buttons.
<!-- Native button -->
<button type="button" class="btn">
Save Changes
</button>
Technical Deep Dive
The Accessibility Tree
Role: button
Name: "Submit"
State: focusable
Focus Flow
- Tab Key: Captures
focusin. Highlighted via:focus-visible. - Enter / Space: Triggers
clickevent natively.
Interactive Behavioral Lab
Interactive Sandbox
π¬ Technical Internals
Understand how this component is processed by the browser and Assistive Technology (AT). This section bridges the gap between visual code and the hidden logic that powers accessibility.
π² Accessibility Tree
The data structure used by screen readers to "see" your page. It translates HTML roles and attributes into standardized objects.
βοΈ Event Logic
Expected behavioral standards for keyboard navigation and state transitions. Crucial for users who don't use a mouse.
- Focus: Highlights via
:focus-visible - Activation: Responds to
EnterandSpace - Role: Identified as
Button Pattern