Skip to content

Typography

Data Display

Semantic text elements with consistent visual roles.

HeadingLeadBodyMuted and smallCode and quotation
Open preview

Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.

Usage

Choose as for document semantics and variant for appearance. Keep heading levels logical; a visual heading variant does not choose a heading level for you. Use code for inline code and blockquote for quotations.

Import
import { Typography } from "@/components/ui/typography";

Shipped as editable source in src/components/ui/typography.tsx in both apps. Copy the implementation below when moving it to another project. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.

Component source

The complete implementation is included in both apps. It uses the React, Radix, Lucide, and shared-core dependencies already installed in Apex. Keep your project’s semantic theme tokens when reusing it.

src/components/ui/typography.tsx
import type { HTMLAttributes } from "react";
import { cn } from "@dashboardpack/core/lib/utils";
const styles = {
  default: "text-sm leading-relaxed",
  lead: "text-lg leading-relaxed text-muted-foreground",
  muted: "text-sm text-muted-foreground",
  small: "text-xs leading-relaxed",
  code: "rounded bg-muted px-1.5 py-0.5 font-mono text-xs",
  heading: "text-2xl font-semibold tracking-tight",
};
export function Typography({
  as: Tag = "p",
  variant = "default",
  className,
  ...props
}: HTMLAttributes<HTMLElement> & {
  as?: "p" | "h2" | "h3" | "h4" | "span" | "code" | "blockquote";
  variant?: keyof typeof styles;
}) {
  return (
    <Tag
      className={cn(
        styles[variant],
        Tag === "blockquote" && "border-s-2 ps-4 italic",
        className,
      )}
      {...props}
    />
  );
}

API reference

Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.

Typography props
PropType / DefaultDescription
asp | h2 | h3 | h4 | span | code | blockquote

Default: p

Semantic element.
variantdefault | lead | muted | small | code | heading

Default: default

Visual treatment.
childrenReactNode

Default: —

Text or appropriate inline content.
classNamestring

Default: —

Extend text styles.

Build with these too