Skip to content

Build UI / Typography / Text

Text ​

The general-purpose type element: size, weight, color, family, line height and alignment are all attributes mapped to design tokens. It carries no document semantics — it is not a heading, a paragraph or a list, even when styled like one.

preview
Code
html
<kb-stack direction="column" spacing="nano" align="start">
  <kb-text size="lg" weight="bold">Monthly summary</kb-text>
  <kb-text size="xs">Everything that happened in your account this month.</kb-text>
  <kb-text size="xxxs" color="master">Updated 2 minutes ago</kb-text>
</kb-stack>

Usage ​

html
<kb-text size="xs" color="master-dark" weight="regular">Hello world</kb-text>

When to use ​

  • Body copy and inline text anywhere, when it should follow the type scale rather than the browser's defaults.
  • A visual heading inside a component — a card title, a section title — where size and weight matter and the document outline doesn't.
  • Text that shifts by token — a muted caption, a bold total — without writing CSS per instance.

When not to use ​

  • A document heading. A screen reader's heading navigation needs a real <h1>–<h6>. Use one and style it, or nest a kb-text inside it.
  • A field label or hint — <kb-label> and <kb-helper> exist so the form vocabulary stays uniform and self-slotting.
  • Long-form prose with multiple paragraphs — this renders one inline box with no paragraph spacing; use real <p> elements inside a <kb-stack>.

Composition ​

  • Can contain: text and inline markup — the shadow root is a single unnamed <slot>. Nested <a>, <strong> or a <kb-icon> inherit the color and size set here. One or more <kb-on> children add arcs beyond the single on attribute.
  • Can be a child of: anything. The host has no display of its own, so it behaves as inline content and participates in whatever flex or grid context surrounds it.
preview
Code
html
<kb-text size="xs">
  Read the <a href="#/learn/quick-start">quick start</a> to see it working.
</kb-text>

Size ​

size steps the shared type scale. Pick by role, not by how large it looks in one layout.

preview
Code
html
<kb-stack direction="column" spacing="quarck" align="start">
  <kb-text size="xxxs">xxxs — captions, metadata</kb-text>
  <kb-text size="xxs">xxs — the default</kb-text>
  <kb-text size="xs">xs — body copy</kb-text>
  <kb-text size="md">md — component titles</kb-text>
  <kb-text size="xl">xl — page titles</kb-text>
</kb-stack>
sizeRenders atUse for
xxxs / xxs12 / 14pxCaptions, metadata, dense cells. xxs is the default.
xs / sm16 / 20pxBody copy and lead paragraphs.
md / lg24 / 32pxComponent and section titles.
xl–xxxl40–64pxPage titles.
display / giant80 / 96pxMarketing headlines only — these break small screens.

weight has three steps (regular, medium, bold) and line-height runs default (100%) through xxl (200%). Tighter line heights suit large display type; body copy wants lg or xl.

Color ​

color accepts any suffix of --color-* as a closed keyword set. Use the semantic families for meaning, the neutral master-* ramp for hierarchy.

preview
Code
html
<kb-stack direction="column" spacing="quarck" align="start">
  <kb-text color="master-dark">master-dark — body text</kb-text>
  <kb-text color="master">master — secondary</kb-text>
  <kb-text color="primary">primary — brand emphasis</kb-text>
  <kb-text color="success">success — positive outcome</kb-text>
  <kb-text color="danger">danger — error or destructive</kb-text>
</kb-stack>

A keyword outside the set is ignored: the attribute change never reaches the property, which keeps its last valid value (master-dark until you set one) — check the token name if a color "doesn't apply". The same holds for size, weight, family, line-height and align.

Attributes ​

AttributeTypeDefaultDescription
sizetoken stepxxsType size, resolved against --font-size-{value}.
weightregular | medium | boldregularResolved against --font-weight-{value}.
colortoken suffixmaster-darkResolved against --color-{value}.
familybase | highlightbaseResolved against --font-family-{value}.
line-heighttoken steplgResolved against --line-height-{value}.
alignleft | center | right | justifyleftText alignment.
onarc string—Echo wiring, source/event:type/sink — lets another element drive an attribute of this text.

This element dispatches no events; on only ever receives.

Styling ​

The attributes cover per-instance cases. The --text-* properties exist for the surface-level override — a whole panel shifting its type — and for values the scale doesn't express, like tracking.

Custom propertyDefaultControls
--text-colorvar(--color-{color})Color, overriding the attribute.
--text-font-familyvar(--font-family-{family})Type family.
--text-font-sizevar(--font-size-{size})Type size.
--text-font-weightvar(--font-weight-{weight})Type weight.
--text-line-heightvar(--line-height-{lineHeight})Line height.
--text-letter-spacing0.38pxTracking — the one value with no attribute.

Prefer the attribute for one element; reach for the property when a rule should apply to many:

css
.panel-dark kb-text {
  --text-color: var(--color-pure-white);
}

States and accessibility ​

  • The element exposes no role. Styling it at display size does not make it a heading — pair it with a real heading element, or role="heading" plus aria-level, when it introduces a section.
  • Watch contrast moving down the master-* ramp: master-light on white is decorative-grade, not body-text grade.
  • Don't let color be the only carrier of meaning — a danger-colored total needs words that say what's wrong.
  • align="justify" produces uneven word spacing in narrow columns; keep it for wide measures.

Do's and don'ts ​

DoDon't
Pick size by the role of the textPick it by how big it looks in one layout
Wrap or nest a real heading element for structureUse size="xxxl" and call it a heading
Use <kb-label> / <kb-helper> inside form fieldsRecreate them with kb-text and per-instance attributes
Set --text-* on an ancestor to shift a whole surfaceRepeat the same attribute override on every element