Typography

Typography

Semantic typography primitives for headings, body and code.

Rust
1use herogpui::components::typography::{Typography, TypographyType};

Usage

Rust
1use herogpui::prelude::{Typography, TypographyType};
2
3Typography::new(
4    "Typography sets the size, weight and line height of a run of text.",
5)

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

TypographyProse

Typography is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Typography uses.

Styling

Typography styling
StyleDescription
text_color(colors.foreground)Base primitive: foreground color only; every metric comes from the type modifier.
H1 => text_size(px(36.)) + line_height(px(40.)) + FontWeight::SEMIBOLD36px semibold at the 40px text-4xl leading. `tracking-tight` is an honest limitation: GPUI 0.2.2 has no letter-spacing.
H2 => text_size(px(30.)) + line_height(px(36.)) + FontWeight::SEMIBOLD30/36 semibold; `tracking-tight` unsupported (no letter-spacing in GPUI).
H3 => text_size(px(24.)) + line_height(px(32.)) + FontWeight::SEMIBOLD24/32 semibold; `tracking-tight` unsupported (no letter-spacing in GPUI).
H4 => text_size(px(20.)) + line_height(px(28.)) + FontWeight::SEMIBOLD20/28 semibold; `tracking-tight` unsupported (no letter-spacing in GPUI).
H5 => text_size(px(18.)) + line_height(px(28.)) + FontWeight::SEMIBOLD18/28 semibold; `tracking-tight` unsupported (no letter-spacing in GPUI).
H6 => text_size(px(16.)) + line_height(px(24.)) + FontWeight::SEMIBOLD16/24 semibold; `tracking-tight` unsupported (no letter-spacing in GPUI).
Body => text_size(px(16.)) + line_height(px(28.))16px body copy at the 28px leading-7.
BodySm => text_size(px(14.)) + line_height(px(24.))14px text at the 24px leading-6.
BodyXs => text_size(px(12.)) + line_height(px(20.))12px text at the 20px leading-5.
Code => font_family(MONO) + bg(colors.default.color) + mark_radius + px(px(6.)) + py(px(2.)) + text_size(px(14.)) + line_height(px(20.))Inline code chip: mono 14/20 text painted on the `bg-default` chip at the mark radius with 6px/2px padding.
TextAlign::Start => text_leftStart alignment, the default.
TextAlign::Center => text_centerCentered alignment.
TextAlign::End => text_rightEnd alignment.
TextAlign::Justify => text_leftJustified text: GPUI 0.2.2 has no `text-justify`, so falls back to start alignment.
TextColor::Default => colors.foregroundDefault color role.
TextColor::Muted => colors.mutedMuted color role.
truncate()Single-line ellipsis truncation; the port's root div is already a block, so only the truncation applies.
FontWeight::Normal => gpui::FontWeight::NORMALNormal (400) weight override, demonstrated in the gallery weight examples.
FontWeight::Medium => gpui::FontWeight::MEDIUMMedium (500) weight override, demonstrated in the gallery weight examples.
FontWeight::Semibold => gpui::FontWeight::SEMIBOLDSemibold (600) weight override, demonstrated in the gallery weight examples.
FontWeight::Bold => gpui::FontWeight::BOLDBold (700) weight override, demonstrated in the gallery weight examples.

API reference

Builders

Typography builders
BuilderTypeDefaultDescription
kind(TypographyType)TypographyTypeTypographyType::BodySemantic typography style, carrying the tagged scale's size/line-height pair, the heading weight and the code family. Named `kind` because `type` is a Rust keyword.
align(TextAlign)TextAlignTextAlign::StartText alignment. GPUI 0.2.2 has no `text-justify`; justify falls back to start alignment.
color(TextColor)TextColorTextColor::DefaultText color role.
weight(FontWeight)FontWeightFont weight override over the type's default.
truncate(bool)boolTruncates the text to one line with an ellipsis.
ParentElement::extendAnyElementText content, either as the constructor's text or as composed children.
heading(u8, text)u8, text1Maps to `type="h1"` through `type="h6"`; higher levels clamp to h6.
paragraph(ParagraphSize, text)ParagraphSize, text'base'Maps to the `body`, `body-sm` and `body-xs` types.
code(text)textThe inline code text; `Typography.Code` is the `code` type.

Parts

Typography parts
PartDescription
TypographyRoot primitive: maps each type to its semantic element (`h1`–`h6`, `p`, `code`) through Text, and headings tighten their tracking. GPUI 0.2.2 has no semantics and no letter-spacing, so the same metrics, weight and color render on a plain div.
ProseProse container: `text-foreground` with the children rendered in order. The per-tag descendant styles in `.typography-prose h1`, `p`, `code`, `a`, lists and friends need CSS selectors GPUI does not have, so nothing is inherited automatically.