---
title: "Text · Base UI — StyleX Blocks"
description: "Typographic primitive for body copy, muted descriptions, labels, captions, overlines, tabular numerals, and truncated text."
url: "https://stylexblocks.com/components/base-ui/text/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Text

Typographic primitive for body copy, muted descriptions, labels, captions, overlines, tabular numerals, and truncated text.

- Behavior engine: Base UI
- Also available for: [Ark UI](https://stylexblocks.com/components/ark-ui/text.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/text.md)
- Category: Typography
- Variants: body, muted, subtle, caption, label, overline, mono
- Sizes: xs, sm, md, lg, xl, 2xl
- HTML page: https://stylexblocks.com/components/base-ui/text/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style base-ui
```

Then add the item as source you own:

```sh
npx stylexblocks add text
```

Equivalent: `npx shadcn add @stylexblocks/text`. Registry item JSON: https://stylexblocks.com/r/base-ui/text.json

## Usage

```tsx
import { Text } from "#components/ui/base-ui/text.tsx";

export function Example() {
  return (
    <>
      <Text variant="overline">Release notes</Text>
      <Text size="md">Atomic CSS compiled to zero-runtime classes.</Text>
      <Text variant="muted" size="sm">Updated 4 minutes ago</Text>
      <Text variant="mono" tabular="true">$14,280.00</Text>

      {/* polymorphic composition via render */}
      <Text variant="label" render={<span />}>Inline span</Text>
    </>
  );
}
```

## Source

`components/ui/base-ui/text.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { createComponent } from "#lib/base-ui/create-component.tsx";
import { defineRecipe } from "#lib/recipe-props.ts";
import { colorPalette } from "@stylexblocks/ui/color-palette.stylex.ts";
import { semanticColors } from "@stylexblocks/ui/semantic-tokens/colors.stylex.ts";
import { fontSizes } from "@stylexblocks/ui/tokens/font-sizes.stylex.ts";
import { fontWeights } from "@stylexblocks/ui/tokens/font-weights.stylex.ts";
import { fonts } from "@stylexblocks/ui/tokens/fonts.stylex.ts";
import { letterSpacings } from "@stylexblocks/ui/tokens/letter-spacings.stylex.ts";
import { lineHeights } from "@stylexblocks/ui/tokens/line-heights.stylex.ts";

const textStyles = stylex.create({
  base: {
    fontFamily: fonts.body,
    marginTop: 0,
    marginBottom: 0,
  },
});

const textVariants = stylex.create({
  body: {
    color: semanticColors.fg,
  },
  muted: {
    color: semanticColors.fgMuted,
  },
  subtle: {
    color: semanticColors.fgSubtle,
  },
  caption: {
    color: semanticColors.fgMuted,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
  },
  label: {
    color: semanticColors.fg,
    fontWeight: fontWeights.medium,
  },
  overline: {
    color: semanticColors.fgMuted,
    fontSize: fontSizes.xs,
    lineHeight: lineHeights.xs,
    fontWeight: fontWeights.semibold,
    letterSpacing: letterSpacings.wider,
    textTransform: "uppercase",
  },
  mono: {
    fontFamily: fonts.mono,
    color: semanticColors.fg,
  },
});

const textSizes = stylex.create({
  "2xs": { fontSize: fontSizes._2xs, lineHeight: lineHeights._2xs },
  xs: { fontSize: fontSizes.xs, lineHeight: lineHeights.xs },
  sm: { fontSize: fontSizes.sm, lineHeight: lineHeights.sm },
  md: { fontSize: fontSizes.md, lineHeight: lineHeights.md },
  lg: { fontSize: fontSizes.lg, lineHeight: lineHeights.lg },
  xl: { fontSize: fontSizes.xl, lineHeight: lineHeights.xl },
  "2xl": { fontSize: fontSizes._2xl, lineHeight: lineHeights._2xl },
});

const textTones = stylex.create({
  inherit: {},
  default: { color: semanticColors.fg },
  muted: { color: semanticColors.fgMuted },
  subtle: { color: semanticColors.fgSubtle },
  accent: { color: colorPalette.fg },
  success: { color: semanticColors.fgSuccess },
  warning: { color: semanticColors.fgWarning },
  error: { color: semanticColors.fgError },
  info: { color: semanticColors.fgInfo },
});

const textWeights = stylex.create({
  inherit: {},
  normal: { fontWeight: fontWeights.normal },
  medium: { fontWeight: fontWeights.medium },
  semibold: { fontWeight: fontWeights.semibold },
  bold: { fontWeight: fontWeights.bold },
});

const textAligns = stylex.create({
  start: { textAlign: "start" },
  center: { textAlign: "center" },
  end: { textAlign: "end" },
});

const textTruncate = stylex.create({
  false: {},
  true: {
    overflow: "hidden",
    textOverflow: "ellipsis",
    whiteSpace: "nowrap",
  },
});

const textTabular = stylex.create({
  false: {},
  true: {
    fontVariantNumeric: "tabular-nums",
  },
});

const textRecipe = defineRecipe({
  styles: textStyles,
  axes: {
    size: textSizes,
    variant: textVariants,
    tone: textTones,
    weight: textWeights,
    align: textAligns,
    truncate: textTruncate,
    tabular: textTabular,
  },
  defaultVariants: {
    size: "sm",
    variant: "body",
    tone: "inherit",
    weight: "inherit",
    align: "start",
    truncate: "false",
    tabular: "false",
  },
});

/**
 * Text — typographic primitive for body copy, muted descriptions, labels,
 * captions, overlines, tabular numbers, and truncated single-line text.
 * Composition via `render`.
 */
export const Text = createComponent("p", textRecipe, "Text");
export type TextProps = React.ComponentProps<typeof Text>;
```
