Skip to main content

Responsive Typography with CSS clamp()

This page demonstrates the fluid typography system using CSS clamp(). Resize your browser window to see how text scales smoothly between mobile and desktop sizes.

Display Text

XL Display (3.5rem to 8rem)

VectorAlpha

Display (3rem to 6rem)

Performance

Heading Hierarchy

H1 (2.5rem to 4.5rem)

Main Page Heading

H2 (2rem to 3rem)

Section Heading

H3 (1.5rem to 2.25rem)

Subsection Heading

H4 (1.25rem to 1.875rem)

Minor Heading

Body Text Sizes

Lead Text (1.125rem to 1.5rem)

This is lead text that scales smoothly from mobile to desktop viewports using CSS clamp().

Large Text (1.125rem to 1.25rem)

Large body text provides subtle scaling for improved readability on larger screens.

Base Text (1rem to 1.125rem)

Base body text scales slightly to maintain optimal reading comfort across devices.

Small Text (0.875rem to 0.9375rem)

Small text maintains legibility with minimal scaling for consistency.

Responsive Components

Buttons

Cards

Responsive Card

Card padding scales with viewport size for optimal spacing.

Large Card

Enhanced padding that scales more dramatically with viewport.

Responsive Gaps

Implementation Details

The responsive typography system uses CSS clamp() to create fluid scaling between minimum and maximum values. This eliminates the need for multiple breakpoint-specific classes.

Example Syntax

/* H1 scales from 40px to 72px */
h1 {
  font-size: clamp(2.5rem, 2rem + 2.5vw, 4.5rem);
}

/* Responsive padding */
.section {
  padding-top: clamp(4rem, 3rem + 5vw, 8rem);
}

Benefits

  • Smooth scaling without breakpoints
  • Better performance (no media query overhead)
  • Consistent proportions across all viewport sizes
  • Reduced CSS complexity

Browser Support

CSS clamp() is supported in all modern browsers. For older browsers, the styles fall back to the minimum value.