0.3.39 Changelog
NoneAntuneHand-tuned reference colorsAntithesisWarm colors, pill buttons, and square text fields
LightDarkSystem
Search documentation

Text

Text is for paragraphs.

Playground

Links follow the surrounding text’s emphasis and color. In supporting text, they stay muted. The examples show how links and inline code look at each priority and tone.

Tones × priorities

NeutralBrandInfoSuccessCriticalWarning
primary
The link behavior section shows links next to code like npm install.
secondary
The link behavior section shows links next to code like npm install.
tertiary
The link behavior section shows links next to code like npm install.
quaternary
The link behavior section shows links next to code like npm install.
import { Text } from '@antadesign/anta/bundle'
const priorities = ['primary', 'secondary', 'tertiary', 'quaternary'] as const
export default function Demo() {
return (
<>
{priorities.map(priority => (
<Text key={priority} tone="brand" priority={priority}>
The <a href="#link-behavior">link behavior section</a> shows links next to code like <code>npm install</code>.
</Text>
))}
</>
)
}

Truncation and expansion

truncate limits text to one line with true or to a specific line count with a number. Clipped text shows its full content in a tooltip on hover.

truncate + automatic tooltip
The quick brown fox jumps over the lazy dog repeatedly while the morning sun rises over a sleepy town that nobody has visited in years and years and years.
truncate={2}
The quick brown fox jumps over the lazy dog repeatedly while the morning sun rises over a sleepy town that nobody has visited in years and years and years.
truncate={3}
The quick brown fox jumps over the lazy dog repeatedly while the morning sun rises over a sleepy town that nobody has visited in years and years and years.
import { Text } from '@antadesign/anta/bundle'
const longText = 'The quick brown fox jumps over the lazy dog repeatedly while the morning sun rises over a sleepy town that nobody has visited in years and years.'
export default function Demo() {
return (
<div style={{ maxWidth: 320, display: 'grid', gap: 12 }}>
<Text truncate>{longText}</Text>
<Text truncate={2}>{longText}</Text>
<Text truncate={3}>{longText}</Text>
</div>
)
}

expandable shows a Show more control when the text overflows. collapsible lets readers fold the text again.

truncate expandable
The quick brown fox jumps over the lazy dog repeatedly while the morning sun rises over a sleepy town that nobody has visited in years and years. Down by the river the old mill still turns, and the market stalls creak open one by one in the early light. Link guidance.
truncate={3} expandable
The quick brown fox jumps over the lazy dog repeatedly while the morning sun rises over a sleepy town that nobody has visited in years and years. Down by the river the old mill still turns, and the market stalls creak open one by one in the early light. Link guidance.
truncate={3} expandable collapsible
The quick brown fox jumps over the lazy dog repeatedly while the morning sun rises over a sleepy town that nobody has visited in years and years. Down by the river the old mill still turns, and the market stalls creak open one by one in the early light. Link guidance.
expandableInert
The quick brown fox jumps over the lazy dog repeatedly while the morning sun rises over a sleepy town that nobody has visited in years and years. Down by the river the old mill still turns, and the market stalls creak open one by one in the early light. Link guidance.
import { Text } from '@antadesign/anta/bundle'
const longText = 'The quick brown fox jumps over the lazy dog repeatedly while the morning sun rises over a sleepy town that nobody has visited in years and years.'
const content = (
<>
{longText} <a href="https://anta.design/text/#link-behavior">Link guidance</a>.
</>
)
export default function Demo() {
return (
<div style={{ maxWidth: 320, display: 'grid', gap: 12 }}>
<Text truncate expandable>{content}</Text>
<Text truncate={3} expandable>{content}</Text>
<Text truncate={3} expandable collapsible>{content}</Text>
<Text truncate={3} expandable collapsible expandableInert>{content}</Text>
</div>
)
}

expandableInert makes the whole folded preview an expansion target. Links become available after expansion.

Component props

Prop Type Default Description
priority? primarysecondarytertiaryquaternary secondary Controls text emphasis, from primary (strongest) to quaternary. See Tones × priorities for examples.
tone? neutralbrandcriticalinfosuccesswarningstring neutral Selects a text palette. A CSS color defines a custom tone. See Tones × priorities for examples.
size? smallmediumlarge medium Sets font size and line height: small 13/16 px, medium 15/20 px, and large 17/24 px.
inline? boolean — Lets Text sit within a line as an inline block.
truncate? booleannumber — Adds an ellipsis at the line limit. true limits text to one line, a positive integer sets the line count, and false or numbers below 1 disable truncation. Clipped text shows a tooltip when expansion is off. A nested <Tooltip> replaces it, and an empty tooltip suppresses it.
expandable? boolean — Shows a fade and a Show more control when truncated text overflows. Requires truncate and replaces the automatic tooltip.
expandableInert? boolean — Lets readers click anywhere in the preview to expand the text. Links and text selection become available after expansion. Requires expandable.
collapsible? boolean — Keeps the control visible after expansion so readers can collapse the text again. Requires expandable.
Inherited props (children, className, id, slot, style, tabIndex, title)
Prop Type Default Description
children? ReactNode — Content to render in place of any default content.
className? string — Adds CSS classes to the root element and preserves its existing classes.
id? string — HTML id attribute.
slot? string — Named slot in a parent web component, such as slot="header" in a <Dialog>.
style? CSSProperties — Inline CSS styles on the root element.
tabIndex? number — Tab order. Set to -1 to skip the element when tabbing.
title? string — HTML title attribute, shown as a browser tooltip on hover.

Plus every standard DOM event handler (onClick, onFocus, onKeyDown, …) and any data-* or aria-* attribute — forwarded as-is to the underlying <a-*> element.

Web Component

Use <a-text> directly for text priority and tone.

Read the color guidance.Your changes have been saved.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Anta Text</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@antadesign/[email protected]/dist/bundle.css">
</head>
<body>
<a-text priority="secondary">
Read the <a href="https://anta.design/colors/">color guidance</a>.
</a-text>
<a-text priority="primary" tone="success">Your changes have been saved.</a-text>
</body>
</html>

Use a tooltip with the web component

To use a tooltip inside the <a-text> web component, nest an <a-tooltip truncated-only> containing the full text. It appears on hover when the text is clipped.

A long status message that is clipped until you hover it.

A long status message that is clipped until you hover it.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Text tooltip</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@antadesign/[email protected]/dist/bundle.css">
<script type="module" src="https://esm.sh/@antadesign/[email protected]/bundle?bundle"></script>
</head>
<body>
<a-text truncate="1" style="max-width: 260px; cursor: help">
A long status message that is clipped until you hover it.
<a-tooltip truncated-only>
A long status message that is clipped until you hover it.
</a-tooltip>
</a-text>
</body>
</html>

In JavaScript, textElement refers to the <a-text> element. The read-only property textElement.isTruncated is true when the text is clipped.

Use expand with the web component

To expand clipped text inside the <a-text> web component, add expandable and place an <a-button> before <a-text-content>.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Expandable text</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@antadesign/[email protected]/dist/bundle.css">
<script type="module" src="https://esm.sh/@antadesign/[email protected]/bundle?bundle"></script>
</head>
<body>
<a-text truncate="1" expandable collapsible style="max-width: 260px">
<a-button role="button" tabindex="0" priority="quaternary" paddingless></a-button>
<a-text-content>The project settings apply to every workspace in the organization. Changes take effect the next time a workspace opens.</a-text-content>
</a-text>
</body>
</html>

For multiple lines, --line-clamp sets the line limit.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Expandable multiline text</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@antadesign/[email protected]/dist/bundle.css">
<script type="module" src="https://esm.sh/@antadesign/[email protected]/bundle?bundle"></script>
<style>.summary { max-width: 260px; --line-clamp: 3; }</style>
</head>
<body>
<a-text class="summary" truncate="3" expandable collapsible>
<a-button role="button" tabindex="0" priority="quaternary" paddingless></a-button>
<a-text-content>The project settings apply to every workspace in the organization. Changes take effect the next time a workspace opens. The project settings apply to every workspace in the organization. Changes take effect the next time a workspace opens.</a-text-content>
</a-text>
</body>
</html>

Make folded content inert

With expandable-inert, clicking anywhere in the collapsed preview expands the text. The example uses textpresentationchange to disable links inside <a-text-content> while the text is clipped and re-enable them when it expands.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Expandable text with an inert preview</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@antadesign/[email protected]/dist/bundle.css">
<script type="module" src="https://esm.sh/@antadesign/[email protected]/bundle?bundle"></script>
</head>
<body>
<a-text id="summary" truncate="1" expandable collapsible expandable-inert style="max-width: 260px">
<a-button role="button" tabindex="0" priority="quaternary" paddingless></a-button>
<a-text-content>The project settings apply to every workspace in the organization. Changes take effect the next time a workspace opens. <a href="https://anta.design/text/">Text docs</a>.</a-text-content>
</a-text>
<script type="module">
const text = document.querySelector('#summary')
const content = text.querySelector('a-text-content')
text.addEventListener('textpresentationchange', ({ detail }) => {
content.inert = detail.overflowing && !detail.expanded
})
</script>
</body>
</html>

Styling

Use priority, tone, and size for emphasis, color, and type scale. Shared Colors keep Text consistent with your theme. For a custom color, pass tone or set --text-tone-source.

import { Text } from '@antadesign/anta/bundle'
export default function Demo() {
return (
<>
<Text priority="secondary" tone="brand">Tinted secondary text</Text>
<Text tone="#0d9488">Custom-tone body copy</Text>
</>
)
}

Style the light-DOM host, content, control, and links with plain CSS. The .fancy class belongs to this example:

Body copy with a prose link inside it.
/* Anta's theme controls color-scheme for light-dark(). */
a-text.fancy {
color: light-dark(#0f6e5f, #5fd0bb);
font-size: 16px;
line-height: 1.7;
letter-spacing: 0.06em;
}
a-text.fancy a { text-decoration-thickness: 2px; text-underline-offset: 3px; }