CodeBlanks Logo Icon CodeBlanks

Summary - Accessible widget

HTML course · Expert · Lesson 6/39

Write an accessible widget skeleton with all ARIA techniques.

What we learned in this group

In this group you met five techniques for accessibility:

  • WCAG principles: the POUR frame
  • Keyboard navigation: tabindex and focus management
  • Live regions: announcing with aria-live
  • Dialogs: <dialog> and aria-modal
  • Heading hierarchy: h1-h6 order

Now you will combine them into an accessible widget skeleton.

Exercise Write the accessible widget skeleton

Write an <h1> inside body (for example 'Settings'). Then add a <button id="opener" aria-haspopup="dialog"> (non-empty text). Then add a <dialog aria-modal="true" aria-labelledby="dlg-title">. Inside the dialog put an <h2 id="dlg-title"> (non-empty text), a <p role="status" aria-live="polite"> (non-empty text) and a <button> (non-empty text). Close the dialog.

Show example solution
<body>
  <h1>Settings</h1>
  <button id="opener" aria-haspopup="dialog">Edit profile</button>
  <dialog aria-modal="true" aria-labelledby="dlg-title">
    <h2 id="dlg-title">Reset profile</h2>
    <p role="status" aria-live="polite">Changes saved</p>
    <button>Close</button>
  </dialog>
</body>

Test yourself

  1. Match each technique to its purpose

    aria-live
    Announces dynamic content
    aria-modal
    Says it is a modal
    tabindex="0"
    Enters keyboard flow
    h1
    Main page title
    alt
    Image alternative text
  2. Write the opener button attribute

    <button id="open-btn" ____="dialog">Open</button>
    Show answer
    <button id="open-btn" aria-haspopup="dialog">Open</button>
  3. Which technique announces dynamic content to a screen reader?

    • tabindex
    • h1 heading
    • alt text
    • aria-live region
    Show answer

    aria-live region — Correct. The aria-live region announces dynamic content changes to the screen reader.

All lessons in Expert