Skip to Content
Neshel-UI
Typography

Caption

Small, muted supporting text for figures, metadata and hints.

Purpose

Caption renders small supporting text (size sm, tone muted): figure captions, metadata, field hints and error messages.

Import

import.tsx
import { Caption } from "@neshel-ui/typography";

Usage

Preview: caption-figure
Preview theme
Figure 1 — Monthly revenue, last twelve months.

Updated a few minutes ago.

caption-figure.tsx
import { Stack } from "@neshel-ui/layout";
import { Caption, Paragraph } from "@neshel-ui/typography";

export default function CaptionFigure() {
  return (
    <Stack as="figure" space="2" className="m-0">
      <div
        className="h-24 rounded-lg bg-[var(--neshel-muted)]"
        role="img"
        aria-label="Revenue chart placeholder"
      />
      <Caption asChild>
        <figcaption>Figure 1 — Monthly revenue, last twelve months.</figcaption>
      </Caption>
      <Paragraph size="sm">
        <Caption as="span" tone="default">
          Updated
        </Caption>{" "}
        a few minutes ago.
      </Paragraph>
    </Stack>
  );
}

API

CaptionProps

CaptionProps
PropTypeDefaultDescription
alignResponsive<TextAlign>—Text alignment (logical: start/end).
asE——
asChild(required)boolean——
familyFontRole—Font role (Heading "display", Paragraph and Caption "body"; Text inherits).
leadingResponsive<TextLeading>—Unitless line height; defaults to the size's leading. Drives Capsize trimming.
measureTextMeasure—Maximum line length: narrow 45ch, comfortable 65ch, wide 80ch.
refRef<HTMLElement>——
sizeResponsive<TextSize>—Size token; font-size = token × the font role's cap-height scale.
toneTextTone—Colour role paired with the background for contrast (Caption defaults to "muted").
trackingTextTracking—Letter spacing.
trimbooleantrueCapsize trimming of the space above the cap height and below the baseline (default true).
truncateboolean—One line with an ellipsis (clips overflow, so trimming is removed).
weightResponsive<TextWeight>—Font weight; Heading defaults to "semibold".
wrapTextWrap—Line wrapping strategy (balance suits headings, pretty paragraphs).

Also accepts the props of: React DOM attributes.

CaptionElement

type CaptionElement = "p" | "span" | "div" | "small" | "figcaption"

Accessibility

For a field hint or error, give the Caption an id and reference it from the control with aria-describedby. Use tone="destructive" for errors, but never colour alone: say what is wrong.

Common mistakes

  • Using Caption for headings of small sections: use Heading with a small size.
Edit on GitHub

On this page