Text

The Text component displays textual information in a number of optional styles and variants.

You can learn more about this component in the Working with Text article.

Also note that variants of the Text component are also mapped to HtmlTag components. See the variant section to check which variant maps to which HtmlTag.

Properties

ellipses (default: false)

This property indicates whether ellipses should be displayed when the text is cropped (true) or not (false).

<App>
  <VStack width="120px">
    <Text
      backgroundColor="cyan"
      color="black"
      maxLines="1"
      ellipses="false">
      Though this long text does is about to crop!
    </Text>
    <Text
      backgroundColor="cyan"
      color="black"
      maxLines="1">
      Though this long text does is about to crop!
    </Text>
  </VStack>
</App>

maxLines

This property determines the maximum number of lines the component can wrap to. If there is no space to display all the contents, the component displays up to as many lines as specified in this property. When the value is not defined, there is no limit on the displayed lines.

<App>
  <Text
    maxWidth="120px"
    backgroundColor="cyan"
    color="black"
    value="A long text that will likely overflow"
    maxLines="2" />
</App>

preserveLinebreaks (default: "false")

This property indicates if linebreaks should be preserved when displaying text.

<App>
  <HStack>
    <Text
      width="250px"
      backgroundColor="cyan"
      color="black"
      preserveLinebreaks="true"
      value="(preserve) This long text
      with several line breaks
              does not fit into a viewport with a 200-pixel width." />
    <Text
      width="250px"
      backgroundColor="cyan"
      color="black"
      value="(don't preserve) This long text
      with several line breaks
              does not fit into a viewport with a 200-pixel width." />
  </HStack>
</App>

Note: Remember to use the value property of the Text. Linebreaks are converted to spaces when nesting the text inside the Text component.

value

The text to be displayed. This value can also be set via nesting the text into the Text component.

<App>
  <Text value="An example text" />
  <Text>An example text</Text>
</App>

variant

An optional string value that provides named presets for text variants with a unique combination of font style, weight, size, color, and other parameters. If not defined, the text uses the current style of its context.

Available values:

ValueDescription
abbrRepresents an abbreviation or acronym
captionRepresents the caption (or title) of a table
citeIs used to mark up the title of a cited work
codeRepresents a line of code
codefenceHandles the display of code blocks if combined with a code variant
deletedRepresents text that has been deleted
emMarks text to stress emphasis
insertedRepresents a range of text that has been added to a document
keyboardRepresents a span of text denoting textual user input from a keyboard or voice input
markedRepresents text which is marked or highlighted for reference or notation
monoText using a mono style font family
paragraphRepresents a paragraph
placeholderText that is mostly used as the placeholder style in input controls
sampleRepresents sample (or quoted) output from a computer program
secondaryRepresents a bit dimmed secondary text
smallRepresents side-comments and small print
subSpecifies inline text as subscript
strongContents have strong importance
subheadingIndicates that the text is the subtitle in a heading
subtitleIndicates that the text is the subtitle of some other content
supSpecifies inline text as superscript
tableheadingIndicates that the text is a table heading
titleIndicates that the text is the title of some other content
varRepresents the name of a variable in a mathematical expression

HtmlTag Mappings

The table below indicates which Text variant maps to which HtmlTag component.

VariantComponent
abbrabbr
citecite
codecode
codefencepre
deleteddel
insertedins
keyboardkbd
markedmark
samplesamp
subsub
supsup
varvar
strongstrong
emem
paragraphp

Events

This component does not have any events.

Exposed Methods

This component does not expose any methods.

Styling

The Text component uses these theme variables:

  • verticalAlign
  • borderRadius
  • color
  • backgroundColor
  • borderColor
  • textDecorationColor
  • fontFamily
  • fontSize
  • fontWeight
  • fontStyle
  • fontStretch
  • letterSpacing
  • textDecorationLine
  • lineHeight
  • textUnderlineOffset
  • paddingHorizontal
  • paddingVertical
  • borderStyle
  • textDecorationStyle
  • borderWidth
  • textDecorationThickness
  • transform

You must combine these property names with Text and the variant's name. For example, you can set a light green background for the abbr variant and add some horizontal padding with the following theme variables:

"backgroundColor-Text-abbr": "lightgreen",
"paddingHorizontal-Text-abbr": "8px"

Theme Variables

