# Text (/docs/native/components/text)

<Preview id="text/type-scale" title={null} />

## Installation [#installation]

<ComponentInstall name="text" />

## Usage [#usage]

```tsx title="app/index.tsx"
import { Text } from "@/components/ui/text";
import { View } from "react-native";

export default function Example() {
  return (
    <View className="flex-1 justify-center gap-2 p-4">
      <Text.Title>Settings</Text.Title>
      <Text.Paragraph>Manage how the app behaves on this device.</Text.Paragraph>
    </View>
  );
}
```

## Presets [#presets]

Eight block presets, largest first, and four inline ones that emit only a delta.

<Preview id="text/type-scale" />

<Preview id="text/inline-presets" />

```tsx
<Text.Display>Display</Text.Display>
<Text.Title>Title</Text.Title>
<Text.Header>Header</Text.Header>
<Text.Subheader>Subheader</Text.Subheader>
<Text.Paragraph>Paragraph</Text.Paragraph>
<Text.Label>Label</Text.Label>
<Text.Caption>Caption</Text.Caption>
<Text.Overline>Overline</Text.Overline>

<Text.Paragraph>
  Inline: <Text.Strong>strong</Text.Strong>, <Text.Emphasis>emphasis</Text.Emphasis>,{" "}
  <Text.Link>link</Text.Link>, <Text.Code>code</Text.Code>.
</Text.Paragraph>
```

<Callout type="warn" title="A nested Text.Code cannot be padded">
A nested `<Text>` is laid out by the platform's text engine — an `NSAttributedString` run on iOS, a
`Span` on Android — and both ignore padding, margin and border radius on an inner `<Text>`. Only the
background survives. The pill treatment applies to the standalone case only; a code *block* is a
`View` you wrap around it.
</Callout>

## Inheritance [#inheritance]

Every `Text` publishes its resolved class to its subtree, and merges the one it inherited.

```tsx
<Text.Paragraph>
  Sign in with <Text.Strong>your work account</Text.Strong> to continue.
</Text.Paragraph>
```

`Text.Strong` comes out at the paragraph's size and colour with only the weight changed. A `Button`
publishes its label's treatment the same way, so a bare `<Text>` composed into one needs nothing at
the call site.

## Axes [#axes]

```tsx
<Text size="lg" weight="semibold" color="muted" align="center" transform="uppercase">
  Heads up
</Text>
```

Each axis beats the variant's own value and anything inherited; omit an axis and it falls through to
the enclosing text.

<Callout type="warn" title="An arbitrary font size must be a length">
Write `text-[17px]` or `text-(length:--x)`. A bare `text-[var(--x)]` is ambiguous to tailwind-merge,
which files it under colour — so it will not override the inherited size.
</Callout>

## Colour [#colour]

`color` is page-level only. Text on a coloured surface writes the utility in a `className`, because
that mapping belongs to the surface.

<Preview id="text/colour" />

```tsx
<Text color="destructive">Could not save</Text>
```

## Truncation [#truncation]

```tsx
<Text.Paragraph numberOfLines={2}>{body}</Text.Paragraph>
```

## Font scaling [#font-scaling]

`allowFontScaling` is left at React Native's default, and `maxFontSizeMultiplier` defaults to
`TEXT_MAX_FONT_SIZE_MULTIPLIER` so a label cannot outgrow the fixed-height chrome around it.

```tsx
<Text allowFontScaling={false}>Fixed</Text>
<Text maxFontSizeMultiplier={2}>Room to grow</Text>
```

## API Reference [#api-reference]

### Presets [#presets-1]

<TypeTable
  type={{
    "Text.Display": { type: "TextPresetProps", description: "30pt bold, announced as a heading. A screen's one hero line." },
    "Text.Title": { type: "TextPresetProps", description: "24pt bold, announced as a heading. A screen or card title." },
    "Text.Header": { type: "TextPresetProps", description: "20pt semibold, announced as a heading. A section heading." },
    "Text.Subheader": {
      type: "TextPresetProps",
      description: "18pt muted. The secondary line under a title — not a fourth heading level.",
    },
    "Text.Paragraph": { type: "TextPresetProps", description: "16pt. The same treatment a bare `<Text>` renders." },
    "Text.Label": { type: "TextPresetProps", description: "14pt medium. A control label or compact UI string." },
    "Text.Caption": { type: "TextPresetProps", description: "14pt on the muted token. Supporting copy." },
    "Text.Overline": { type: "TextPresetProps", description: "12pt semibold, uppercase, muted. An eyebrow above a section." },
    "Text.Strong": { type: "TextPresetProps", description: "Inline. Emphasis by weight." },
    "Text.Emphasis": { type: "TextPresetProps", description: "Inline. Emphasis by slant." },
    "Text.Link": { type: "TextPresetProps", description: "Inline. A tappable run on the `info` token. Takes `onPress`." },
    "Text.Code": { type: "TextPresetProps", description: "Inline. Monospaced, padded only when it stands alone." },
  }}
/>

### TextProps [#textprops]

`Animated.Text`'s props, minus `className`, plus:

<TypeTable
  type={{
    variant: {
      type: '"display" | "title" | "header" | "subheader" | "paragraph" | "label" | "caption" | "overline" | "strong" | "emphasis" | "link" | "code"',
      description: "The named role. Omit it and the text inherits, falling back to the base treatment.",
    },
    size: {
      type: '"xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl"',
      description: "A step on the type scale. Beats the variant's own size.",
    },
    weight: {
      type: '"normal" | "medium" | "semibold" | "bold"',
    },
    color: {
      type: '"default" | "muted" | "destructive" | "success" | "warning" | "info"',
      description: "A page-level text colour. For text on a coloured surface, use a className — that mapping belongs to the surface.",
    },
    align: {
      type: '"left" | "center" | "right"',
      description: "Never start / end: React Native's textAlign rejects logical values.",
    },
    transform: {
      type: '"none" | "uppercase" | "lowercase" | "capitalize"',
      description: '"none" emits normal-case rather than an empty string, so it can clear an Overline\'s uppercase.',
    },
    className: {
      type: "string",
      description: "Merged last, so it beats every named axis and anything inherited.",
    },
  }}
/>

### useTextClass() [#usetextclass]

Returns the resolved class of the nearest enclosing `Text` or `TextClassProvider`.

<TypeTable
  type={{
    "(returns)": { type: "string | undefined", required: true },
  }}
/>

### Exports [#exports]

```tsx
import {
  TEXT_VARIANTS,
  TEXT_INLINE_VARIANTS,
  TEXT_SIZES,
  TEXT_WEIGHTS,
  TEXT_COLORS,
  TEXT_ALIGNS,
  TEXT_TRANSFORMS,
  TEXT_BASE_CLASS,
  TEXT_MAX_FONT_SIZE_MULTIPLIER,
  TextClassProvider,
  useTextClass,
  textVariants,
  resolveTextClass,
  canNestText,
  isInlineTextVariant,
} from "@delacour/react-native-ui/text";
```
