Typography

PreviousNext

A polymorphic typography component with multiple variants for consistent text styling across your application.

Installation

pnpm dlx shadcn@latest add https://ui.nowts.app/r/typography.json

Usage

The Typography component provides consistent text styling with multiple variants:

import { Typography } from "@/components/ui/typography"
 
export function MyComponent() {
  return (
    <div>
      <Typography variant="h1">Page Title</Typography>
      <Typography variant="lead">
        An introductory paragraph with larger text
      </Typography>
      <Typography variant="p">Regular paragraph text</Typography>
    </div>
  )
}

Variants

Headings

<Typography variant="h1">Heading 1</Typography>
<Typography variant="h2">Heading 2</Typography>
<Typography variant="h3">Heading 3</Typography>

Text

<Typography variant="p">Paragraph</Typography>
<Typography variant="lead">Lead text</Typography>
<Typography variant="large">Large text</Typography>
<Typography variant="small">Small text</Typography>
<Typography variant="muted">Muted text</Typography>

Special

<Typography variant="code">const code = true</Typography>
<Typography variant="quote">A memorable quote</Typography>
<Typography variant="link" as="a" href="/about">Link text</Typography>

Polymorphic

The component is polymorphic and renders the appropriate HTML element by default:

<Typography variant="h1"> {/* renders <h1> */}
<Typography variant="p">  {/* renders <p> */}
<Typography variant="link"> {/* renders <a> */}

You can override the element with the as prop:

<Typography variant="h2" as="h1">
  This is an h1 styled as h2
</Typography>
 
<Typography variant="p" as="div">
  This is a div styled as a paragraph
</Typography>

Custom Styling

Add custom classes with className:

<Typography variant="h1" className="text-blue-500">
  Blue Heading
</Typography>
 
<Typography variant="p" className="text-center">
  Centered paragraph
</Typography>

Props

PropTypeDefaultDescription
variantstring"p"Typography variant (h1, h2, h3, p, lead, large, small, muted, code, quote, link)
asElementType-Override the HTML element
classNamestring-Additional CSS classes
...propsHTMLAttributes-Standard HTML attributes

Variants Reference

VariantDefault ElementDescription
h1h1Large page heading
h2h2Section heading
h3h3Subsection heading
ppRegular paragraph
leadpIntroductory text
largepEmphasized text
smallpFine print
mutedpSecondary text
codecodeInline code
quoteblockquoteQuotation
linkaLink text