VariableDefault Value (Light)Default Value (Dark)
backgroundColor-Text-code$color-surface-100$color-surface-100
backgroundColor-Text-codefence$color-primary-100$color-primary-100
backgroundColor-Text-keyboard$color-surface-200$color-surface-200
backgroundColor-Text-markedyellowyellow
borderColor-Text-code$color-surface-200$color-surface-200
borderColor-Text-keyboard$color-surface-300$color-surface-300
borderRadius-Text$borderRadius$borderRadius
borderStyle-Textsolidsolid
borderWidth-Text$space-0$space-0
borderWidth-Text-code1px1px
borderWidth-Text-keyboard1px1px
color-Text-codefence$color-surface-900$color-surface-900
color-Text-placeholder$color-surface-500$color-surface-500
color-Text-secondary$textColor-secondary$textColor-secondary
color-Text-subheading$textColor-secondary$textColor-secondary
fontFamily-Text$fontFamily$fontFamily
fontFamily-Text-code$fontFamily-monospace$fontFamily-monospace
fontFamily-Text-codefence$fontFamily-monospace$fontFamily-monospace
fontFamily-Text-keyboard$fontFamily-monospace$fontFamily-monospace
fontFamily-Text-mono$fontFamily-monospace$fontFamily-monospace
fontFamily-Text-sample$fontFamily-monospace$fontFamily-monospace
fontSize-Text$fontSize-small$fontSize-small
fontSize-Text-code$fontSize-small$fontSize-small
fontSize-Text-keyboard$fontSize-small$fontSize-small
fontSize-Text-markdown$fontSize-normal$fontSize-normal
fontSize-Text-placeholder$fontSize-small$fontSize-small
fontSize-Text-sample$fontSize-small$fontSize-small
fontSize-Text-secondary$fontSize-small$fontSize-small
fontSize-Text-small$fontSize-small$fontSize-small
fontSize-Text-sub$fontSize-smaller$fontSize-smaller
fontSize-Text-subheading$fontSize-H6$fontSize-H6
fontSize-Text-subtitle$fontSize-medium$fontSize-medium
fontSize-Text-sup$fontSize-smaller$fontSize-smaller
fontSize-Text-title$fontSize-large$fontSize-large
fontStyle-Text-citeitalicitalic
fontStyle-Text-varitalicitalic
fontWeight-Text$fontWeight-normal$fontWeight-normal
fontWeight-Text-abbr$fontWeight-bold$fontWeight-bold
fontWeight-Text-keyboard$fontWeight-bold$fontWeight-bold
fontWeight-Text-subheading$fontWeight-bold$fontWeight-bold
fontWeight-Text-tableheading$fontWeight-bold$fontWeight-bold
letterSpacing-Text-caption0.05rem0.05rem
letterSpacing-Text-subheading0.04em0.04em
lineHeight-Text-small$lineHeight-tight$lineHeight-tight
marginBottom-Text-abbr

none

none

marginBottom-Text-caption

none

none

marginBottom-Text-cite

none

none

marginBottom-Text-code

none

none

marginBottom-Text-codefence$space-4$space-4
marginBottom-Text-default

none

none

marginBottom-Text-deleted

none

none

marginBottom-Text-inserted

none

none

marginBottom-Text-keyboard

none

none

marginBottom-Text-markdown$space-3$space-3
marginBottom-Text-marked

none

none

marginBottom-Text-mono

none

none

marginBottom-Text-paragraph

none

none

marginBottom-Text-placeholder

none

none

marginBottom-Text-sample

none

none

marginBottom-Text-secondary

none

none

marginBottom-Text-small

none

none

marginBottom-Text-sub

none

none

marginBottom-Text-subheading

none

none

marginBottom-Text-subtitle

none

none

marginBottom-Text-sup

none

none

marginBottom-Text-tableheading$space-4$space-4
marginBottom-Text-title

none

none

marginBottom-Text-var

none

none

marginTop-Text-abbr

none

none

marginTop-Text-caption

none

none

marginTop-Text-cite

none

none

marginTop-Text-code

none

none

marginTop-Text-codefence$space-4$space-4
marginTop-Text-default

none

none

marginTop-Text-deleted

none

none

marginTop-Text-inserted

none

none

marginTop-Text-keyboard

none

none

marginTop-Text-markdown$space-3$space-3
marginTop-Text-marked

none

none

marginTop-Text-mono

none

none

marginTop-Text-paragraph

none

none

marginTop-Text-placeholder

none

none

marginTop-Text-sample

none

none

marginTop-Text-secondary

none

none

marginTop-Text-small

none

none

marginTop-Text-sub

none

none

marginTop-Text-subheading

none

none

marginTop-Text-subtitle

none

none

marginTop-Text-sup

none

none

marginTop-Text-tableheading$space-1$space-1
marginTop-Text-title

none

none

marginTop-Text-var

none

none

paddingHorizontal-Text-code$space-1$space-1
paddingHorizontal-Text-codefence$space-3$space-3
paddingHorizontal-Text-keyboard$space-1$space-1
paddingHorizontal-Text-tableheading$space-1$space-1
paddingVertical-Text-codefence$space-2$space-2
paddingVertical-Text-paragraph$space-1$space-1
textColor-Text$textColor-primary$textColor-primary
textDecorationLine-Text-deletedline-throughline-through
textDecorationLine-Text-insertedunderlineunderline
textTransform-Text-abbruppercaseuppercase
textTransform-Text-subheadinguppercaseuppercase
verticalAlign-Text-abbr

none

none

verticalAlign-Text-caption

none

none

verticalAlign-Text-cite

none

none

verticalAlign-Text-code

none

none

verticalAlign-Text-codefence

none

none

verticalAlign-Text-default

none

none

verticalAlign-Text-deleted

none

none

verticalAlign-Text-inserted

none

none

verticalAlign-Text-keyboard

none

none

verticalAlign-Text-markdown

none

none

verticalAlign-Text-marked

none

none

verticalAlign-Text-mono

none

none

verticalAlign-Text-paragraph

none

none

verticalAlign-Text-placeholder

none

none

verticalAlign-Text-sample

none

none

verticalAlign-Text-secondary

none

none

verticalAlign-Text-small

none

none

verticalAlign-Text-subsubsub
verticalAlign-Text-subheading

none

none

verticalAlign-Text-subtitle

none

none

verticalAlign-Text-supsupersuper
verticalAlign-Text-tableheading

none

none

verticalAlign-Text-title

none

none

verticalAlign-Text-var

none

none