Skip to Content
CodeUI

Typography and spacing

@codeui/solid v0.3.0

The type scale and the spacing scale the components use.

Interface text is small and steady. Most of a screen is 12 to 14px, and nothing is smaller than 11px. Spacing sits on a 4px grid with 2px half steps.

badgePNG
xsExported 2 minutes ago
captionPadding around your code
smExport snippet
mdAppearance
lgWhat's new
xlWhat's new
2xlWhat's new
typography-and-spacing/type-scale.tsx
import { Stack, Text } from "@codeui/solid";
import { For } from "solid-js";

const steps = [
	{ size: "badge", weight: "medium", sample: "PNG" },
	{ size: "xs", weight: "normal", sample: "Exported 2 minutes ago" },
	{ size: "caption", weight: "normal", sample: "Padding around your code" },
	{ size: "sm", weight: "medium", sample: "Export snippet" },
	{ size: "md", weight: "semibold", sample: "Appearance" },
	{ size: "lg", weight: "semibold", sample: "What's new" },
	{ size: "xl", weight: "semibold", sample: "What's new" },
	{ size: "2xl", weight: "semibold", sample: "What's new" },
] as const;

export default function TypeScale() {
	return (
		<Stack gap="3" style={{ width: "100%", "max-width": "420px" }}>
			<For each={steps}>
				{step => (
					<Stack direction="row" gap="4" align="baseline">
						<Text size="xs" tone="hint" style={{ width: "64px", "flex-shrink": 0 }}>
							{step.size}
						</Text>
						<Text size={step.size} weight={step.weight}>
							{step.sample}
						</Text>
					</Stack>
				)}
			</For>
		</Stack>
	);
}

Font sizes

Text takes size, and its type is keyof typeof tokens.font.size. Each size maps to one token.

sizeTokenValueInkstone stepUse
badge--cui-font-size-badge11pxMicroBadge, tag, keycap. One word.
xs--cui-font-size-xs12pxMetaDescription, summary, group label.
caption--cui-font-size-caption13pxBaseRunning text, row labels inside a section.
sm--cui-font-size-sm14pxLabelRow title, menu item, button, section header. The Text default.
md--cui-font-size-md16pxTitleGroup title. Phone inputs, so iOS does not zoom.
lg--cui-font-size-lg18pxDisplaySheet titles and announcements only.
xl--cui-font-size-xl20pxDisplaySheet titles and announcements only.
2xl--cui-font-size-2xl24pxDisplaySheet titles and announcements only.

11px is the floor. Do not set interface text smaller, even in a dense table. The reasons and the line height for each step are in Typography.

Text sets line-height: var(--cui-font-line-height-normal), which is 1.5. --cui-font-line-height-compact is 1.15. Kbd uses it for keycaps. Each size step has a matching line height: --cui-font-line-height-badge (1.2), -xs (1.4), -caption (1.5), -sm (1.3) and -md (1.3). Form controls set these on their text parts instead of inheriting the page's leading.

Weights and tones

WindowShow line numbersLine numbers start at 1 and use tabular figures.The snippet name is required.
typography-and-spacing/weights-and-tones.tsx
import { Stack, Text } from "@codeui/solid";

export default function WeightsAndTones() {
	return (
		<Stack gap="1" style={{ width: "100%", "max-width": "360px" }}>
			<Text size="sm" weight="semibold">
				Window
			</Text>
			<Text size="sm" weight="medium">
				Show line numbers
			</Text>
			<Text size="xs" tone="muted">
				Line numbers start at 1 and use tabular figures.
			</Text>
			<Text size="xs" tone="danger">
				The snippet name is required.
			</Text>
		</Stack>
	);
}

Text takes weight, and its type is keyof typeof tokens.font.weight.

weightTokenValueUse
normal--cui-font-weight-normal400Text you read. The default.
medium--cui-font-weight-medium500Text you act on, such as a label or a button.
semibold--cui-font-weight-semibold600Headings.

The kit has no other weights. Hierarchy comes from tone first, then weight, then size. Most text is the muted tone.

tone takes default, muted, hint, label, danger and success. Each reads the --cui-text-* token of the same name, except success. See Text.

Font families

TokenValue
--cui-font-family-sans"Inter var", system-ui, -apple-system, sans-serif
--cui-font-family-monoui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace

The kit does not load font files. To get Inter, load it in your app, or set --cui-font-family-sans to your own font. Use the mono family only for code, file paths and hex values.

The spacing scale

0.5
1
1.5
2
3
4
6
8
typography-and-spacing/gap-scale.tsx
import { Stack, Text, type Gap } from "@codeui/solid";
import { For } from "solid-js";

const gaps: Gap[] = ["0.5", "1", "1.5", "2", "3", "4", "6", "8"];

const chip = {
	width: "28px",
	height: "28px",
	"border-radius": "var(--cui-radius-nav)",
	background: "var(--cui-surface-input)",
} as const;

export default function GapScale() {
	return (
		<Stack gap="3">
			<For each={gaps}>
				{gap => (
					<Stack direction="row" gap="4" align="center">
						<Text size="xs" tone="hint" style={{ width: "40px" }}>
							{gap}
						</Text>
						<Stack direction="row" gap={gap}>
							<span style={chip} />
							<span style={chip} />
							<span style={chip} />
						</Stack>
					</Stack>
				)}
			</For>
		</Stack>
	);
}

Each row is a Stack with a different gap. Gap is the type of that prop, and each value maps to a --cui-space-* token.

GapTokenValue
px--cui-space-px1px
0--cui-space-00
0.5--cui-space-0-52px
1--cui-space-10.25rem (4px)
1.5--cui-space-1-56px
2--cui-space-20.5rem (8px). The Stack default.
3--cui-space-30.75rem (12px)
4--cui-space-41rem (16px)
6--cui-space-61.5rem (24px)
8--cui-space-82rem (32px)
10--cui-space-102.5rem (40px)
12--cui-space-123rem (48px)
16 to 64--cui-space-16 to --cui-space-644rem to 16rem

The pixel values assume a 16px root font size. Three tokens have no Gap value: --cui-space-2-5 (10px), --cui-space-5 (1.25rem) and --cui-space-auto. Use them in CSS. Tokens lists every step.

Inkstone uses 2 · 4 · 6 · 8 · 12 · 16 · 24 · 32 for almost everything. Keep 10px for the inside of compact controls. Space inside a group is smaller than the space between groups. See Space and shape.

Control heights

Fields, buttons and other controls with a size prop take their height from --cui-control-height-*.

sizeTokenValue
xs--cui-control-height-xs28px
sm--cui-control-height-sm36px
md--cui-control-height-md44px
lg--cui-control-height-lg52px

The table shows comfortable density. Controls default to sm. Comfortable is the default density. Compact multiplies heights by 0.875, and touch multiplies them by 1.125. Heights round to the nearest 2px. A coarse pointer selects touch density automatically. Set data-cui-density="compact|comfortable|touch" on an element to set density for its subtree. Font sizes stay tied to the control size.

On this page