Set the alignment, wrapping, transformation, size, weight, line height and decoration of text.
Text alignment
Text alignment utilities set the CSS text-align property. Responsive variants apply at the specified breakpoint and above, and container variants under the @ prefix (.@md:text-center) at the same width of the nearest query container.
Start aligned text on all viewport sizes.
Center aligned text on all viewport sizes.
End aligned text on all viewport sizes.
End aligned text on viewports sized "sm" or wider.
End aligned text on viewports sized "md" or wider.
End aligned text on viewports sized "lg" or wider.
End aligned text on viewports sized "xl" or wider.
End aligned text on viewports sized "2xl" or wider.
<p class="text-start">Start aligned text on all viewport sizes.</p>
<p class="text-center">Center aligned text on all viewport sizes.</p>
<p class="text-end">End aligned text on all viewport sizes.</p>
<p class="sm:text-end">End aligned text on viewports sized "<b>sm</b>" or wider.</p>
<p class="md:text-end">End aligned text on viewports sized "<b>md</b>" or wider.</p>
<p class="lg:text-end">End aligned text on viewports sized "<b>lg</b>" or wider.</p>
<p class="xl:text-end">End aligned text on viewports sized "<b>xl</b>" or wider.</p>
<p class="2xl:text-end">End aligned text on viewports sized "<b>2xl</b>" or wider.</p>There is no utility class for justified text: it produces uneven word spacing, which reduces readability.
Text wrapping
.text-wrap sets white-space: normal, so text breaks across lines when it reaches the edge of its container.
<div class="badge primary text-wrap" style="width: 6rem;">
This text should wrap.
</div>.text-nowrap keeps text on a single line, whatever the width of the container.
<div class="text-nowrap bg-evident border" style="width: 8rem;">
This text should overflow the parent.
</div>Word break
.text-break keeps a long unbroken string from overflowing its container by setting word-wrap: break-word and word-break: break-word.
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
<p class="text-break">mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm</p>Arabic words cannot be broken, so .text-break does not suit content in Arabic, the most widely used RTL language.
Text transform
Text transform utilities set the CSS text-transform property.
Lowercased Text
uppercased text
capitalized text
istanbul
İSTANBUL
istanbul
<p class="text-lowercase">Lowercased Text</p>
<p class="text-uppercase">uppercased text</p>
<p class="text-capitalize">capitalized text</p>
<p class="text-uppercase" lang="tr">istanbul</p>
<p class="text-lowercase" lang="tr">İSTANBUL</p>
<p class="text-capitalize" lang="tr">istanbul</p>.text-capitalize does not account for locale, even when lang is specified on the element.
Font size
.text-lg and .text-sm scale the font size up or down in em, relative to the font size the element inherits.
Easily make text larger or smaller to suit your design needs.
Easily make text larger or smaller to suit your design needs.
<p class="font-lg">Easily make text <span class="text-lg">larger</span> or <span class="text-sm">smaller</span> to suit your design needs.</p>
<p class="font-sm">Easily make text <span class="text-lg">larger</span> or <span class="text-sm">smaller</span> to suit your design needs.</p>Font weight and style
.text-{weight} classes set font-weight, and .text-italic and .text-normal set font-style.
Bold text.
Bolder weight text (relative to the parent element).
Semibold weight text.
Medium weight text.
Normal weight text.
Light weight text.
Lighter weight text (relative to the parent element).
Italic text.
Text with normal font style
<p class="text-bold">Bold text.</p>
<p class="text-bolder">Bolder weight text (relative to the parent element).</p>
<p class="text-semibold">Semibold weight text.</p>
<p class="text-md">Medium weight text.</p>
<p class="text-regular">Normal weight text.</p>
<p class="text-light">Light weight text.</p>
<p class="text-lighter">Lighter weight text (relative to the parent element).</p>
<p class="text-italic">Italic text.</p>
<p class="text-normal">Text with normal font style</p>Line height
.text-lh-{size} utilities set line-height: .text-lh-1 to 1, and .text-lh-sm, .text-lh-md, and .text-lh-lg to the small, medium, and large line heights.
This is a long paragraph written to show how the line-height of an element is affected by the utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with the utility API.
This is a long paragraph written to show how the line-height of an element is affected by the utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with the utility API.
This is a long paragraph written to show how the line-height of an element is affected by the utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with the utility API.
This is a long paragraph written to show how the line-height of an element is affected by the utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with the utility API.
<p class="text-lh-1">This is a long paragraph written to show how the line-height of an element is affected by the utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with the utility API.</p>
<p class="text-lh-sm">This is a long paragraph written to show how the line-height of an element is affected by the utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with the utility API.</p>
<p class="text-lh-md">This is a long paragraph written to show how the line-height of an element is affected by the utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with the utility API.</p>
<p class="text-lh-lg">This is a long paragraph written to show how the line-height of an element is affected by the utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with the utility API.</p>Text decoration
Text decoration utilities set or remove the line of the decoration, the CSS text-decoration-line property. They leave the color and thickness classes below alone, whichever class comes later in the stylesheet.
This text has a line underneath it.
This text has a line going through it.
This link has its text decoration removed<p class="text-underline">This text has a line underneath it.</p>
<p class="text-line-through">This text has a line going through it.</p>
<a class="text-decoration-none" href="#">This link has its text decoration removed</a>Thickness
Add .text-decoration-{n} to set the text-decoration-thickness property.
Decoration thickness 1
Decoration thickness 2
Decoration thickness 3
Decoration thickness 4
<p class="text-underline text-decoration-1">Decoration thickness 1</p>
<p class="text-underline text-decoration-2">Decoration thickness 2</p>
<p class="text-underline text-decoration-3">Decoration thickness 3</p>
<p class="text-underline text-decoration-4">Decoration thickness 4</p>Color
.text-decoration-{context} sets the decoration to a context color and leaves the text color as it is.
Default underline
Alternate underline
Primary underline
Secondary underline
Neutral underline
Danger underline
Success underline
Warning underline
Info underline
Black underline
White underline
<p class="text-underline text-decoration-default">Default underline</p>
<p class="text-underline text-decoration-alternate">Alternate underline</p>
<p class="text-underline text-decoration-primary">Primary underline</p>
<p class="text-underline text-decoration-secondary">Secondary underline</p>
<p class="text-underline text-decoration-neutral">Neutral underline</p>
<p class="text-underline text-decoration-danger">Danger underline</p>
<p class="text-underline text-decoration-success">Success underline</p>
<p class="text-underline text-decoration-warning">Warning underline</p>
<p class="text-underline text-decoration-info">Info underline</p>
<p class="text-underline text-decoration-black">Black underline</p>
<p class="text-underline text-decoration-white">White underline</p>Opacity
.text-decoration-opacity-{value} adjusts the alpha channel of the decoration color. Apply it alongside .text-decoration or any .text-decoration-{color} class, which set the decoration color as an opacity-aware value.
Text decoration opacity solid
Text decoration opacity 95
Text decoration opacity 90
Text decoration opacity 80
Text decoration opacity 70
Text decoration opacity 60
Text decoration opacity 50
Text decoration opacity 40
Text decoration opacity 30
Text decoration opacity 20
Text decoration opacity 10
Text decoration opacity 05
Text decoration opacity zero
<p class="text-underline text-decoration text-decoration-opacity-solid">Text decoration opacity solid</p>
<p class="text-underline text-decoration text-decoration-opacity-95">Text decoration opacity 95</p>
<p class="text-underline text-decoration text-decoration-opacity-90">Text decoration opacity 90</p>
<p class="text-underline text-decoration text-decoration-opacity-80">Text decoration opacity 80</p>
<p class="text-underline text-decoration text-decoration-opacity-70">Text decoration opacity 70</p>
<p class="text-underline text-decoration text-decoration-opacity-60">Text decoration opacity 60</p>
<p class="text-underline text-decoration text-decoration-opacity-50">Text decoration opacity 50</p>
<p class="text-underline text-decoration text-decoration-opacity-40">Text decoration opacity 40</p>
<p class="text-underline text-decoration text-decoration-opacity-30">Text decoration opacity 30</p>
<p class="text-underline text-decoration text-decoration-opacity-20">Text decoration opacity 20</p>
<p class="text-underline text-decoration text-decoration-opacity-10">Text decoration opacity 10</p>
<p class="text-underline text-decoration text-decoration-opacity-05">Text decoration opacity 05</p>
<p class="text-underline text-decoration text-decoration-opacity-zero">Text decoration opacity zero</p>Underline offset
.underline-offset-{n} sets text-underline-offset in em units, so the offset scales with the font size of the element.
Standard underline
Offset 1 underline
Offset 2 underline
Offset 3 underline
<p class="text-underline">Standard underline</p>
<p class="text-underline underline-offset-1">Offset 1 underline</p>
<p class="text-underline underline-offset-2">Offset 2 underline</p>
<p class="text-underline underline-offset-3">Offset 3 underline</p>CSS
Text utilities are generated using Sass maps via the utilities API.
Reference
The table lists all text utilities and their CSS properties.
| Class | Properties |
|---|---|
.font-ui | font-family: var(--cx-font-family-ui); |
.font-prose | font-family: var(--cx-font-family-prose); |
.font-display | font-family: var(--cx-font-family-display); |
.font-code | font-family: var(--cx-font-family-code); |
.font-icon | font-family: var(--cx-font-family-icon); |
.font-normal | font-weight: var(--cx-font-weight-normal); |
.font-strong | font-weight: var(--cx-font-weight-strong); |
.font-mass | font-weight: var(--cx-font-weight-mass); |
.font-elegant | font-weight: var(--cx-font-weight-elegant); |
.font-6xl | font-size: var(--cx-font-size-6xl); |
.font-5xl | font-size: var(--cx-font-size-5xl); |
.font-4xl | font-size: var(--cx-font-size-4xl); |
.font-3xl | font-size: var(--cx-font-size-3xl); |
.font-2xl | font-size: var(--cx-font-size-2xl); |
.font-xl | font-size: var(--cx-font-size-xl); |
.font-lg | font-size: var(--cx-font-size-lg); |
.font-md | font-size: var(--cx-font-size-md); |
.font-sm | font-size: var(--cx-font-size-sm); |
.font-xs | font-size: var(--cx-font-size-xs); |
.font-2xs | font-size: var(--cx-font-size-2xs); |
.text-italic | font-style: italic; |
.text-normal | font-style: normal; |
.text-lighter | font-weight: lighter; |
.text-light | font-weight: 300; |
.text-regular | font-weight: 400; |
.text-medium | font-weight: 500; |
.text-semibold | font-weight: 600; |
.text-bold | font-weight: 700; |
.text-bolder | font-weight: bolder; |
.text-sm | font-size: 0.875em; |
.text-lg | font-size: 1.25em; |
.text-lh-1 | line-height: 1; |
.text-lh-sm | line-height: 1.25em; |
.text-lh-md | line-height: 1.5em; |
.text-lh-lg | line-height: 2em; |
.text-start | text-align: start; |
.text-end | text-align: end; |
.text-center | text-align: center; |
.text-wrap | white-space: normal; |
.text-nowrap | white-space: nowrap; |
.text-break | word-wrap: break-word; |
.text-lowercase | text-transform: lowercase; |
.text-uppercase | text-transform: uppercase; |
.text-capitalize | text-transform: capitalize; |
.text-decoration-none | text-decoration-line: none; |
.text-underline | text-decoration-line: underline; |
.text-line-through | text-decoration-line: line-through; |
.text-decoration-default | text-decoration-color: oklch(from var(--cx-default) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-alternate | text-decoration-color: oklch(from var(--cx-alternate) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-primary | text-decoration-color: oklch(from var(--cx-primary) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-secondary | text-decoration-color: oklch(from var(--cx-secondary) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-neutral | text-decoration-color: oklch(from var(--cx-neutral) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-warning | text-decoration-color: oklch(from var(--cx-warning) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-success | text-decoration-color: oklch(from var(--cx-success) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-danger | text-decoration-color: oklch(from var(--cx-danger) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-info | text-decoration-color: oklch(from var(--cx-info) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-black | text-decoration-color: oklch(from var(--cx-black) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-white | text-decoration-color: oklch(from var(--cx-white) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration | text-decoration-color: oklch(from var(--cx-fg-color) l c h / var(--cx-decoration-opacity, 1)); |
.text-decoration-1 | text-decoration-thickness: 0.0625rem; |
.text-decoration-2 | text-decoration-thickness: 0.125rem; |
.text-decoration-3 | text-decoration-thickness: 0.185rem; |
.text-decoration-4 | text-decoration-thickness: 0.25rem; |
.underline-offset-0 | text-underline-offset: 0; |
.underline-offset-1 | text-underline-offset: 0.125em; |
.underline-offset-2 | text-underline-offset: 0.25em; |
.underline-offset-3 | text-underline-offset: 0.375em; |
.text-decoration-opacity-solid | --cx-decoration-opacity: 1; |
.text-decoration-opacity-95 | --cx-decoration-opacity: 0.95; |
.text-decoration-opacity-90 | --cx-decoration-opacity: 0.9; |
.text-decoration-opacity-80 | --cx-decoration-opacity: 0.8; |
.text-decoration-opacity-70 | --cx-decoration-opacity: 0.7; |
.text-decoration-opacity-60 | --cx-decoration-opacity: 0.6; |
.text-decoration-opacity-50 | --cx-decoration-opacity: 0.5; |
.text-decoration-opacity-40 | --cx-decoration-opacity: 0.4; |
.text-decoration-opacity-30 | --cx-decoration-opacity: 0.3; |
.text-decoration-opacity-20 | --cx-decoration-opacity: 0.2; |
.text-decoration-opacity-10 | --cx-decoration-opacity: 0.1; |
.text-decoration-opacity-05 | --cx-decoration-opacity: 0.05; |
.text-decoration-opacity-zero | --cx-decoration-opacity: 0; |
.text-decoration-opacity-subtle | --cx-decoration-opacity: 0.6; |
.text-decoration-opacity-slight | --cx-decoration-opacity: 0.25; |
Sass variables
The base font variables in scss/config/_defaults.scss refer to the typography tokens through custom properties.
// $font-size-root affects the value of `rem`, which is used for as well font sizes, paddings, and margins
$font-size-root: null; // 2vw;
$font-size-root-lg: $font-size-root; // 1vw; // for media-breakpoint-up(lg)
$font-size-root-sm: $font-size-root; // 4vw; // for media-breakpoint-down(sm)
$text-align: null;
// $font-size-base affects the font size of the body text
$font-size-base: var(--font-size-md); // Assumes the browser default, typically `16px`
$font-family-base: var(--font-family-ui);
$font-weight-base: var(--font-weight-normal);
$line-height-base: var(--line-height-md);
$small-font-size: .875em;
$lg-font-size: 1.25em;
$small-line-height: 1.25em;
$md-line-height: 1.5em;
$lg-line-height: 2em;
$sub-sup-font-size: .75em;
$font-weight-lighter: lighter;
$font-weight-light: 300;
$font-weight-regular: 400;
$font-weight-medium: 500;
$font-weight-semibold: 600;
$font-weight-bold: 700;
$font-weight-bolder: bolder;Sass maps
.font utilities are generated from Sass maps in scss/maps/_fonts.scss. $font-sizes, $font-weights and $line-heights hold the ui scale. A family class such as .font-prose points them at the scale of its family, read from its own maps: $prose-font-sizes, $prose-font-weights and $prose-line-heights, and the same three maps of display and code.
$font-families: (
"ui": $font-family-ui,
"prose": $font-family-prose,
"display": $font-family-display,
"code": $font-family-code,
"icon": $font-family-icon,
);$font-sizes: (
"6xl": $font-size-6xl,
"5xl": $font-size-5xl,
"4xl": $font-size-4xl,
"3xl": $font-size-3xl,
"2xl": $font-size-2xl,
"xl": $font-size-xl,
"lg": $font-size-lg,
"md": $font-size-md,
"sm": $font-size-sm,
"xs": $font-size-xs,
"2xs": $font-size-2xs,
);$font-weights: (
"normal": $font-weight-normal,
"strong": $font-weight-strong,
"mass": $font-weight-mass,
"elegant": $font-weight-elegant,
);$line-heights: (
"6xl": $line-height-6xl,
"5xl": $line-height-5xl,
"4xl": $line-height-4xl,
"3xl": $line-height-3xl,
"2xl": $line-height-2xl,
"xl": $line-height-xl,
"lg": $line-height-lg,
"md": $line-height-md,
"sm": $line-height-sm,
"xs": $line-height-xs,
"2xs": $line-height-2xs,
);Design tokens
Font utilities consume design tokens from Chassis Tokens with the $cx- prefix. — See the design tokens page.
Utilities API
Font and text utilities are declared in scss/utilities/_text.scss using the utilities API.
"font-family": (
property: $-family-properties,
class: font,
values: $-family-values
),
"cx-font-weight": (
property: font-weight,
class: font,
values: map-loop($font-weights, varify, "$key", "font-weight")
),
// scss-docs-start utils-font-size
"font-size": (
property: (
"font-size": null,
"line-height": null
),
class: font,
responsive: $enable-responsive-font-sizes,
container: false,
values: $-font-size-values
),
// scss-docs-end utils-font-size
"font-style": (
property: font-style,
class: text,
values: italic normal
),
"font-weight": (
property: font-weight,
class: text,
values: (
lighter: $font-weight-lighter,
light: $font-weight-light,
regular: $font-weight-regular,
medium: $font-weight-medium,
semibold: $font-weight-semibold,
bold: $font-weight-bold,
bolder: $font-weight-bolder
)
),
"text-size": (
property: font-size,
class: text,
values: (
sm: $small-font-size,
lg: $lg-font-size,
)
),
"line-height": (
property: line-height,
class: text-lh,
values: (
1: 1,
sm: $small-line-height,
md: $md-line-height,
lg: $lg-line-height,
)
),
"text-align": (
responsive: true,
container: true,
property: text-align,
class: text,
values: (
start: start,
end: end,
center: center,
)
),
"white-space": (
property: white-space,
class: text,
values: (
wrap: normal,
nowrap: nowrap,
)
),
"word-wrap": (
property: word-wrap word-break,
class: text,
values: (break: break-word)
),
"text-transform": (
property: text-transform,
class: text,
values: lowercase uppercase capitalize
),
// The longhand, so the line leaves the color and thickness classes alone
"text-decoration": (
property: text-decoration-line,
class: text,
values: (
decoration-none: none,
underline: underline,
line-through: line-through
)
),
"text-decoration-color": (
property: text-decoration-color,
class: text-decoration,
values: map.merge(
map-loop($context-colors, opacity-var, "$key", "decoration"),
(
null: #{to-opacity(var(--fg-color), var(--decoration-opacity, 1))},
)
)
),
"text-decoration-thickness": (
property: text-decoration-thickness,
class: text-decoration,
values: (
1: .0625rem,
2: .125rem,
3: .185rem,
4: .25rem,
)
),
"underline-offset": (
property: text-underline-offset,
class: underline-offset,
values: (
0: 0,
1: .125em,
2: .25em,
3: .375em,
)
),
"underline-opacity": (
property: --decoration-opacity,
class: text-decoration-opacity,
enabled: $enable-property-opacities,
state: hover,
values: $text-decoration-opacities
),