# Text

> The primary component for rendering all text content. It provides props to control typographic properties like size, weight, color, and alignment.

Source: https://vaneui.com/docs/typography-components/text

Import: `import { Text, Button, Card, Col, Row } from "@vaneui/ui"`

Use Text for paragraphs, captions and helper copy. It renders a `<p>` element, or an `<a>` when `href` is set. Headings belong in [Title](/docs/typography-components/title) and its siblings, which render `<h1>` to `<h3>` elements. For a link inside a sentence, nest a [Link](/docs/typography-components/link) in the Text: it keeps the link color and matches the size of the text around it.

## Basic usage

Text renders paragraph text with default styling.

```tsx demo
<Text>Compose interfaces with VaneUI components. Text provides consistent typography across your application.</Text>
```

## Sizes

Text comes in different sizes: `xs`, `sm`, `md` (default), `lg`, `xl`: 12, 14, 16, 18 and 20px. Inside a Card or a Modal an unsized Text is 14px (see [type sizes inside a Card](/docs/layout-components/card#type-sizes-inside-a-card)).

```tsx demo
<Col>
  <Text xs>Extra small text</Text>
  <Text sm>Small text for captions</Text>
  <Text>Medium text (default)</Text>
  <Text lg>Large text for emphasis</Text>
  <Text xl>Extra large text</Text>
</Col>
```

## Appearances

Text supports explicit color appearances: `primary`, `accent`, `secondary`, `tertiary`, `success`, `danger`, `warning`, `info`. Use these to override the default `inheritAppearance` behavior.

```tsx demo
<Col>
  <Text primary>Primary text for important content</Text>
  <Text accent>Accent text for highlights</Text>
  <Text secondary>Secondary text for supporting content</Text>
  <Text tertiary>Tertiary text for muted content</Text>
  <Text success>Success text for positive feedback</Text>
  <Text danger>Danger text for errors or warnings</Text>
  <Text warning>Warning text for cautionary messages</Text>
  <Text info>Info text for informational content</Text>
</Col>
```

## Variants

Text never paints a background, so the variant does one thing here: it picks which colour of the appearance the text is painted in. `outline`, the default, uses the appearance's own colour, for text on a plain surface. `filled` uses the "on this fill" colour, for text sitting on a filled surface of the same appearance.

```tsx demo
<Col>
  <Text info>outline info, on the page surface</Text>
  <Text danger>outline danger, on the page surface</Text>
  <Card info filled>
    <Text info filled>filled info, on a matching filled Card</Text>
  </Card>
  <Card danger filled>
    <Text danger filled>filled danger, on a matching filled Card</Text>
  </Card>
</Col>
```

Use `filled` on a plain page and the text takes the colour meant to sit on the fill, which is close to the page itself. Wrap it in a matching surface, or leave the default `inheritAppearance` on and let it take the colour from whatever it sits in.

## Inherit appearance (default)

Text defaults to the `inheritAppearance` appearance: it picks up its color from the parent via CSS cascade instead of applying its own. Set an explicit appearance to override.

```tsx demo
<Row flexWrap itemsStretch>
  <Card primary filled>
    <Text fontBold>Inherited Primary</Text>
    <Text>This text inherits primary from the Card.</Text>
  </Card>
  <Card success filled>
    <Text fontBold>Inherited Success</Text>
    <Text>Inherits success color automatically.</Text>
  </Card>
  <Card border secondary>
    <Text fontBold>On a plain surface</Text>
    <Text>Inherits the Card's own colour.</Text>
    <Text danger>Explicit danger overrides inherit.</Text>
  </Card>
</Row>
```

An explicit appearance stops inheriting, so it has to read on the surface it lands on. Inside a filled Card, `<Text danger>` resolves to the outline danger colour, which is close in weight to the filled surface behind it.

## Font weights

Control weight with `fontThin`, `fontExtralight`, `fontLight`, `fontNormal`, `fontMedium`, `fontSemibold`, `fontBold`, `fontExtrabold`, `fontBlack`.

```tsx demo
<Col>
  <Text fontThin>Thin weight</Text>
  <Text fontLight>Light weight</Text>
  <Text fontNormal>Normal weight</Text>
  <Text fontMedium>Medium weight</Text>
  <Text fontSemibold>Semibold weight</Text>
  <Text fontBold>Bold weight</Text>
  <Text fontExtrabold>Extra bold weight</Text>
  <Text fontBlack>Black weight</Text>
</Col>
```

## Font families

Switch font family with `fontSans` (default), `fontSerif`, `fontMono`.

```tsx demo
<Col>
  <Text fontSans>Sans-serif font (default)</Text>
  <Text fontSerif>Serif font for editorial content</Text>
  <Text fontMono>Monospace for code or technical content</Text>
</Col>
```

## Italic, underline, line-through

```tsx demo
<Col>
  <Text italic>Italic text for quotes or terms</Text>
  <Text underline>Underlined text for emphasis</Text>
  <Text lineThrough>Line-through for deleted content</Text>
</Col>
```

## Text transform

Use `uppercase`, `lowercase`, `capitalize`.

```tsx demo
<Col>
  <Text uppercase>Uppercase for labels</Text>
  <Text lowercase>LOWERCASE NORMALIZED</Text>
  <Text capitalize>capitalized words example</Text>
</Col>
```

## Text alignment

Align text with `textLeft` (default), `textCenter`, `textRight`, `textJustify`. Text defaults to `wFit`, so set `wFull` to see alignment effects across the container.

```tsx demo
<Col>
  <Text wFull>Left aligned (default)</Text>
  <Text wFull textCenter>Center aligned</Text>
  <Text wFull textRight>Right aligned</Text>
  <Text wFull textJustify>Justified text spreads to fill the line, distributing extra space between words across the full container width.</Text>
</Col>
```

## Truncate and line clamp

Use `truncate` for single-line ellipsis, or `lineClamp2`/`lineClamp3`/`lineClamp4`/`lineClamp5` for multi-line clamping.

```tsx demo
<Col>
  <Text wFull truncate>Truncated single line of text that will be cut off with an ellipsis when it exceeds the container width.</Text>
  <Text wFull lineClamp2>Clamped to two lines. This release note covers the new size props, the revised default appearances, and the spacing changes that now scale with the size prop across every typography component in the library.</Text>
  <Text wFull lineClamp3>Clamped to three lines. The migration guide walks through each change in detail, from the renamed appearance props to the updated default margins, and explains how to update your existing components step by step so nothing renders differently after you upgrade to the latest version.</Text>
</Col>
```

## Word break

Control how long unbreakable strings behave when they would overflow the container. `breakWords` wraps a long word onto the next line (`overflow-wrap: break-word`), `breakAll` breaks between any two characters, `breakKeep` prevents breaks in CJK text, and `breakNormal` sets `overflow-wrap: normal` so the string overflows. By default Text already wraps long strings (`overflow-wrap: anywhere`). This is the opposite of `truncate`: instead of hiding the overflow, the text wraps to fit.

```tsx demo
<Col>
  <Text breakNormal className="w-48 border border-gray-300 p-2">
    breakNormal: https://vaneui.com/docs/typography-components/text overflows.
  </Text>
  <Text breakWords className="w-48 border border-gray-300 p-2">
    breakWords: https://vaneui.com/docs/typography-components/text wraps.
  </Text>
  <Text breakAll className="w-48 border border-gray-300 p-2">
    breakAll: https://vaneui.com/docs/typography-components/text wraps.
  </Text>
</Col>
```

## Letter spacing

Control letter spacing with `trackingTighter`, `trackingTight`, `trackingNormal`, `trackingWide`, `trackingWider`, `trackingWidest`. Text defaults to a compact `-0.011em` tracking; `trackingNormal` resets it to `0`.

```tsx demo
<Col>
  <Text trackingTighter>Tighter letter spacing</Text>
  <Text trackingTight>Tight letter spacing</Text>
  <Text trackingNormal>Normal letter spacing</Text>
  <Text trackingWide>Wide letter spacing</Text>
  <Text trackingWider>Wider letter spacing</Text>
  <Text trackingWidest>Widest letter spacing</Text>
</Col>
```

## Hidden text for screen readers

`srOnly` hides the text from view and keeps it for screen readers, for a label that the layout already shows with an icon or a position, such as the name of an icon-only control or the "(opens in a new tab)" note after a link. It needs `@vaneui/ui` 1.8.0 or later, and the other typography components and [Label](/docs/form-components/label) take it too.

```tsx demo
<Button secondary>
  <svg viewBox="0 0 24 24" width={16} height={16} fill="currentColor" aria-hidden="true">
    <path d="M12 2.5l2.95 5.98 6.6.96-4.78 4.66 1.13 6.58L12 17.6l-5.9 3.1 1.13-6.58-4.78-4.66 6.6-.96L12 2.5z"/>
  </svg>
  <Text tag="span" srOnly>Add to favorites</Text>
</Button>
```

## Margins

Block typography (`Text`, `Title`, `SectionTitle`, `PageTitle`, `Blockquote`) accepts size-driven margin props: `margin` (all sides), `marginX`, `marginY`, `marginT`, and `marginB`. `Text` defaults to `noMargin`, so opt in where you need vertical rhythm outside a gap-based layout. The margin scales with the size prop. Side props compose: `marginT marginB` applies both. `noMargin` resets and wins.

```tsx demo
<Col noGap>
  <Text>No margin (default), sits flush.</Text>
  <Text marginT marginB>Margin above and below, scales with size.</Text>
  <Text>Another flush line.</Text>
</Col>
```

## Text in context

Combining text properties for real-world use cases.

```tsx demo
<Col>
  <Card>
    <Text lg fontBold>Product Title</Text>
    <Text secondary>Category • 4.5 ★ (128 reviews)</Text>
    <Text>High-quality component library for building modern web applications with React and TypeScript.</Text>
    <Text sm primary fontSemibold>$99.00</Text>
  </Card>
</Col>
```

## Frequently asked questions

### Why does React warn about a `<p>` inside a `<p>`?

Text renders a `<p>`, and a paragraph cannot hold another paragraph or a block element such as a `<div>`, so a Text inside a Text, or a Col inside a Text, is invalid HTML. The browser closes the outer paragraph early, and React reports a hydration error on a server-rendered page. Give the inner Text `tag="span"`, as you would for a Text inside a Button or a Label.

### Why doesn't `truncate` cut off my text?

Text is `wFit` by default, so its box grows with the text and there is nothing to cut. Add `wFull`, as in [Truncate and line clamp](#truncate-and-line-clamp), so the box takes the width of its parent. Inside a Row, the flex item that holds the Text, such as a Col, also needs `className="min-w-0"`, because a flex item does not shrink below its content otherwise.

### Should I give Text an `href` or use Link?

Use [Link](/docs/typography-components/link). Text with `href` renders an `<a>` that keeps the look of body text, with no link color and no underline, so readers cannot tell that it is a link. Link adds both, a keyboard focus outline, the new-tab handling of `external` and the size of the text around it. For a whole clickable block, use a Card or a Col with `href`.

## Props

| Prop | Category | Default | Description |
| --- | --- | --- | --- |
| `primary` | Appearance |  | Primary color appearance (gray) |
| `accent` | Appearance |  | Accent color appearance (rose) |
| `secondary` | Appearance |  | Secondary color appearance (gray) |
| `tertiary` | Appearance |  | Tertiary color appearance |
| `success` | Appearance |  | Success color appearance (green) |
| `danger` | Appearance |  | Danger color appearance (red) |
| `warning` | Appearance |  | Warning color appearance (amber) |
| `info` | Appearance |  | Info color appearance (cyan) |
| `inheritAppearance` | Appearance | yes | Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables |
| `fontSans` | Font Family | yes | Sans-serif font family (default) — emits font-sans |
| `fontSerif` | Font Family |  | Serif font family — emits font-serif |
| `fontMono` | Font Family |  | Monospace font family — emits font-mono |
| `fontHeading` | Font Family |  | Heading font family (defaults to sans, customizable via --font-heading) — emits font-heading |
| `italic` | Font Style |  | Italic font style |
| `notItalic` | Font Style |  | Not italic (normal) font style |
| `fontThin` | Font Weight |  | Thin font weight (100) — emits font-thin |
| `fontExtralight` | Font Weight |  | Extra light font weight (200) — emits font-extralight |
| `fontLight` | Font Weight |  | Light font weight (300) — emits font-light |
| `fontNormal` | Font Weight |  | Normal font weight (400) — emits font-normal |
| `fontMedium` | Font Weight |  | Medium font weight (500) — emits font-medium |
| `fontSemibold` | Font Weight |  | Semibold font weight (600) — emits font-semibold |
| `fontBold` | Font Weight |  | Bold font weight (700) — emits font-bold |
| `fontExtrabold` | Font Weight |  | Extra bold font weight (800) — emits font-extrabold |
| `fontBlack` | Font Weight |  | Black font weight (900) — emits font-black |
| `inheritColor` | Inherit Color |  | Inherit text color from parent via CSS variable cascade (suppresses data-appearance emission) |
| `noInheritColor` | Inherit Color |  | Keep own text color; do not inherit from parent |
| `inheritSize` | Inherit Size |  | Inherit font-size and line-height from the nearest parent typography element |
| `noInheritSize` | Inherit Size |  | Keep own font-size; do not inherit from parent |
| `trackingTighter` | Letter Spacing |  | Tighter letter spacing (-0.05em) |
| `trackingTight` | Letter Spacing |  | Tight letter spacing (-0.025em) |
| `trackingNormal` | Letter Spacing |  | Normal letter spacing (0) |
| `trackingWide` | Letter Spacing |  | Wide letter spacing (0.025em) |
| `trackingWider` | Letter Spacing |  | Wider letter spacing (0.05em) |
| `trackingWidest` | Letter Spacing |  | Widest letter spacing (0.1em) |
| `margin` | Margin |  | Enable margin on all sides |
| `marginX` | Margin |  | Enable only horizontal (inline) margin |
| `marginY` | Margin |  | Enable only vertical (block) margin |
| `marginT` | Margin |  | Enable only top margin |
| `marginB` | Margin |  | Enable only bottom margin |
| `noMargin` | Margin | yes | Disable margin (reset to 0) |
| `xs` | Size |  | Extra small size |
| `sm` | Size |  | Small size |
| `md` | Size | yes | Medium size (default) |
| `lg` | Size |  | Large size |
| `xl` | Size |  | Extra large size |
| `skeleton` | Skeleton |  | Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too |
| `srOnly` | Sr Only |  | Hide visually and keep it for screen readers (sr-only) |
| `textLeft` | Text Align | yes | Align text to left (physical side, does not flip under RTL) |
| `textCenter` | Text Align |  | Align text to center |
| `textRight` | Text Align |  | Align text to right (physical side, does not flip under RTL) |
| `textJustify` | Text Align |  | Justify text |
| `textStart` | Text Align |  | Align text to the reading-direction start (left in LTR, right in RTL) |
| `textEnd` | Text Align |  | Align text to the reading-direction end (right in LTR, left in RTL) |
| `underline` | Text Decoration |  | Add underline decoration below text |
| `lineThrough` | Text Decoration |  | Add strikethrough/line-through decoration across text |
| `noUnderline` | Text Decoration |  | Remove ALL text-decoration — underline, line-through, and overline (text-decoration: none) |
| `overline` | Text Decoration |  | Add overline decoration above text |
| `uppercase` | Text Transform |  | Transform text to uppercase |
| `lowercase` | Text Transform |  | Transform text to lowercase |
| `capitalize` | Text Transform |  | Capitalize first letter of each word |
| `normalCase` | Text Transform |  | Normal text case (no transformation) |
| `truncate` | Truncate |  | Single line truncation with ellipsis |
| `lineClamp2` | Truncate |  | Truncate at 2 lines with ellipsis |
| `lineClamp3` | Truncate |  | Truncate at 3 lines with ellipsis |
| `lineClamp4` | Truncate |  | Truncate at 4 lines with ellipsis |
| `lineClamp5` | Truncate |  | Truncate at 5 lines with ellipsis |
| `noTruncate` | Truncate |  | Remove truncation |
| `filled` | Variant |  | Filled variant - solid background with contrasting text color |
| `outline` | Variant | yes | Outline variant - transparent background with border and colored text (default) |
| `ghost` | Variant |  | Ghost variant - transparent background, no border, appearance-colored text, tinted hover background |
| `breakNormal` | Word Break |  | Reset breaking - overflow-wrap and word-break normal |
| `breakWords` | Word Break |  | Break long words to prevent overflow - overflow-wrap: break-word |
| `breakAll` | Word Break |  | Break between any two characters - word-break: break-all |
| `breakKeep` | Word Break |  | Do not break CJK text - word-break: keep-all |

Layout and utility props (Cursor, Display, Height, Hide, Items, Justify, Overflow, Position, Responsive Sizing, Responsive Width, Show, Whitespace, Width) are listed on [Common Props](https://vaneui.com/docs/reference/common-props.md).
