Text
Text is a polymorphic typography component for rendering any text element with consistent size, weight, and overflow handling.
Default
Text renders a p element by default.
The quick brown fox jumps over the lazy dog. Typography is the art of arranging type to make written language legible and appealing.
tsx
import { Text } from "@hummingbirdui/react";
export default function TextDefault() {
return (
<Text>
The quick brown fox jumps over the lazy dog. Typography is the art of
arranging type to make written language legible and appealing.
</Text>
);
}Headings
Text can render any heading element from h1 to h6.
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
tsx
import { Text } from "@hummingbirdui/react";
export default function TextHeadings() {
return (
<div className="flex flex-col gap-2">
<Text as="h1">Heading 1</Text>
<Text as="h2">Heading 2</Text>
<Text as="h3">Heading 3</Text>
<Text as="h4">Heading 4</Text>
<Text as="h5">Heading 5</Text>
<Text as="h6">Heading 6</Text>
</div>
);
}Elements
Other text elements can be rendered by passing the as prop.
Code textMark texttsx
import { Text } from "@hummingbirdui/react";
export default function TextElements() {
return (
<div className="flex flex-col gap-2">
<Text as="span">Span text</Text>
<Text as="strong">Strong text</Text>
<Text as="em">Emphasis text</Text>
<Text as="small">Small text</Text>
<Text as="label">Label text</Text>
<Text as="code">Code text</Text>
<Text as="mark">Mark text</Text>
<Text as="del">Deleted text</Text>
<Text as="ins">Inserted text</Text>
</div>
);
}Sizes
The size prop sets the font size, from xs up to 9xl.
Text xs
Text sm
Text base
Text lg
Text xl
Text 2xl
Text 3xl
Text 4xl
Text 5xl
Text 6xl
Text 7xl
Text 8xl
Text 9xl
tsx
import { Text } from "@hummingbirdui/react";
export default function TextSizes() {
return (
<div className="flex flex-col gap-2">
<Text size="xs">Text xs</Text>
<Text size="sm">Text sm</Text>
<Text size="base">Text base</Text>
<Text size="lg">Text lg</Text>
<Text size="xl">Text xl</Text>
<Text size="2xl">Text 2xl</Text>
<Text size="3xl">Text 3xl</Text>
<Text size="4xl">Text 4xl</Text>
<Text size="5xl">Text 5xl</Text>
<Text size="6xl">Text 6xl</Text>
<Text size="7xl">Text 7xl</Text>
<Text size="8xl">Text 8xl</Text>
<Text size="9xl">Text 9xl</Text>
</div>
);
}Font weight
The fontWeight prop sets the font weight, from thin up to black.
Font weight thin
Font weight extralight
Font weight light
Font weight normal
Font weight medium
Font weight semibold
Font weight bold
Font weight extrabold
Font weight black
tsx
import { Text } from "@hummingbirdui/react";
export default function TextWeights() {
return (
<div className="flex flex-col gap-2">
<Text fontWeight="thin">Font weight thin</Text>
<Text fontWeight="extralight">Font weight extralight</Text>
<Text fontWeight="light">Font weight light</Text>
<Text fontWeight="normal">Font weight normal</Text>
<Text fontWeight="medium">Font weight medium</Text>
<Text fontWeight="semibold">Font weight semibold</Text>
<Text fontWeight="bold">Font weight bold</Text>
<Text fontWeight="extrabold">Font weight extrabold</Text>
<Text fontWeight="black">Font weight black</Text>
</div>
);
}Truncate
Setting truncate cuts off overflowing text on a single line with an ellipsis.
This is a long line of text that gets cut off with an ellipsis once it runs out of horizontal space inside its container.
tsx
import { Text } from "@hummingbirdui/react";
export default function TextTruncate() {
return (
<Text truncate className="max-w-xs">
This is a long line of text that gets cut off with an ellipsis once it
runs out of horizontal space inside its container.
</Text>
);
}Line clamp
The lineClamp prop limits the text to the given number of lines and truncates the overflow with an ellipsis.
Line clamping limits a block of text to the given number of lines and truncates the rest with an ellipsis. This paragraph is intentionally long so the overflow beyond the second line is hidden from view.
tsx
import { Text } from "@hummingbirdui/react";
export default function TextLineClamp() {
return (
<Text lineClamp={2} className="max-w-sm">
Line clamping limits a block of text to the given number of lines and
truncates the rest with an ellipsis. This paragraph is intentionally long
so the overflow beyond the second line is hidden from view.
</Text>
);
}API Reference
| Prop | Type | Default |
|---|---|---|
as | "p" | "span" | "label" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "small" | "strong" | "em" | "blockquote" | "code" | "mark" | "del" | "ins" | "sub" | "sup" | "b" | "p" |
size | "xs" | "sm" | "base" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "7xl" | "8xl" | "9xl" | — |
fontWeight | "thin" | "extralight" | "light" | "normal" | "medium" | "semibold" | "bold" | "extrabold" | "black" | — |
truncate | boolean | — |
lineClamp | 1 | 2 | 3 | 4 | 5 | 6 | — |
className | string | — |