# Text

A polymorphic typography primitive using Zenos semantic type scales.

A polymorphic typography primitive using Zenos semantic type scales.

```tsx
import { Stack, Text } from "@zentara-co/zenos-ui";

function TextOverviewExample() {
  return (
    <Stack gap="3" align="center">
      <Text type="heading" size="h4">
        Security overview
      </Text>
      <Text size="m" color="subtle">
        Monitor assets, policies, and workspace activity.
      </Text>
      <Text type="code">pnpm add @zentara-co/zenos-ui</Text>
    </Stack>
  );
}
```

## Import

```tsx
import { Text } from "@zentara-co/zenos-ui";
```

## Heading scale

Heading sizes `h1` through `h6` choose matching HTML heading elements by default. `h7` is a visual heading style and renders a paragraph because HTML has no seventh heading level.

```tsx
import { Stack, Text } from "@zentara-co/zenos-ui";

function TextHeadingScaleExample() {
  return (
    <Stack gap="4" className="w-full">
      {(["h1", "h2", "h3", "h4", "h5", "h6", "h7"] as const).map((size) => (
        <Stack key={size} direction="row" gap="4" align="baseline">
          <Text type="code" color="subtlest" className="w-8 shrink-0">
            {size}
          </Text>
          <Text type="heading" size={size}>
            Zenos heading
          </Text>
        </Stack>
      ))}
    </Stack>
  );
}
```

## Body scale and weight

Body text uses large, medium, and small scales. Choose `weight="regular"` (400), `medium` (500), `semibold` (600), or `bold` (700). Weight only affects `body`; heading, emphasis, and code roles own their weight through their type tokens.

In 0.2.2, body `bold` changes from 600 to 700. Use `semibold` to retain the previous 600 weight. Theme overrides can customize the corresponding `--font-weight-body-*` tokens.

```tsx
import { Stack, Text } from "@zentara-co/zenos-ui";

function TextBodyScaleExample() {
  return (
    <Stack gap="5" className="w-full max-w-2xl">
      {(["l", "m", "s"] as const).map((size) => (
        <Stack key={size} gap="2">
          <Text type="code" color="subtlest">
            Body {size}
          </Text>
          <Text size={size}>Regular text supports the primary reading flow.</Text>
          <Text size={size} weight="medium">
            Medium text adds measured emphasis.
          </Text>
          <Text size={size} weight="semibold">
            Semibold text distinguishes labels from surrounding copy.
          </Text>
          <Text size={size} weight="bold">
            Bold text marks the strongest body emphasis.
          </Text>
        </Stack>
      ))}
    </Stack>
  );
}
```

## Body, emphasis, code, and italic

Use `type` for the typography role rather than approximating it with arbitrary font classes. `italic` can be combined with any role when the content convention calls for it.

```tsx
import { Stack, Text } from "@zentara-co/zenos-ui";

function TextTypesExample() {
  return (
    <Stack gap="4" className="w-full max-w-xl">
      <Text type="body">Body text is the default for paragraphs and descriptions.</Text>
      <Text type="emphasis">Emphasis uses the dedicated emphasis type treatment.</Text>
      <Text type="code">const status = "healthy";</Text>
      <Text italic>Italic text can mark titles, terms, or a change in voice.</Text>
    </Stack>
  );
}
```

## Semantic colors

Colors describe text meaning and hierarchy. Use default, subtle, and subtlest for hierarchy; status colors for actual state; and contextual colors only on surfaces where their contrast role applies.

```tsx
import { Stack, Text } from "@zentara-co/zenos-ui";

function TextColorsExample() {
  const groups = [
    ["Hierarchy", ["default", "subtle", "subtlest"]],
    ["Meaning", ["brand", "danger", "warning", "success", "information"]],
    ["Context", ["contrary", "selected", "visited"]],
  ] as const;

  return (
    <Stack gap="5" className="w-full">
      {groups.map(([label, colors]) => (
        <Stack key={label} gap="2">
          <Text size="s" weight="bold">
            {label}
          </Text>
          <Stack direction="row" gap="4" wrap="wrap">
            {colors.map((color) => (
              <Text key={color} color={color} weight="medium">
                {color}
              </Text>
            ))}
          </Stack>
        </Stack>
      ))}
    </Stack>
  );
}
```

## Styling and semantics

`type` and `size` control visual typography; `as` controls the rendered element. Preserve a logical heading hierarchy even when design calls for a smaller visual size. Polymorphic props and refs follow the selected element.

```tsx
import { Input, Stack, Text } from "@zentara-co/zenos-ui";

function TextSemanticsExample() {
  return (
    <Stack gap="4" className="w-full max-w-xl">
      <Text as="h2" type="heading" size="h4">
        Semantic h2 with h4 styling
      </Text>
      <Text as="span" size="s" color="subtle">
        Inline metadata rendered as a span
      </Text>
      <Text as="label" htmlFor="text-semantics-input" weight="medium">
        Native label rendered through Text
      </Text>
      <Input id="text-semantics-input" placeholder="Example control" />
    </Stack>
  );
}
```

## Overflow and alignment

`truncate` applies a single-line ellipsis. `maxLines` clamps longer copy from two to six lines. Neither adds a tooltip; provide another way to access complete content when truncation hides information needed for a task.

```tsx
import { Stack, Text } from "@zentara-co/zenos-ui";

function TextOverflowExample() {
  return (
    <Stack gap="6" className="w-full max-w-md">
      <Stack gap="2" className="min-w-0">
        <Text size="s" weight="bold">
          Single line
        </Text>
        <Text truncate>
          audit-export-production-eu-central-1-with-an-intentionally-long-file-name.json
        </Text>
      </Stack>
      <Stack gap="2">
        <Text size="s" weight="bold">
          Three lines
        </Text>
        <Text maxLines={3} color="subtle">
          This workspace description contains more detail than the surrounding card can show at
          once. Line clamping keeps the layout stable, but the complete text should remain available
          from another view whenever users need to read or act on all of it.
        </Text>
      </Stack>
      <Stack direction="row" gap="4" justify="between">
        <Text align="start">Start</Text>
        <Text align="center">Center</Text>
        <Text align="end">End</Text>
      </Stack>
    </Stack>
  );
}
```

## Variants

type: heading, type: body, type: emphasis, type: code, weight: regular, weight: medium, weight: semibold, weight: bold, align: start, align: center, align: end, align: justify, color: default, color: subtle, color: subtlest, color: brand, color: danger, color: warning, color: success, color: information, color: contrary, color: selected, color: visited

## Sizes

h1, h2, h3, h4, h5, h6, h7, l, m, s

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| as | ElementType | p | Rendered semantic element. |
| type | heading \| body \| emphasis \| code | body | Typography family. |
| size | TextSize | m | Heading or body scale. |
| weight | regular \| medium \| semibold \| bold | regular | Body font weight; ignored by other typography roles. |
| align | start \| center \| end \| justify | — | Text alignment. |
| color | TextColor | default | Semantic foreground color. |
| italic | boolean | false | Applies italic styling. |
| truncate | boolean | false | Applies a single-line ellipsis and takes precedence over maxLines. |
| maxLines | number | — | Clamps content to two through six lines. |
| native props | React.HTMLAttributes for the selected element | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Choose semantic elements from document structure, then apply the required visual style. Do not skip heading levels to obtain a smaller font. Color does not communicate meaning by itself, and justified text can reduce readability in narrow columns. Truncated text remains present in the accessibility tree, but sighted users still need a discoverable route to the full value when it affects a decision.

Source: https://zenos-ui.pages.dev/components/text/