Typography

Text

Run of text in one of the typography variants h1 to h5, caption, or body that inherits its color from its container.

import { Text } from '@lostgradient/cinder';
typographytext
01

Overview

Reference usage

A run of text in one of the typography variants h1 to h5, caption, and body. Color is inherited from the container.

Usage

svelte
<script lang="ts">
  import { Text } from '@lostgradient/cinder';
</script>

<Text variant="h2">Release notes</Text>
<Text>Body text renders a paragraph.</Text>
<Text variant="h1" as="h2">Styled as h1, rendered as h2</Text>

Clamping a long run

clamp holds the text to that many lines so a long reply keeps the shape of the page. A "Show all" button appears on the line under it only while the text is actually cut off, and opens the rest in place (it reads "Show less" while open). expanded is bindable. actions puts a page's own link on the same line, after a middle dot, such as "Show raw payloads".

svelte
<script lang="ts">
  import { Text } from '@lostgradient/cinder';

  let { reply }: { reply: string } = $props();
</script>

<Text clamp={5}>
  {reply}
  {#snippet actions()}
    <a href="#raw">Show raw payloads</a>
  {/snippet}
</Text>

Cutting an identifier in the middle

truncate="middle" keeps the end of a long identifier visible, because the end is what tells one from another: "payments-worker-eu-w…3a68". It takes the plain string as text (so it has no children), keeps the last tailLength characters (4 by default), and gives the head an ellipsis only when the line is too narrow, and measures the cut so the ellipsis sits against the tail with no gap. The full text is a Cinder tooltip unless title is set, and the cut text takes focus, so a keyboard or touch user can reach the whole value too. The whole string stays in the DOM for assistive technology and copying.

svelte
<script lang="ts">
  import { Text } from '@lostgradient/cinder';
</script>

<Text truncate="middle" text="payments-worker-eu-west-1b-7f3a9c2e-4d81-4b06-a9e2-1c5d0f7b3a68" />
Live preview

Overriding the element

Styled as h1, rendered as h2

Inline caption

02

When to use

Use when
  • Rendering a heading, paragraph, or caption in the design system's type scale.
  • Overriding the rendered element while keeping a variant's visual style.
Avoid when
  • Introducing a page section with an eyebrow, description, or actions — use section-heading instead.
  • Rendering Markdown content — compose the Markdown renderer instead.
03

Examples

Overriding the element

The as prop swaps the rendered element while keeping the variant style, for example a visually large h2 inside a section.

Clamped run with Show all

A long run holds to five lines; Show all opens the rest in place and the page's own link sits beside it.

Inherited color

Text takes its color from the container, so it follows any surface it is placed on.

Cut in the middle

A long identifier keeps its last four characters when the line is too narrow, because the end of an id tells workers apart. Focus it, or hover it, to read the whole id in the tooltip; it is the only tab stop in the row.

Typography variants

Each variant renders its matching element: h1 to h5 headings, and paragraphs for caption and body.

04

Props

Props for text
Name
Type
Default
Description
variant 'h1''h2''h3''h4''h5''caption''body' 'body' Typography variant. Headings render h1 to h5; caption and body render paragraphs.
as NonMetadataHTMLElementTagName Element tag that overrides the variant's default element.
children discriminated-union Required text content.
clamp number Holds the text to this many lines, so a long reply keeps the shape of the page. A "Show all" button appears under it only while the text is actually cut off, and opens the rest in place.
expanded bindable boolean false Whether a clamped run is open to its full length. Bindable; ignored without clamp.
actions snippet Content that sits beside the "Show all" button on the line under a clamped run, separated from it by a middle dot, such as a "Show raw payloads" link. Ignored without clamp.
truncate undefined Cuts the text in the middle when it is too long for one line, so the end stays visible ("payments-worker-eu-w…3a68"), for an identifier whose end tells one from another. Needs text. The full text is a tooltip, reachable by keyboard and touch because the cut text takes focus, unless title is set.
text discriminated-union The plain text to cut in the middle.
tailLength number 4 With truncate="middle", how many characters at the end of the text stay visible.