Skip to content
Change the site theme
(information)

Text

A primitive component that can be used to create all text styles in Paste


Guidelines

Guidelines page anchor
Information icon

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.

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.

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(link takes you to an external page) 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 icon

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.

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.

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.

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


Installation

Installation page anchor
yarn add @twilio-paste/text - or - yarn add @twilio-paste/core
import {Text} from '@twilio-paste/text';
const Component = () => (
<Text as="p" fontSize="fontSize70" fontWeight="fontWeightMedium">
Foo
</Text>
);

All the regular HTML attributes (role, aria-*, type, and so on) including the following custom props:

PropTypeDescriptionDefault
as?keyof JSX.IntrinsicElementsA custom HTML tagdiv
display?ResponsiveValue<CSS.DisplayProperty>
fontFamily?ResponsiveValue<keyof ThemeShape[fonts]>
fontSize?ResponsiveValue<keyof ThemeShape[fontSizes]>
fontStyle?ResponsiveValue<CSS.FontStyleProperty>
fontWeight?ResponsiveValue<keyof ThemeShape[fontWeights]>
letterSpacing?ResponsiveValue<CSS.LetterSpacingProperty<TLengthStyledSystem>>
lineHeight?ResponsiveValue<keyof ThemeShape[lineHeights]>
margin?ResponsiveValue<keyof ThemeShape['space']>One of our spacing tokens
marginTop?ResponsiveValue<keyof ThemeShape['space']>One of our spacing tokens
marginRight?ResponsiveValue<keyof ThemeShape['space']>One of our spacing tokens
marginBottom?ResponsiveValue<keyof ThemeShape['space']>One of our spacing tokens
marginLeft?ResponsiveValue<keyof ThemeShape['space']>One of our spacing tokens
overflowResponsiveValue<CSS.OverflowProperty>;
overflowXResponsiveValue<CSS.OverflowXProperty>;
overflowYResponsiveValue<CSS.OverflowYProperty>;
padding?ResponsiveValue<keyof ThemeShape['space']>One of our spacing tokens
paddingBottom?ResponsiveValue<keyof ThemeShape['space']>One of our spacing tokens
paddingLeft?ResponsiveValue<keyof ThemeShape['space']>One of our spacing tokens
paddingRight?ResponsiveValue<keyof ThemeShape['space']>One of our spacing tokens
paddingTop?ResponsiveValue<keyof ThemeShape['space']>One of our spacing tokens
textAlign?ResponsiveValue<CSS.textAlignProperty>
color?ResponsiveValue<keyof ThemeShape['textColors']>
textDecoration?ResponsiveValue<CSS.TextDecorationProperty<CSS.TextDecorationLineProperty>>
textOverflow?ResponsiveValue<CSS.TextOverflowProperty>
whiteSpace?ResponsiveValue<CSS.WhiteSpaceProperty>
fontVariantNumeric?FontVariantNumericProperty
_after?TextProps
_before?TextProps
_focus?TextProps
_hover?TextProps
_active?TextProps
_pressed?TextProps
_selected?TextProps
_focusWithin?TextProps
_invalid?TextProps
_disabled?TextProps
_grabbed?TextProps
_expanded?TextProps
_checked?TextProps
_mixed?TextProps
_odd?TextProps
_even?TextProps
_visited?TextProps
_readOnly?TextProps
_first?TextProps
_last?TextProps
_notFirst?TextProps
_notLast?TextProps

Black lives matter.