Text
A typographic component for sentences, paragraphs, and general basic pieces of text.
Hierarchy
The basic hierarchy of text sizes available. If no size is provided, it defaults to "m"
.
Editable example
Best practices
- Avoid manually applying a
className
to override thecolor
,text-align
,font-weight
, orfont-size
. All of these parameters are handled by the component's props. - Text components do not contain any inherent spacing. It's recommended to use the layout to determine spacing. Rather than applying a
className
and applying amargin
orpadding
to the text, use the containing element withdisplay: flex;
ordisplay: grid;
andgap
to determine spacing.
Element
Determines the underlying HTML
element rendered by the component. By default it's a <span>
, but can be changed to any other element such as a <p>
for paragraph text.
Editable example
Secondary
Secondary text should be used to reduce emphasis on text with a fainter text color.
Editable example
Strong
Use the strong
prop to make text appear bolder for emphasis. Note that this does not change the rendered HTML
element to a <strong>
tag. If the text is not just cosmetically bolder but should be read by a screen reader with more emphasis, you can also set it to render a <strong>
tag with element="strong"
.
Editable example
Alignment
Alignment can be set using the align
prop. Defaults to left aligned.
Editable example
Theme
Change the theme for text to match its context.
Editable example
Accessibility
Avoid manually overriding the text color and instead use the secondary
prop to dim less important text and the theme
prop to use appropriate colors for a light or dark theme. The default colors assigned for each of these props have been chosen to meet the WCAG AA minimum contrast ratio.
Figma text styles
There's an explicit mapping of text styles to React components for the standard and strong variants. Figma doesn't store text color or alignment in text styles though, so those variants need to be inferred. Rule of thumb is if the text color is Slate-80
in Figma, it should be the secondary
variant.
Figma text style | React component |
---|---|
Text/Size XL | <Text size="xl"> |
Text/Size L | <Text size="l"> |
Text/Size M | <Text size="m"> |
Text/Size S | <Text size="s"> |
Text/Size XS | <Text size="xs"> |
Text/Strong/Size XL | <Text strong size="xl"> |
Text/Strong/Size L | <Text strong size="l"> |
Text/Strong/Size M | <Text strong size="m"> |
Text/Strong/Size S | <Text strong size="s"> |
Text/Strong/Size XS | <Text strong size="xs"> |