Screen Reader Compatibility

Screen reader compatibility means making a web interface understandable and operable through assistive technology. It depends on exposing meaningful structure, accessible names, states, relationships, and interaction behavior through the browser accessibility tree.

Screen readers obtain much of their information from the browser's accessibility tree rather than simply reading the visual pixels on the page. Semantic HTML gives browsers useful information about headings, landmarks, links, buttons, lists, forms, and other controls.

Interactive elements need an accessible name so users can identify their purpose. A button containing visible text usually gets its name from that text, while an icon-only button may need an explicit accessible label such as `aria-label` when no suitable visible text exists.

Dynamic interfaces must also expose relevant state and relationship information. Attributes such as `aria-expanded`, `aria-checked`, and `aria-selected` can communicate states when native HTML cannot express them, while relationships such as labeling and descriptions can connect controls with supporting text.

Keyboard accessibility and screen reader compatibility overlap but are not identical. A custom control can be keyboard-focusable yet still expose the wrong role, name, state, or behavior to assistive technology. Prefer native HTML controls because browsers already provide much of the expected semantics and interaction behavior.

ARIA should supplement semantic HTML rather than replace it unnecessarily. Incorrect roles, missing names, broken focus management, and dynamically changing content that is not announced can make an otherwise visual interface difficult or impossible to use with a screen reader.

Key points

Interview questions

What does screen reader compatibility mean in a web application?

It means that assistive technology can understand the important structure and controls of the page and communicate them to the user. Elements should have appropriate semantics, accessible names, states, and relationships. Interactive controls should also behave predictably when operated through supported input methods. Semantic HTML is usually the starting point.

Why is semantic HTML important for screen readers?

Semantic HTML tells the browser what an element represents instead of only describing how it should look. A native button, for example, exposes button semantics and expected interaction behavior. Screen readers can use these semantics to identify controls and their roles. This generally requires less custom accessibility code than recreating native elements.

What is an accessible name, and how can an element get one?

An accessible name is the text assistive technology uses to identify a UI element. Depending on the element, it can come from visible text, an associated `<label>`, or an appropriate ARIA naming mechanism. The name should describe the control's purpose rather than merely its appearance. Icon-only controls are a common case where developers need to provide an explicit name.

When should you use ARIA instead of native HTML?

Native HTML should normally be preferred because it provides established semantics and interaction behavior. ARIA is useful when native HTML cannot express the required widget semantics, relationships, or states. Adding ARIA does not automatically create keyboard behavior, focus management, or event handling. Custom widgets therefore require both correct semantics and correct interaction behavior.

How would you make a custom modal accessible to a screen reader?

I would first determine whether a native or well-supported dialog pattern can meet the requirement. The dialog needs an appropriate role, an accessible name, and relationships to relevant descriptive content when necessary. When it opens, focus should move into the dialog, and keyboard interaction should provide a predictable way to close it and prevent users from accidentally interacting with inappropriate background content. When it closes, focus should normally return to the element that opened it.