Character
A character component displays a single character (glyph, symbol, emoji, or letter) with proper accessibility semantics. When the character conveys meaning (like a checkmark for success or a warning symbol), it uses role="img" with an aria-label so screen readers announce its purpose. When the character is purely decorative, the decorative prop hides it from assistive technologies.
This component is useful for initials, status indicators, rating symbols, decorative flourishes, and any place where a single glyph needs clear accessible context.
Implementation Notes
- Renders as a
<span>wrapper around the character content - Uses
role="img"witharia-labelfor meaningful characters so assistive technology announces the character's purpose - Uses
role="presentation"witharia-hidden="true"for decorative characters to hide from screen readers - Uses
slotfor children content - Spreads
...restPropson the root<span>element for consumer customization
Props
label: string (optional) -- accessible description of the character for screen readersdecorative: boolean (default: false) -- when true, hides the character from assistive technologychildren: slot (required) -- the character to display
Usage
Meaningful characters with accessible labels:
<Character label="Check mark">✓</Character>
<Character label="Warning symbol">⚠</Character>
Decorative character hidden from assistive technology:
<Character decorative>★</Character>
Status indicator in a task list:
<ul>
<li><Character label="Complete">✓</Character> Set up repository</li>
<li><Character label="In progress">◐</Character> Write documentation</li>
<li><Character label="Not started">○</Character> Add tests</li>
</ul>
Decorative drop cap at the start of a paragraph:
<p>
<Character decorative class="drop-cap">O</Character>nce upon a time, in a design system far, far away...
</p>
Keyboard Interactions
None -- this component is a passive display element.
ARIA
role="img"-- applied when the character is meaningful (decorative is false), indicating the span represents an image-like glyphrole="presentation"-- applied whendecorativeis true, removing semantic meaningaria-label-- provides the accessible name for meaningful characters; omitted when decorativearia-hidden="true"-- applied whendecorativeis true, hiding the element from the accessibility tree
When to Use
- Use for displaying a single glyph, symbol, or character that needs accessible context, such as a checkmark for success or a warning symbol.
- Use for decorative symbols like stars or flourishes where you want to hide them from assistive technology.
- Use for status indicators represented by a single character, such as a bullet or arrow.
- Use for decorative initial caps or drop caps at the start of a paragraph.
When Not to Use
- Do not use for emoji -- use Emoji with an accessible name instead.
- Do not use for icons -- use Icon instead.
- Do not use for multi-character text strings -- use a standard
<span>or text element instead.
Headless
This headless Character component provides the semantic <span> with conditional role="img" and aria-label for meaningful characters, or role="presentation" with aria-hidden for decorative ones. The consumer provides all visual styling including font size, color, spacing, and any decorative effects.
Styles
The consumer provides all CSS styling. The component renders with a .character class for targeting. No default styles are included — this is a fully headless component.
Testing
- Verify the component renders a
<span>element with classcharacter - Verify role="img"` -- applied when the character is meaningful (decorative is false), indicating the span represents an image-like glyph
- Verify role="presentation"
-- applied whendecorative` is true, removing semantic meaning - Verify aria-label` -- provides the accessible name for meaningful characters; omitted when decorative
- Verify pass-through attributes are applied
Advice
- Designers: Ensure meaningful characters have sufficient size and color contrast to be legible. Consider pairing symbols with supporting text for clarity.
- Developers: Always provide a descriptive
labelfor meaningful characters. Setdecorativeto true for purely visual symbols that add no information.
Related components
character-counter— a counter showing remaining or used characters in a text fieldkbd— show keyboard shortcuts and key combinations in a styled inline elementemoji— a single emoji character with accessible name