Skip to contentSkip to navigationSkip to topbar
Figma
Star

Text

Version 10.1.1GithubStorybook

The Text component is a primitive of the system and can output any supported text style provided by our design tokens. Coupled with Box, it underpins most of our components.

Component preview theme
<Text as="p">Hello</Text>

Guidelines

Guidelines page anchor
(information)

Please note

Only use this component if all other Paste typographic components don’t meet your use case. If you find yourself here, come to the Design System Office Hours.

About Text

About Text page anchor

The Text component is a design primitive. It is designed to be used when other typographic components in Paste do not meet your requirements. It is a styled component that allows you to create text styles with values from our design tokens. When using the Text component you can create any type of UI text and always be using the Twilio design language.

The Text component allows you to set style properties for common text styles. These properties include font family, color and line-height. You can only select design tokens as the value of each property. You can use any combination of the different properties, though.

Style properties on the Text component can be set with a single value or a responsive value. By setting a responsive value, you can control how your text will appear at each breakpoint the theme supports. This can be useful in supporting responsive designs for different screen sizes.

Via the as property, you can also set the Text component to render as any HTML element.

The Text component can be used in any situation. As always, when working with HTML you need to make a careful choice to select an appropriate semantic for your text. That semantic communicates the intended meaning of that text to assistive technology.

(information)

Be sure to use the "as" prop to select semantically meaningful HTML elements. The "as" property is required. As a fallback, the Text component will render as a span which may not be suitable for your use-case.

Component preview theme
<Text
as="p"
fontWeight="fontWeightMedium"
fontSize="fontSize30"
marginBottom="space40"
color="colorTextSuccess"
>
Hello
</Text>

You can set an array of values to any style property supported by the Text component. By providing an array of styles you can declare how the text should appear for each breakpoint. You can provide as many styles as there are breakpoints supported by the theme. Each style you provide in the array will match a breakpoint in the theme object, based on the same order.

Component preview theme
<Text
as="p"
fontSize={["fontSize20", "fontSize40", "fontSize60"]}
color={["colorTextBrandHighlight", "colorTextSuccess", "colorTextError"]}
>
Hello
</Text>

Tokens as pseudo-class props

Tokens as pseudo-class props page anchor

To view the full list of pseudo-class props, check the props table.

Component preview theme
<Text
_hover={{color: 'colorTextLink', cursor: "pointer"}}
>
Hover over me!
</Text>

There are many pre-styled text components in Paste. For example, Heading, Paragraph and InputLabel. You should use those components wherever possible. Only when your use case cannot be met by these components should you reach for the Text component.

The best use case for the Text component is when you are working with a design partner and are creating a net new experience not already covered by Paste. The Text component will be the easiest way to recreate your new experience using the Twilio design language.

Do

Explore what’s in Paste that will meet your needs first. For example, the Paragraph and Heading components

Don't

Don’t reach for the Text component as your first option

Do

Use the Text component to create entirely new experiences not covered by Paste

Don't

Don’t use the Text Component to recreate a slightly different version of a pre-existing Paste component

Do

Use the Text component for all styled text that doesn’t already exist in Paste

Don't

Don’t use base HTML elements for your text since there are no global styles

Do

Always set the “as” property to ensure you are making a suitable semantic choice

Don't

Don’t use the Text component without setting the “as” property