Skip to content

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:

Behaviors often lost when replacing native elements
Native ElementCritical Behaviors Frequently Lost in Custom Builds
<select>Native mobile pickers (iOS wheels, Android dropdowns), type-ahead search filtering, and standard form submission serialization
Checkboxes / RadiosThe :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 with appearance: none, are not enough. With the reason on record, custom builds do not spread where native elements would do.
Check: UI-01UI-01 Reason for a custom UI✕ NGNo reason why <select> won't doCustom select spec has no reason native will not do✓ OKReason is written in the specCustom select spec states why native will not do

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, Enter or Space runs it, and overlays close with Esc. People who cannot use a mouse get the same functions.
Check: UI-11UI-11 Keyboard-only operation✕ NGEnter and Esc do nothingTab reaches it, but Enter does not run it and Esc does not close it✓ OKWorks with the keyboard aloneTab reaches it, Enter runs it and Esc closes it
Keep the focus position visible MUSTUI-R02
Do not set outline: none without a replacement. Keyboard users never lose track of where they are.
Check: UI-06UI-06 Visible focus ring✕ NGCannot see where focus isOutline: none hides the ring when the button is focused✓ OKFocus ring is visibleThe button shows a ring when focused with Tab
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-07 Trigger is a button✕ NGRole is not buttonThe open trigger is a div with a click handler✓ OKRole is buttonThe open trigger is a button element
Switch state attributes together with the visible state MUSTUI-R04
Keep aria-expanded, aria-selected and aria-current matching what is shown after every interaction. What screen readers announce never contradicts the screen.
Check: UI-08UI-08 State attributes follow✕ NGOpen on screen, still falseThe panel is open but aria-expanded stays false✓ OKAttribute matches what is shownThe panel is open and aria-expanded is true
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-03 Focus after closing✕ NGFocus jumps to page topAfter Esc closes the dialog, focus lands at the top of the page, not on the opening button✓ OKFocus returns to the openerAfter Esc closes the dialog, focus returns to the button that opened it MNB-04MNB-04 Focus after Esc closes✕ NGFocus does not returnAfter Esc closes the menu, no element has focus✓ OKFocus returns to the triggerEsc closes the menu and focus returns to the trigger

Patterns ​

The keyboard interaction and WAI-ARIA markup for each component are on these pages: