Typography

Text

Run of text in one of the typography variants display, 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 display, h1 to h5, caption, body and code. display renders an h1 at the display size. 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>

An identifier in a line of text

variant="code" renders an inline <code> in the monospace face (--cinder-font-mono). It takes the size, weight and leading of the text around it, with no em scaling, so an identifier sits on the type scale beside the words instead of a step off it. Use it for an id, a name the person typed or a value no one would say aloud.

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

<Text variant="caption">Acme audit, <Text variant="code">acme-audit:redact-secrets</Text></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 more" 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, a space and a muted colour step after it, 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. truncate="end" does the same for a cut at the end, but only while the value is actually cut: a value that fits has no tab stop and no tooltip, and a cut one takes focus and opens its whole value in a tooltip (or the title you set), except inside a page's own Tooltip, which speaks instead.

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 more

A long run holds to five lines; Show more 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 'display''h1''h2''h3''h4''h5''caption''body'
1 more members 'code'
'body' Typography variant. Headings render h1 to h5, and display renders an h1; caption and body render paragraphs, and code renders an inline code element in the monospace face that takes the size of the text around it, for an identifier.
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 more" 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.
measure boolean false Holds the run to a readable line length (70 characters), so a paragraph in a wide region does not run to the region's edge. Off by default, so no existing text moves; turn it on for prose that sits in a column wider than a comfortable line, such as a note or an explanation.
actions snippet Content that sits beside the "Show more" button on the line under a clamped run, separated from it by a space and a colour step, 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.