Theme & Front End CSS Beginner

Fluid Heading Sizes With clamp()

Make headings scale smoothly between a minimum size on phones and a maximum on large screens, with no breakpoints.

Tested on WordPress 7.1 No plugin needed Updated
style.css 14 lines
h1 {
	font-size: clamp(2rem, 1.4rem + 3vw, 3.5rem);
	line-height: 1.1;
}

h2 {
	font-size: clamp(1.6rem, 1.2rem + 2vw, 2.5rem);
	line-height: 1.15;
}

h3 {
	font-size: clamp(1.3rem, 1.1rem + 1vw, 1.75rem);
	line-height: 1.25;
}

Where to add this

Recommended Additional CSS Appearance → Customize → Additional CSS, or your page builder's global CSS.
Child theme At the end of your child theme's style.css file.
A code snippets plugin As a CSS snippet set to load on the front end.

Headings that look right on a laptop are often huge on phones, and themes fix that with a few fixed breakpoints. clamp() scales them smoothly with the screen width instead.

How it works

clamp(min, preferred, max) uses the preferred value but never goes below the minimum or above the maximum. The preferred value mixes a fixed rem part with a vw part, so the size grows with the window, and the rem part keeps it responding to the visitor’s browser text size.

Things to watch

  • Your theme may set heading sizes with more specific selectors, such as .entry-content h2. Match its selectors if these rules don’t take effect.
  • Block themes set fluid sizes in theme.json. Adjust them in the Site Editor’s Typography settings instead.

How to test it

Open a post and slowly narrow the browser window. Headings should shrink smoothly rather than jumping at certain widths.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only