Skip to content
engineering workbench.by StudyPort Academy
Learning path
Foundations18 minLESSON 05 / 16

Accessibility basics

A screen reader does not describe your colors. It speaks the role, the name, and the state the browser built from the elements. Toggle the two versions and listen to the difference before you read on.

Semantic markup
<main>
  <h1>Rain gauge</h1>
  <button type="button">Save note</button>
</main>
Div soup
<div class="main">
  <div class="title">Rain gauge</div>
  <div class="save" onclick="save()">Save note</div>
</div>

A screen reader would start with: main landmark. heading, level 1, Rain gauge. button, Save note.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

The semantic version announces a landmark, a heading level, and a button. The div version announces groups and text. The sandbox HTML is the semantic one, and the script reads those tags.

+Go deeper

The accessibility tree

The browser builds a tree of roles, names, and states from the HTML. starts there. A such as main, h1, or button supplies a role. A div supplies a generic group.

The name comes from text

A button's name is its text. An input's name is its label, the same label the forms lesson tied to the field. An image's name is its alt: describe what a meaningful image shows, and use an empty alt when the image is only decoration so it is skipped. A heading's name is its text, plus the level from the tag. Keep the levels in order, h1 then h2 then h3, because many people move through a page heading by heading. strong and em carry meaning. b and i are only a bold or italic look, so they are not announced as emphasis. If the words exist only in a picture, they are not in the tree.

Semantic markup and div soup

The toggle you used is the whole lesson in one switch. The semantic column exposes main, a level-1 heading, and a button. The div column exposes groups. The words Rain gauge and Save note appear in both. Only one version says what those words are.

What gets announced
MarkupRoleName
mainlandmarkFrom the heading or label inside
h1heading, level 1Rain gauge
buttonbuttonSave note
divgroupWhatever text is inside, with no role

Keyboard is part of the element

A button can be reached with Tab and pressed with Enter or Space. A div cannot, until you add that behavior yourself and keep it in sync. Prefer the element that already has the keyboard path. A table header from the last lesson is the same idea: the element carries the meaning.

Listen before you paint

Read the announcement for the semantic version, then the div version, before you change any color. If the role is missing, fix the element. The script below only confirms the tags you can already see.

04

Guided challenge

Accessibility basics

The control is a button element, not a class of save. Read the button so the logs show button, Save note, main, and Rain gauge.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

EXPECTED CONSOLE OUTPUT

button
Save note
main
Rain gauge

Hints 0/2

    Use all hints or make 3 failed runs (0/3).

    05

    Free sandbox

    Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.

    Opening editor…
    LIVE PREVIEW
    Console 0

    Your console output appears here.

    Saved on this deviceJavaScript · ES2022
    06

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01What does a screen reader use for a button name?
    02Why is a div a weak substitute for a button?

    Ready to call this one understood?

    Mark this lesson complete to earn 100 XP. You can always revisit it.

    Sign in to save progress
    Next lesson