Custom UI Principles
In these guidelines, "Custom UI" refers to bespoke interactive components that recreate, override, or extend browser-native elements (such as <select>, <dialog>, or <details>).
Implementing custom UI demands holistic engineering rigor across Coding Guidelines, Page Quality, and Accessibility Principles.
Why Native Elements Come First
Browser-native controls provide robust keyboard navigation, automated focus restoration, and programmatic state announcements out of the box.
When developing custom components, every lost accessibility feature must be meticulously reconstructed by hand. Teams must avoid shipping surface-level widgets that respond only to pointer clicks while failing to support keyboard users or assistive technology APIs.
Defining UI States During Design
Interactive controls have many more states than the default and hover states that static mockups usually show. The states to define, and the rules to meet before handoff, are in UI States.
What Replacing Native Elements Loses
Bespoke implementations frequently omit subtle yet vital browser behaviors:
| Native Element | Critical Behaviors Frequently Lost in Custom Builds |
|---|---|
<select> | Native mobile pickers (iOS wheels, Android dropdowns), type-ahead search filtering, and standard form submission serialization |
| Checkboxes / Radios | The :indeterminate pseudo-state, native constraint validation tooltips, and <label> click delegation |
<input type="date"> | OS-level calendar pickers, locale-aware date formatting, and assistive technology date synthesis |
<input type="range"> | Arrow key incrementation and live value announcements to screen readers |
<input type="file"> | Operating system drag-and-drop support and keyboard-driven file explorer triggers |
Styling Native Elements via CSS
Applying CSS to native elements via appearance: none preserves native accessibility contracts while allowing custom aesthetics. Transition to bespoke component development only when CSS genuinely cannot satisfy design requirements.
- Record why a native element cannot meet the requirements before building a custom one SHOULDUI-R06
- Write in the spec or ticket why
<select>,<dialog>,<details>and the like, even styled withappearance: none, are not enough. With the reason on record, custom builds do not spread where native elements would do. - Check:
UI-01UI-01Reason for a custom UI✕ NGNo reason why <select> won't do✓ OKReason is written in the spec
Definition of Done
Every custom component meets these rules before it is delivered.
- Make the component operable with the keyboard alone MUSTUI-R01
- Focus reaches it with
Tab,EnterorSpaceruns it, and overlays close withEsc. People who cannot use a mouse get the same functions. - Check:
UI-11UI-11Keyboard-only operation✕ NGEnter and Esc do nothing✓ OKWorks with the keyboard alone
- Keep the focus position visible MUSTUI-R02
- Do not set
outline: nonewithout a replacement. Keyboard users never lose track of where they are. - Check:
UI-06UI-06Visible focus ring✕ NGCannot see where focus is✓ OKFocus ring is visible
- Build triggers that open, close or run something as
<button>elements MUSTUI-R03 - Do not attach click handlers to
<div>or<span>. A<button>comes with keyboard operation and is announced as a button. - Check:
UI-07UI-07Trigger is a button✕ NGRole is not button✓ OKRole is button
- Switch state attributes together with the visible state MUSTUI-R04
- Keep
aria-expanded,aria-selectedandaria-currentmatching what is shown after every interaction. What screen readers announce never contradicts the screen. - Check:
UI-08UI-08State attributes follow✕ NGOpen on screen, still false✓ OKAttribute matches what is shown
- Return focus to the trigger when an overlay closes MUSTUI-R05
- A dialog moves focus to its first control when it opens and back to the button that opened it when it closes. Users carry on from where they were.
- Check:
MDL-03MDL-03Focus after closing✕ NGFocus jumps to page top✓ OKFocus returns to the opener
MNB-04MNB-04Focus after Esc closes✕ NGFocus does not return✓ OKFocus returns to the trigger
Patterns
The keyboard interaction and WAI-ARIA markup for each component are on these pages: