Skip to content

    Frontend System Design

    Design Systems and Accessibility

    Why a shared component library is the cheapest place to fix accessibility: build role, name, keyboard, focus and contrast rules in once, and test them once.

    By Published 13 min read

    • frontend-system-design
    • design-systems
    • accessibility
    • components
    • focus
    Share

    Standard lessonbeginnerFrontend System Design

    Before this: Component-Based Architecture

    What you'll learn: By the end of this lesson you will be able to explain why accessibility belongs in a design system's shared layer, say what a component library can guarantee and what only the product team can supply, write an accessibility contract for a component (role, name, keyboard, focus, state, visual rules), choose between a native element and a custom widget, and name the visual rules (contrast, target size, focus indicator, forced colours) that a shared stylesheet can break for every product at once.

    Think of a building code. A city could ask every shop owner to work out, alone, how wide a door must be and where a ramp goes. Some would get it right, most would guess, and each fix would help one door. Or the code can say it once, and every new door follows it. A design system is that code for a user interface, with the same two edges: a rule written once is followed everywhere, and a mistake written once is built everywhere.

    The running example is the ShopStream storefront and admin app, the front ends of the grocery marketplace used throughout this course. Two teams build screens. They share buttons, dialogs, text fields and a colour palette, and the question is where accessibility lives.

    The core idea

    1. A design system is a shared layer: tokens (named design decisions such as colours and spacing), components built from them, and rules for how both are used. This lesson uses that as a working definition. The next lesson, Design Tokens and Theming, goes deep on the tokens.
    2. Accessibility is cheapest at the shared layer. One fix to the Button reaches every screen that uses it. One defect in the Button reaches every screen too, so the layer deserves the most careful testing in the code base.
    3. The system can promise behaviour, not meaning. A component can guarantee its role, keyboard handling, focus order and contrast. It cannot make a vague label clear or an image description true. Those come from the product team.

    What the system can promise, and what it cannot

    Concern Decided by the design system Decided by the product team
    Role and semantics The element or pattern a component uses Whether the right component was chosen for the job
    Accessible name A required prop, so a name cannot be forgotten The words of the name
    Keyboard Which keys do what inside a widget Where the widget sits in the page's tab order
    Focus The focus indicator and where focus goes when a dialog opens Focus after a navigation or a deleted item
    State aria-* or native attributes kept in step with the visual state Which state the screen is in
    Contrast and target size The token pairs and minimum control sizes Text and images the product adds outside the components
    Content Nothing Headings, labels, error text, alt text, reading order

    The right column is why a library is not a certificate: a page of perfect components can still have no heading structure or a wrong image description. Semantic HTML and Document Structure covers the page-level half.

    Figure 1. Where a fix travels

    Accessibility in the shared layer reaches every productTokens to Components (colours, sizes); Components to Storefront; Components to Admin app; Components to Checkout; Tests to Components (guard)Tokens: contrast-checked pairsTokenscontrast-checkedpairsComponents: role, name, keyboard, focusComponentsrole, name,keyboard, focusTests: per componentTestsper componentStorefront: product screensStorefrontproduct screensAdmin app: product screensAdmin appproduct screensCheckout: product screensCheckoutproduct screenscolours, sizesguard

    How to read this: the accent box is the leverage point. A change there, good or bad, flows to all three products. That is why the tests sit on the components and not on each product screen alone.

    Start from the native element

    The most effective accessibility decision in a component library is also the oldest: use the element the browser already provides.

    WCAG 4.1.2, Name, Role, Value (Level A), requires that the name and role of each component can be programmatically determined. The W3C's explanation adds that standard HTML controls already meet it when used according to specification, while scripted or re-purposed controls need additional measures. The W3C's "Using ARIA" turns this into rules: use a native element or attribute when one already has the semantics and behaviour you need (the first rule), do not change native semantics unless you really have to, make every interactive ARIA control usable with the keyboard, and never put role="presentation" or aria-hidden="true" on a focusable element.

    The ARIA Authoring Practices Guide (APG) is blunt about why: its first section is titled "No ARIA is better than Bad ARIA", and it says that, unlike HTML input elements, ARIA roles do not cause browsers to provide keyboard behaviours or styling.

    Illustration 1: the minimal example

    Two ways to write the storefront's "Add to cart" control, A (the button) and B (the div):

    <button type="button">Add to cart</button>
    
    <div class="btn" onclick="addToCart()">Add to cart</div>

    Version B has no button role, so assistive technology is not told it is a button, and as written it has no tabindex and no key handler. To catch up it needs a role, a tabindex, key handlers and styling for states, each a place for the shared Button to drift from what users expect. Version A needs none of that, so a system's Button should render a button. Component Composition and API Design shows how a component can choose its element (button or link) without losing these semantics.

    MDN says an icon-only button has no accessible name until you put concise text in the element. A library can turn that into a required label prop, so the type checker refuses the call without it: an accessibility rule becomes a build-time failure.

    Keyboard and focus inside widgets

    Some widgets have no native element: tabs, menus, comboboxes, tree views. The APG lists patterns for them with the roles, states and keys each expects, and a shared library is the place to implement them once. Inside a composite widget the APG says the tab sequence should include only one focusable element of the composite, achieved by roving tabindex (the active item has tabindex="0", the others -1, and arrow keys move the 0 and call focus()) or by aria-activedescendant (the container holds focus and points at the active child by id).

    Figure 2. Roving tabindex in a toolbar

    sequenceDiagram accTitle: Roving tabindex in a toolbar accDescr: A keyboard user presses Tab and focus lands on the toolbar's active button, which has tabindex 0 while the other buttons have tabindex minus 1. Arrow Right moves tabindex 0 and focus to the next button. Tab leaves the toolbar as a whole to the next control on the page. participant U as Keyboard user participant T as Toolbar participant B as Buttons U->>T: Tab T->>B: focus the item with tabindex 0 U->>B: Arrow Right B->>B: previous item gets -1, next item gets 0 and focus U->>T: Tab T-->>U: focus leaves the whole toolbar

    How to read this: the toolbar is one stop in the tab order, however many buttons it holds. Arrow keys move inside it; Tab moves past it.

    Illustration 2: the realistic example

    The storefront opens a "Remove this item?" confirmation. The system's Dialog is built on the native dialog element and opens it with showModal(). MDN says a dialog opened that way is modal: the browser makes the rest of the document inert, shows a backdrop, closes it on Esc by default, and sets focus on the first focusable element inside it (or one marked autofocus). Its implicit role is dialog, exposed as aria-modal="true"; a dialog opened with show() is non-modal and does not close on Esc. The component gets those behaviours from the platform and supplies the rest:

    Contract line Dialog
    Role Native dialog, opened with showModal()
    Name A required title prop wired to the dialog's accessible name
    Keyboard Esc closes it; the rest of the document is inert while it is open
    Focus An initial focus rule (MDN: put autofocus on the element the user should interact with first) and a documented rule for where focus returns on close
    Visual Backdrop and border meet the non-text contrast token pair; buttons meet the target-size minimum

    MDN's dialog page does not say where focus goes when the dialog closes, so the component must set and test that rule itself.

    Visual rules belong in the shared stylesheet

    The system owns the CSS, so it owns the visual criteria that the stylesheet can break.

    Contrast. WCAG 1.4.3 (AA) sets 4.5:1 for normal text and 3:1 for large-scale text, which it defines as at least 18 point or 14 point bold. The W3C explains that computed values must not be rounded: a ratio of 4.499:1 does not meet 4.5:1. WCAG 1.4.11 (AA) asks for 3:1 against adjacent colours for what identifies a user interface component and its states, such as a focus ring. The next lesson turns these numbers into token pairs that a test checks.

    Not by colour alone. WCAG 1.4.1 (Level A): colour is not the only visual means of conveying information, so an error needs text or an icon, not only a red border.

    Target size. WCAG 2.5.8 (AA) requires pointer targets of at least 24 by 24 CSS pixels, with exceptions (spacing, an equivalent control, inline targets, user-agent controls, essential cases). MDN's button page recommends 44 by 44. A system can set a minimum size on its controls.

    Focus indicator. WCAG 2.4.7 (AA): a keyboard-operable interface has a mode where the focus indicator is visible. MDN says :focus-visible lets you restyle the indicator without changing when it shows, warns that removing focus styles makes keyboard navigation inaccessible, and notes the indicator should reach 3:1. WCAG 2.4.11 (AA) adds that a focused component must not be entirely hidden by author-created content such as a fixed header.

    Forced colours. In forced colours mode (Windows High Contrast is the main example) the browser replaces author colours with a user-chosen palette. MDN says color, background-color, border-color, outline-color and SVG fill and stroke ignore author values, and box-shadow and text-shadow are forced to none. System colours follow native element semantics, not ARIA roles. The feature has been widely available since September 2022.

    Figure 3. A decision for each new component

    flowchart TD accTitle: Choosing how to build a shared component accDescr: A decision flow. If a native element has the semantics and behaviour needed, use it and style it. If not, find the APG pattern and implement its roles, states and keys. Either way, write the accessibility contract, add tests for keyboard, name and states, and check the token pairs for contrast and target size. A{"Does a native element
    give the semantics
    and behaviour?"} A -->|"yes"| B["Use it and style it
    (keep the focus indicator)"] A -->|"no"| C["Find the APG pattern
    and implement its roles,
    states and keys"] B --> D["Write the contract:
    role, name, keyboard,
    focus, state, visual"] C --> D D --> E["Tests for keyboard, name
    and states; token pairs
    checked for contrast and size"]

    How to read this: the native-element question comes first because it removes the most work and the most risk. The contract and the tests are the same for both branches.

    Illustration 3: a failure, a reset that hides focus

    The system's base stylesheet removes the outline from every interactive element because the default ring clashes with the brand. Keyboard users tab through the storefront and nothing shows where focus is, in every product the same day. WCAG 2.4.7 asks for a visible indicator. The fix is to restyle, not remove: draw a ring with :focus-visible and check its colour against the surface.

    Trade-offs

    Choice Gain Cost
    Accessibility built into shared components One fix reaches every product; tests run once A defect reaches every product too; the library team carries the responsibility
    Native elements first Behaviour supplied by the platform; fewer ARIA mistakes Styling limits on some elements; fewer visual options
    Custom widgets from APG patterns Patterns for tabs, menus and comboboxes the platform lacks Real work in keys and focus; testing with assistive technology is still required
    Accessible by default, escape hatches allowed Teams can ship unusual layouts Escape hatches bypass the guarantees and need review

    Build it

    This lesson has no lab. The numeric rules (contrast pairs, themes) are run in the lab of the next lesson, Design Tokens and Theming. As a paper exercise, write the contract table (role, name, keyboard, focus, state, visual) for a Tabs component using only the APG tabs pattern and the rules above, then write one test sentence for each row. No output is shown or claimed for this lesson, and no screen reader or browser was run for it.

    In practice: one library for two apps

    NOTE

    This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.

    The situation

    The ShopStream storefront and admin app each grew their own buttons, dialogs and form fields. An internal audit of both finds an icon button with no name, a custom dropdown that cannot be used from the keyboard, three different focus rings (one invisible), and error states shown only by colour. The same defects recur because each team re-implements the controls.

    Starting architecture

    Figure 4. Two apps, two sets of controls

    Starting architecture: every app owns its controlsStorefront to Audit findings; Admin app to Audit findingsStorefront: own Button, Dialog, SelectStorefrontown Button,Dialog, SelectAdmin app: own Button, Dialog, SelectAdmin appown Button,Dialog, SelectAudit findings: same defects twiceAudit findingssame defectstwice

    How to read this: the warning boxes are the duplicated controls. Every defect found in one app is likely present in the other, and a fix has to be made twice.

    Options considered

    Option What it fixes What it costs Risk
    Fix each app separately Fastest for the worst defects Work is done twice and drifts again The next component repeats the same mistakes
    Adopt an existing third-party component library Patterns already implemented Visual and API fit; upgrade cadence outside your control Gaps stay hidden; its guarantees must still be checked
    Build a small shared library from native elements Control of behaviour and look; contracts you own Maintenance; the library team needs accessibility skill A bug is shipped everywhere at once

    The decision

    Field Decision record
    Context Two apps duplicate controls and their accessibility defects.
    Decision Build a small shared library starting with Button, IconButton, Dialog and TextField on native elements. Each has a written contract (role, name, keyboard, focus, state, visual), a required name where relevant, and tests. The base stylesheet restyles focus and never removes it.
    Consequences, good One fix reaches both apps; reviews check a contract, not a guess; new screens start accessible by default.
    Consequences, bad A defect in the library reaches both apps; the library team owns a standing responsibility; escape hatches need review.
    Revisit when A third app, a framework change or a rebrand changes what must be shared.

    Rollout and verification

    1. Write the contract first, one table per component, reviewed by someone who works keyboard-only.
    2. Replace one control at a time behind the existing components, so each swap is small.
    3. Test each component for its keys, name and states (see the testing lessons in this module) and keep a manual keyboard pass in the release checklist.
    4. Check the token pairs in the build, as the next lesson shows.
    5. Run a manual pass with a screen reader and in forced colours for the dialog and form field.

    The 2 a.m. failure

    A library release changes the focus ring from an outline to a box-shadow. In forced colours mode box-shadow is forced to none, so Windows High Contrast users lose the focus indicator on every button in both apps.

    First three checks: (1) compare focus styles before and after the release; (2) turn on forced colours (or the developer tools emulation) and tab through a page; (3) check whether the contract mentions forced colours. Mitigation: restore an outline (MDN says outline-color is replaced by a system colour while the outline remains) and patch. Follow-up: add forced colours to the checklist for any change to focus, border or shadow tokens.

    Architect's notes

    • Write the contract before the component. Six lines per component find most problems before any code exists.
    • Make the right thing the easy thing: required names, a safe focus ring, sensible minimum sizes.
    • Keep escape hatches visible, and say in the docs what the library does not do.

    Common mistakes

    • A div with a click handler as a button, or ARIA added where a native element would do.
    • Removing the focus outline in a global reset.
    • Icon-only buttons with no accessible name, or colour as the only signal.
    • Treating a passing automated check as proof. It cannot judge whether a label makes sense.
    • Never testing in forced colours or with assistive technology. The APG says to test interoperability before using its code in production.

    Key takeaways

    • A design system's shared layer is the cheapest place to fix accessibility, and the most expensive place to break it.
    • A library can promise role, keyboard, focus and contrast; the product team supplies content and structure.
    • Use the native element first; ARIA roles do not add keyboard behaviour.
    • Turn rules into types and tests: required names, contract tables, token checks.
    • Focus indicators, contrast, target size and forced colours are properties of the shared stylesheet; guard them there.
    • Write a contract per component: role, name, keyboard, focus, state, visual.

    Practice exercises

    Exercise 1: Starter (30 min). Pick three controls in an app you know. For each, say whether the native element is used and write its accessible name. Which one has none?

    Exercise 2: Intermediate (2 hours). Write the contract table for a Select and a Tabs component from the APG patterns. List the keys each must support and where focus goes.

    Exercise 3: Advanced (half day). Review a base stylesheet for rules that remove outlines, rely on box-shadow for focus, or use colour alone. Propose replacements and say how you would test each in forced colours.

    In this course:

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments