Skip to content

Text

The Text component is a versatile typographic component that supports various styling options through variants, colors, and text alignment. It picks a sensible default HTML element based on the selected variant, which you can override with as.

Variations

Variant

The Text component supports various typographic variants. The default variant is body-normal. Other variants include:

Color

The Text component supports various color options to enhance visibility and convey meaning. The default color is foreground-2 (heading variants default to foreground-1). Other available colors include:

Align

Wrap

Truncate

The truncate prop truncates text with an ellipsis if it overflows its container. This is particularly useful for single-line text that should not wrap.

Line clamp

The lineClamp prop controls how many lines of text are shown before truncating. It can be set to a specific number or to 'default' for the component’s default behavior.

Note: The lineClamp prop takes precedence over the truncate prop when both are used, as it provides more specific control over text clamping.

Installation

import { Text } from "@harnessio/ui/components";
// Basic
<Text>Default text with the body-normal variant</Text>
// Variant + color
<Text variant="heading-section" color="foreground-1">Section heading</Text>
// Override the element for correct semantics
<Text variant="heading-hero" as="h1">Hero heading as a real h1</Text>
// Truncation
<Text truncate>Truncated with an ellipsis if it overflows</Text>