Token
Token is a compact representation of an object, and is typically used to show a collection of related metadata.
Page navigation navigation
A Token can be static text, a link or a button, and may be removable.
Accessibility and usability expectations
Presentation
Cognition
- A
Tokenmust be implemented using appropriate semantic HTML:- Use
<span>for static text - Use
<a>for links - Use
<button>for buttons
- Use
- If a
Tokenis a link or button and removable via Backspace or Delete, this keyboard functionality must be communicated to screen reader users via accessible name or description - A
Tokenmay have a leading visual (icon) which is decorative only and should be hidden from screen readers - A removable
Tokenmust contain a close icon to visually indicate removability
Vision
- Text within a
Tokenmust meet a minimum contrast ratio of 4.5:1 against its background - The default
Tokenin dark mode does not meet this requirement (grey on dark grey) - An interactive
Tokenmust have a visible custom focus style that meets a minimum contrast of 3:1 against the background - Avoid relying on browser defaults due to poor contrast in some environments
Mobility
- The control for removing a
Tokenmust meet a minimum target size of 24 by 24 CSS pixels- The small and medium variants currently do not meet this requirement
Adaptability
- Text resizing and spacing adjustments must be supported
- Content must remain readable without requiring horizontal scrolling at small screen widths (e.g., 320 CSS pixels)
Interaction
Keyboard
- A removable
Tokenmust be dismissible via keyboard (e.g.BackspaceorDelete) - A static text
Tokenthat is removable must include a<button>with an accessible name indicating theTokenthat will be removed
Engineering for AT Compatibility
Screen reader
- A removable
Tokenmust include accessible names or descriptions for screen readers that clarify:- That the
Tokenis removable - How it can be removed (e.g., by keypress if no visible remove button is present)
- That the
- Icons used as leading visuals should be hidden from screen readers if they are decorative
Speech recognition
- For both interactive an
Token(marked up as<button>) and aTokenthat includes a separate remove button, the accessible name of the button must include the visible label text. This ensures that speech recognition users can activate the button by speaking the visible label
Built-in accessibility features
Tokenare a<span>by default, but a link can use an<a>and a button can use a<button>by specifying the appropriate element with theasprop- The default color meets the minimum contrast requirement of 4.5:1 between foreground and background colors
- A
Tokenthat is interactive has a visible focus style - A
Tokenthat is removable has a close icon - The control for removing a
Tokenmeets the minimum target size of 24 by 24 CSS pixels in thelargeandxlargevariants - The removable
Tokenhas built in keyboard accessibility - A static text
Tokenthat is removable contains a<button>with an accessible name that conveys whichTokenwill be removed - A
Tokenthat is a link or a button and is removable includes the instructions " (press backspace or delete to remove)" for screen reader users as part of the accessible name by default.IssueTokendoes not include the instruction
Implementation requirements
- If using custom colors, ensure the text in a
Tokenhas a minimum contrast of 4.5:1 against theTokenbackground - If a
Tokenhas the functionality of a link (takes a user to a page) or a button (performs an action), set the appropriate semantic element by using theasprop - When using a removable
Tokenthat is a link or button, do not use the small or medium variants as the close control does not meet the minimum target size and spacing requirements of 24 by 24 CSS pixels - If an
IssueTokenis a link or a button and is removable, the keyboard instructions " (press backspace or delete to remove)" must be added to the accessible name or description for screen reader users, as they are not included by default - Only use decorative icons for the leading visual as a text description cannot be set
How to test the component
Integration tests
- The text contrast of custom colors meets the minimum requirement of 4.5:1 between foreground and background colors
- A
Tokenis implemented using the appropriate HTML element:- A
Tokenthat is a link uses an<a>element - A
Tokenthat is a button uses a<button>element - A
Tokenthat is text uses a<span>element
- A
- A
Tokenthat is removable and is a link or a button use either thelargeorxlargevariant. Thesmallandmediumvariant's close control do not meet the minimum target size and spacing requirements - If an
IssueTokenis a link or a button and is removable, the keyboard instructions " (press backspace or delete to remove)" has been added to the accessible name or description - A leading visual is only used for decorative purpose
Component tests
- The text contrast of default colors meet the minimum requirement of 4.5:1 between foreground and background colors
Tokenthat is interactive has a visible focus style- When a
Tokenis removable it has a close icon - In the
largeandxlargevariants of aToken, the target size, including spacing of the control for removing theToken, is at least 24 by 24 CSS pixels - If a
Tokenis removable and is a<span>, then the control to remove theTokenis a<button>with a descriptive accessible name, and is focusable with the "Tab" key and can be activated using the "Esc" and "Space" keys - If a
Tokenis removable and is an<a>or a<button>:- a close button is not rendered, the
Tokenis removed by focusing theTokenand using the "Backspace" or "Delete" keys - the text "(press backspace or delete to remove)" is included as visibly hidden text in the link/button so it is part of the accessible name
- a close button is not rendered, the