Liking cljdoc? Tell your friends :D

x-typography

A themeable text styling wrapper that applies consistent typographic styles via a variant attribute. Supports headings, body text, captions, code, keyboard shortcuts, blockquotes, and more. Includes text alignment, single-line truncation, and multi-line clamping.


Tag

<x-typography></x-typography>

Attributes

AttributeTypeDefaultDescription
variantenum"body1"Typographic variant (see Variants below)
alignenum"left"Text alignment: left center right justify
truncatebooleanfalseSingle-line ellipsis truncation
line-clampnumberMulti-line truncation (positive integer, number of lines)

Attribute values are case-insensitive (e.g. variant="H1" normalises to h1).

When both truncate and line-clamp are set, truncate takes precedence (single-line).

Invalid line-clamp values (zero, negative, non-numeric, floats) are ignored — the attribute is treated as absent.


Variants

VariantSizeWeightLine HeightLetter SpacingNotes
h12.5rem7001.2-0.02em
h22rem7001.25-0.015em
h31.75rem6001.3-0.01em
h41.5rem6001.35-0.005em
h51.25rem6001.4normal
h61.125rem6001.4normal
subtitle11.125rem5001.40.005em
subtitle20.875rem5001.40.01em
body11rem4001.5normalDefault
body20.875rem4001.5normal
caption0.75rem4001.40.02em
overline0.625rem6001.50.1emUppercase
small0.8125rem4001.4normal
blockquote1.125rem4001.6normalItalic, left border
code0.875rem4001.5Monospace, background
kbd0.875rem4001.5Monospace, background, border

Properties

PropertyTypeReflects attributeDefault
variantstringvariant"body1"
alignstringalign"left"
truncatebooleantruncatefalse
lineClampnumber | nullline-clampnull

Note: lineClamp (camelCase) maps to the line-clamp (kebab-case) HTML attribute. Reading a property before its attribute is set returns the default listed above.


Events

None.


Slots

SlotDescription
(default)Text content or child elements to style

Parts

PartDescription
containerInner <div> wrapper that receives typographic styles

CSS Custom Properties

Typography

VariableDefaultDescription
--x-typography-font-familysystem-ui, -apple-system, sans-serifBase font family
--x-typography-mono-font-familyui-monospace, "SFMono-Regular", ...Monospace font for code/kbd
--x-typography-colorinheritText color

Code variant

VariableLight defaultDark defaultDescription
--x-typography-code-bgrgba(0,0,0,0.06)rgba(255,255,255,0.1)Background
--x-typography-code-radius4pxBorder radius
--x-typography-code-padding0.15em 0.35emPadding

Kbd variant

VariableLight defaultDark defaultDescription
--x-typography-kbd-bgrgba(0,0,0,0.06)rgba(255,255,255,0.1)Background
--x-typography-kbd-borderrgba(0,0,0,0.15)rgba(255,255,255,0.2)Border color
--x-typography-kbd-radius4pxBorder radius
--x-typography-kbd-padding0.15em 0.4emPadding

Blockquote variant

VariableLight defaultDark defaultDescription
--x-typography-blockquote-border-colorrgba(0,0,0,0.2)rgba(255,255,255,0.25)Left border
--x-typography-blockquote-padding0 0 0 1emPadding

Accessibility

This component is purely presentational. It does not add ARIA roles, landmarks, or keyboard behavior. For semantic document structure, use native HTML heading elements (<h1><h6>), <p>, <blockquote>, <code>, etc. alongside or instead of this component.


Examples

Basic variants

<x-typography variant="h1">Main Heading</x-typography>
<x-typography variant="body1">Body text paragraph.</x-typography>
<x-typography variant="caption">A small caption.</x-typography>
<x-typography variant="overline">Overline label</x-typography>

Alignment

<x-typography variant="body1" align="center">Centred text</x-typography>
<x-typography variant="body1" align="right">Right-aligned</x-typography>

Truncation

<x-typography variant="body1" truncate>
  This very long text will be truncated with an ellipsis on a single line.
</x-typography>

Line clamping

<x-typography variant="body1" line-clamp="3">
  This multi-line text will be clamped to three visible lines.
  Any overflow beyond the third line is hidden with an ellipsis.
</x-typography>

Code and Kbd

<x-typography variant="code">const x = 42;</x-typography>
<x-typography variant="kbd">Ctrl + C</x-typography>

Blockquote

<x-typography variant="blockquote">
  The only way to do great work is to love what you do.
</x-typography>

Programmatic (JavaScript)

const el = document.createElement('x-typography');
el.variant = 'h2';
el.align = 'center';
el.textContent = 'Dynamic heading';
document.body.appendChild(el);

ClojureScript / hiccup

[:x-typography {:variant "h1"} "Page Title"]
[:x-typography {:variant "body1" :truncate true} "Long text..."]
[:x-typography {:variant "body1" :line-clamp "3"} "Multi-line clamped text..."]
[:x-typography {:variant "code"} "(defn hello [] \"world\")"]

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close