Text

A flexible text component for displaying content with various styles and properties.

experimental
---
import Text from '@/components/Text.astro';
---

<Text>Default text</Text>

Sizes

Text components use a numeric scale for sizes, corresponding to specific text styles.

sizedescriptionexamplecode
1Tiny TextTiny text<Text size="1">Tiny text</Text>
3Small TextSmall text<Text size="3">Small text</Text>
5Medium TextMedium text<Text size="5">Medium text</Text>
7Large TextLarge text<Text size="7">Large text</Text>
9Extra Large TextExtra large text<Text size="9">Extra large text</Text>

Note: Sizes 2, 4, 6, and 8 are also available for more fine-grained control.

Weights

Text components support different font weights.

weightdescriptionexamplecode
lightLight WeightLight text<Text weight="light">Light text</Text>
regularRegular WeightRegular text<Text weight="regular">Regular text</Text>
mediumMedium WeightMedium text<Text weight="medium">Medium text</Text>
boldBold WeightBold text<Text weight="bold">Bold text</Text>

Alignment

Text can be aligned in different ways.

aligndescriptionexamplecode
leftLeft AlignedLeft aligned text<Text align="left">Left aligned text</Text>
centerCenter AlignedCenter aligned text<Text align="center">Center aligned text</Text>
rightRight AlignedRight aligned text<Text align="right">Right aligned text</Text>

Colors

Text components support different colors based on the theme’s color system.

colordescriptionexamplecode
grayGray ColorGray text<Text color="gray">Gray text</Text>
blueBlue ColorBlue text<Text color="blue">Blue text</Text>
redRed ColorRed text<Text color="red">Red text</Text>
greenGreen ColorGreen text<Text color="green">Green text</Text>

Note: All color options from the theme are available.

Text components support different colors based on the theme’s color system.Text components support different colors based on the theme’s color system.

Trimming

Text can be trimmed to remove leading or trailing line height.

trimdescriptionexamplecode
normalNo TrimNormal text<Text trim="normal">Normal text</Text>
startTrim StartTrimmed start<Text trim="start">Trimmed start</Text>
endTrim EndTrimmed end<Text trim="end">Trimmed end</Text>
bothTrim BothTrimmed both<Text trim="both">Trimmed both</Text>

Other Properties

  • truncate: Truncates text with an ellipsis if it overflows its container.
  • wrap: Controls text wrapping (wrap, nowrap, pretty, balance).
  • highContrast: Increases the contrast of the text color.
  • as: Renders the text as a different HTML element (span, div, p, label).

Combining Properties

You can combine different properties to create custom text styles:

<Text 
  size="5" 
  weight="bold" 
  color="blue" 
  align="center" 
  truncate
>
  Custom styled text
</Text>

This will create a medium-sized, bold, blue, center-aligned text that truncates if it overflows.

Responsive Properties

Many properties of the Text component can be made responsive:

<Text 
  size={{ base: "3", md: "5", lg: "7" }}
  align={{ base: "left", md: "center" }}
>
  Responsive text
</Text>

This text will change size and alignment based on the viewport size.

Margin Properties

Text components support margin properties for spacing:

  • m: Margin on all sides
  • mx: Horizontal margin
  • my: Vertical margin
  • mt: Top margin
  • mr: Right margin
  • mb: Bottom margin
  • ml: Left margin

Example:

<Text m="2" mx="4">
  Text with margin
</Text>

This applies a margin of 2 units on all sides, and overrides the horizontal margin to 4 units.