
Options
Text supports body text, headline, and eyebrow configurations with multiple sizing options to accommodate various typography scenarios.Body Text
Body Text sizing
Styling
Headline
Headline sizing
Eyebrow
Eyebrow sizing
Behavior
Text responds to different style and size requirements while maintaining consistent typography.Usage Guidelines
Content
Content within Text should follow typography best practices for readability and hierarchy.Accessibility
Out of the box, text provides necessary accessibility around sizing and color contrast.Text color contrast with backgrounds
Text should follow the WCAG AA guidance on color contrast. By default, Anvil’s Text will provide at least 4.5:1 contrast with a white background. Use caution when using subdued on other background values, or when using custom color values in general, as they may not meet contrast guidance. For more guidance on text hierarchy and semantic markup, see semantic markup best practices.Code
- Implementation
- Text Props
Common Examples
Text variants
TheText component accepts one of three options for the variant prop:"body"(default): renders as HTMLporspanelement, ifinlineis set totrue"eyebrow": renders as HTMLspanelement"headline": renders as HTML heading element (h1throughh4) element, based onelprop
Body
Eyebrow
Headline
Headlines without a bottom margin
Headlines carry a bottom margin so they space correctly above the content that follows. When a headline is aligned against a sibling element instead, that trailing margin shifts it off center. SetnoMargin to drop it:Nesting body text
When using body text within body text, make sure to use theinline prop on any of the child Body components to render a span instead of p.Subdued body text
Ifsubdued is set to true on a body text, it will use a de-emphasized color:The useAccessibleColor hook
The Anvil2useAccessibleColor hook makes it easy to determine which text color to use given a specific background color without making it inaccessible. This hook accepts two parameters, and returns an object with both foreground and background colors. In the case that no color can be made accessible with the given color, the background color will be adjusted until it can.