Text
The Text component is a semantic text component built on top of Box, designed for body copy, labels, captions, and other inline text content.
Open in Storybook
Import
import { Text } from "@tosui/react";
Basic usage
- Preview
- Code
<Text>Default text content</Text>
Key features
- Default element:
<span>(inline) - Polymorphic: Can render as any element via
asprop - Shorthand props: Convenient aliases for common text styling
- Utility props: Built-in support for truncation and italics
- Built on Box: Accepts Box props except the typography and color props that Text replaces
Size
Text uses Tosui's font size scale:
- Preview
- Code
5XL (48px)4XL (36px)3XL (30px)2XL (24px)Extra large (20px)Large text (18px)Default text (16px)Small text (14px)Extra small text (12px)
<Text size="5xl">5XL (48px)</Text>
<Text size="4xl">4XL (36px)</Text>
<Text size="3xl">3XL (30px)</Text>
<Text size="2xl">2XL (24px)</Text>
<Text size="xl">Extra large (20px)</Text>
<Text size="lg">Large text (18px)</Text>
<Text size="md">Default text (16px)</Text>
<Text size="sm">Small text (14px)</Text>
<Text size="xs">Extra small text (12px)</Text>
Default: md
Weight
Font weight options:
- Preview
- Code
Normal weight (400)
Medium weight (500)
Semibold weight (600)
Bold weight (700)
Medium weight (500)
Semibold weight (600)
Bold weight (700)
<Text weight="normal">Normal weight (400)</Text>
<Text weight="medium">Medium weight (500)</Text>
<Text weight="semibold">Semibold weight (600)</Text>
<Text weight="bold">Bold weight (700)</Text>
Default: normal
Alignment
<Text align="left">Left aligned</Text>
<Text align="center">Center aligned</Text>
<Text align="right">Right aligned</Text>
<Text align="justify">Justified text</Text>
Color
Text supports Tosui's semantic color tokens:
- Preview
- Code
Primary text color
Secondary/muted text
Tertiary/subtle text
Primary brand color
Primary emphasis
Accent color
Accent emphasis
Success color
Warning color
Error color
Secondary/muted text
Tertiary/subtle text
Primary brand color
Primary emphasis
Accent color
Accent emphasis
Success color
Warning color
Error color
<Text color="foreground">Primary text color</Text>
<Text color="foreground-muted">Secondary/muted text</Text>
<Text color="foreground-subtle">Tertiary/subtle text</Text>
<Text color="primary">Primary brand color</Text>
<Text color="primary-emphasis">Primary emphasis</Text>
<Text color="accent">Accent color</Text>
<Text color="accent-emphasis">Accent emphasis</Text>
<Text color="success">Success color</Text>
<Text color="warning">Warning color</Text>
<Text color="error">Error color</Text>
Truncate
Automatically truncates text with an ellipsis:
<Text truncate>
This is a very long piece of text that will be truncated with an ellipsis when
it overflows its container
</Text>
This applies:
overflow: hiddentext-overflow: ellipsiswhite-space: nowrap
Italic
<Text italic>Italic text</Text>
Polymorphic rendering
Render as different elements while maintaining Text styling:
<Text as="p">Paragraph element</Text>
<Text as="label">Label element</Text>
<Text as="span">Span element (default)</Text>
<Text as="div">Block-level div</Text>
Common patterns
Label text
<Text as="label" size="sm" weight="medium">
Email Address
</Text>
Caption text
<Text size="sm" color="foreground-muted">
Last updated 2 hours ago
</Text>
Error message
<Text size="sm" color="error">
This field is required
</Text>
Muted helper Text
<Text size="sm" color="foreground-subtle">
We'll never share your email address
</Text>
Emphasized text
<Text weight="semibold" color="primary">
Important information
</Text>
Combining with Box props
Text accepts the Box props that it does not replace:
<Text size="lg" weight="medium" p={4} bg="surface" rounded="md">
Text with background and padding
</Text>
Layout example
<Box display="flex" flexDirection="column" gap={2}>
<Text size="lg" weight="semibold">
Section Title
</Text>
<Text color="foreground-muted">
Section description goes here with muted color
</Text>
<Text size="sm" color="foreground-subtle">
Additional context or metadata
</Text>
</Box>
Props reference
Text-Specific props
size: Font size (xs|sm|md|lg|xl|2xl|3xl|4xl|5xl)weight: Font weight (normal|medium|semibold|bold)align: Text alignment (left|center|right|justify)color: Semantic color token (see Color section above)truncate: Enable text truncation with ellipsisitalic: Enable italic styling
Inherited from Box
Text inherits all props from Box except fontSize, fontWeight, textAlign, and color (which are replaced by the shorthand props above). This includes:
- Spacing (margin, padding)
- Layout (display, position)
- Size (width, height)
- Flexbox and grid
- Borders, roundness, shadows
- Other Box style props
See the Box component documentation for the full list.
TypeScript
TextProps infers the HTML attributes for the element selected by as.