Text

Typography helps establish hierarchy and communicate important content by creating clear visual patterns.

Text component examples

Use to create various levels of hierarchy on the page.

import {Text, LegacyStack} from '@shopify/polaris';
import React from 'react';

function TextExample() {
  return (
    <LegacyStack vertical>
      <Text variant="heading3xl" as="h2">
        Online store dashboard
      </Text>
      <Text variant="heading2xl" as="h3">
        Online store dashboard
      </Text>
      <Text variant="headingXl" as="h4">
        Online store dashboard
      </Text>
      <Text variant="headingLg" as="h5">
        Online store dashboard
      </Text>
      <Text variant="headingMd" as="h6">
        Online store dashboard
      </Text>
      <Text variant="headingSm" as="h6">
        Online store dashboard
      </Text>
      <Text variant="headingXs" as="h6">
        Online store dashboard
      </Text>
    </LegacyStack>
  );
}

Props

interface TextProps
alignment?'start' | 'center' | 'end' | 'justify'

Adjust horizontal alignment of text.

as'dt' | 'dd' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'span' | 'strong' | 'legend'

The element type.

breakWord?boolean

Prevent text from overflowing.

childrenReactNode

Text to display.

tone?'base' | 'disabled' | 'inherit' | 'success' | 'critical' | 'caution' | 'subdued' | 'text-inverse' | 'text-inverse-secondary' | 'magic' | 'magic-subdued'

Adjust tone of text.

fontWeight?'regular' | 'medium' | 'semibold' | 'bold'

Adjust weight of text.

id?string

HTML id attribute.

numeric?boolean

Use a numeric font variant with monospace appearance.

truncate?boolean

Truncate text overflow with ellipsis.

variant?'headingXs' | 'headingSm' | 'headingMd' | 'headingLg' | 'headingXl' | 'heading2xl' | 'heading3xl (deprecated)' | 'bodyXs' | 'bodySm' | 'bodyMd' | 'bodyLg'

Typographic style of text.

visuallyHidden?boolean

Visually hide the text.

textDecorationLine?"line-through"

Add a line-through to the text.

Variant tokens

Each variant uses a predetermined combination of the font tokens to set the font size and line height. Heading variants have a set font weight but can be overridden by using the fontWeight prop. Nested Text components will inherit properties from its parent Text container.

VariantFont size tokenpx valuerem valueFont line height tokenFont weight tokenResponsive
heading3xl--p-font-size-900362.25--p-line-height-1200--p-font-weight-boldYes
heading2xl--p-font-size-750301.875--p-line-height-1000--p-font-weight-boldYes
headingXl--p-font-size-600241.5--p-line-height-800--p-font-weight-boldYes
headingLg--p-font-size-500201.25--p-line-height-600--p-font-weight-semiboldYes
headingMd--p-font-size-350140.875--p-line-height-500--p-font-weight-semiboldNo
headingSm--p-font-size-325130.8125--p-line-height-500--p-font-weight-semiboldNo
headingXs--p-font-size-300120.75--p-line-height-400--p-font-weight-semiboldNo
bodyLg--p-font-size-350140.875--p-line-height-500--p-font-weight-regularNo
bodyMd--p-font-size-325130.8125--p-line-height-500--p-font-weight-regularNo
bodySm--p-font-size-300120.75--p-line-height-400--p-font-weight-regularNo
bodyXs--p-font-size-275110.6875--p-line-height-300--p-font-weight-regularNo

Mapping from previous type components

These are suggested replacements for existing text style components, but ultimately the best replacement should be evaluated based on the context of the usage. The Text component also requires setting the semantically appropriate html element through the as prop.

DisplayText

Small

Example
- <DisplayText size="small">Sales this year</DisplayText>
+ <Text variant="headingLg" as="p">Sales this year</Text>

Medium

Example
- <DisplayText size="medium">Sales this year</DisplayText>
+ <Text variant="headingXl" as="p">Sales this year</Text>

Large

Example
- <DisplayText size="large">Sales this year</DisplayText>
+ <Text variant="heading2xl" as="p">Sales this year</Text>

Extra large

Example
- <DisplayText size="extraLarge">Sales this year</DisplayText>
+ <Text variant="heading3xl" as="p">Sales this year</Text>

Heading

Example
- <Heading>Online store dashboard</Heading>
+ <Text variant="headingMd" as="h2">Online store dashboard</Text>

Subheading

Example
- <Subheading>Accounts</Subheading>
+ <Text variant="headingSm" as="h3">Accounts</Text>

Caption

Example
- <Caption>Received April 21, 2017</Caption>
+ <Text variant="bodySm" as="p">Received April 21, 2017</Text>

TextStyle

Subdued

Example
- <TextStyle variation="subdued">No supplier listed</TextStyle>
+ <Text as="span" tone="subdued">No supplier listed</Text>

Strong

Example
- <TextStyle variation="strong">No supplier listed</TextStyle>
+ <Text as="span" fontWeight="semibold" >No supplier listed</Text>

Positive

Example
- <TextStyle variation="positive">No supplier listed</TextStyle>
+ <Text as="span" tone="success">No supplier listed</Text>

Negative

Example
- <TextStyle variation="negative">No supplier listed</TextStyle>
+ <Text as="span" tone="critical">No supplier listed</Text>

Warning

Example
- <TextStyle variation="warning">No supplier listed</TextStyle>
+ <Text as="span" tone="warning">No supplier listed</Text>

Code

Example
- <TextStyle variation="code">No supplier listed</TextStyle>
+ <Text as="span"><InlineCode>No supplier listed</InlineCode></Text>

VisuallyHidden

Example
- <VisuallyHidden>
-   <Heading>Title and description</Heading>
- </VisuallyHidden>
+ <Text visuallyHidden as="h2">Title and description</Text>

Best practices

Headings

Headings use all the variants with heading in the name, such as headingMd. Headings should:

  • Clearly describe the section of interface they refer to
  • Highlight the most important concept or piece of information merchants need to know
  • Sit at the top of the section of interface they’re referring to

Captions

Captions use the bodySm Text variant.

  • Use for secondary labels in graphs and charts
  • May be used for timestamps in lists of content
  • Don’t use this variant for other cases
  • Don’t use this variant for text longer than a few words
  • Don’t use this variant for aesthetic effect or to break from the standard text size

Text styles

Text styles should be:

  • Used when enhancing the text to help merchants understand its meaning
  • Subdued if the text is less important than its surrounding text
  • Warning if the text denotes something that needs attention, or that merchants need to take action on.
  • Semibold for input fields, or for a row total in a price table
  • Paired with symbols, like an arrow or dollar sign, when using success or critical styles

Visually hidden

Visually hidden text should:

  • Not be used if semantic markup can make content understandable to people using assistive technology
  • Be used to provide extra context when semantic markup isn’t enough
  • Be used on any content that is normally present but is being omitted
  • Make sense in context when used with a screen reader

    On this page