npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

postcss-size-clamp

v3.3.2

Published

PostCSS plugin for fluid typography using modern CSS clamp()

Readme

PostCSS Size Clamp

A PostCSS plugin that generates fluid values using modern CSS clamp() calculations.

NPM Version NPM Downloads License: MIT PostCSS Known Vulnerabilities Tests Bundle Size GitHub stars

This plugin was inspired by the excellent postcss-responsive-type. While it started as a typography solution, it has evolved into a comprehensive fluid value generator for any CSS property.

Unlike similar plugins, this plugin:

  • Outputs a single line of CSS using clamp() instead of multiple media/container queries
  • Pre-calculates values for optimized browser rendering
  • Supports container query units (cqw, cqi, cqb)
  • Supports custom container widths via CSS custom properties
  • Works with any CSS property that accepts pixel values
  • Includes property blacklisting for granular control
  • Preserves the !important flag

Installation

npm install postcss-size-clamp --save-dev

Usage

// postcss.config.js
module.exports = {
	plugins: [
		require('postcss-size-clamp')({
			range: [420, 1620],     // default viewport/container range
			unit: 'cqw',            // default unit (vw, cqw, cqi, cqb, %)
			blacklist: [            // properties to ignore
				'container-name',
				'grid-template-areas',
				'grid-template',
				'grid-area',
				'content',
				'list-style',
				'transition',
				'animation',
				'transform',
				'display'
			]
		}),
		require('postcss-preset-env'),
	],
};

Basic Usage

.element {
	font-size: responsive 16px 32px;
	margin-block: responsive 20px 40px;
	padding-inline: responsive 16px 32px;
	gap: responsive 16px 32px;
}

/* Typography shorthand with line-height */
.element {
	font-size: responsive 16px 32px / 1.5;  /* Sets both font-size and line-height */
}

/* Using !important flag */
.element {
	font-size: responsive 16px 32px !important;
	/* or with line-height */
	font-size: responsive 16px 32px / 1.5 !important;
}

Outputs:

.element {
	font-size: clamp(16px, calc(10.4px + 1.33333cqw), 32px);
	margin-block: clamp(20px, calc(14.4px + 1.33333cqw), 40px);
	padding-inline: clamp(16px, calc(10.4px + 1.33333cqw), 32px);
	gap: clamp(16px, calc(10.4px + 1.33333cqw), 32px);
}

.element {
	font-size: clamp(16px, calc(10.4px + 1.33333cqw), 32px);
	line-height: 1.5;
}

.element {
	font-size: clamp(16px, calc(10.4px + 1.33333cqw), 32px) !important;
	/* or with line-height */
	font-size: clamp(16px, calc(10.4px + 1.33333cqw), 32px) !important;
	line-height: 1.5 !important;
}

Understanding Fluid Values

The syntax responsive <min>px <max>px creates a fluid value that scales between two sizes based on the viewport or container width:

.example {
	/* At 420px viewport: font-size = 16px
	   At 1620px viewport: font-size = 32px
	   Between: scales proportionally */
	font-size: responsive 16px 32px;
}

The default range (420px to 1620px) determines when the value starts and stops scaling. Below 420px it stays at 16px, above 1620px it stays at 32px, and between these values it scales fluidly.

Custom Range and Units

.element {
	margin: responsive 20px 48px;
	width: responsive 280px 560px;
	fluid-range: 768px 1920px;
	fluid-unit: vw;
}

Outputs:

.element {
	margin: clamp(20px, calc(1.33333px + 2.43056vw), 48px);
	width: clamp(280px, calc(183.33px + 19.44444vw), 560px);
}

Custom Container Widths

You can use CSS custom properties to define specific container widths for fluid scaling:

/* Define container widths */
:root {
    --sidebar-width: 0.25; /* 25% of viewport width */
    --main-content: 0.75;  /* 75% of viewport width */
}

/* Use in your components */
.sidebar {
    fluid-unit: --sidebar-width;
    padding: responsive 10px 20px;
}

.main-content {
    fluid-unit: --main-content;
    font-size: responsive 16px 24px;
}

Outputs:

.sidebar {
    padding: clamp(10px, calc(10px + (20 - 10) * (var(--sidebar-width) - 420px) / (1620 - 420))), 20px);
}

.main-content {
    font-size: clamp(16px, calc(16px + (24 - 16) * (var(--main-content) - 420px) / (1620 - 420))), 24px);
}

Features

Global Configuration Set default ranges and units in your PostCSS config:

require('postcss-size-clamp')({
	range: [420, 1620],     // min and max viewport/container width
	unit: 'cqw',            // viewport or container query unit
	blacklist: ['container-name'] // properties to ignore
});

Supported Units

  • vw: Viewport width
  • cqw: Container query width
  • cqi: Container query inline size
  • cqb: Container query block size
  • %: Percentage of the width
  • --*: Custom property (must start with '--' and contain a decimal value between 0 and 1)

Per-Declaration Overrides Override global settings using fluid-range and fluid-unit properties:

.custom {
	padding: responsive 16px 32px;
	fluid-range: 320px 1440px;
	fluid-unit: cqi;
}

Property Blacklist Some properties might not work well with fluid values or could cause issues. These can be blacklisted globally:

require('postcss-size-clamp')({
	blacklist: [
		'container-name',  // Container queries
		'display',        // Non-numeric properties
		'position',       // Non-numeric properties
		'grid-template',  // Complex values
		'transform'       // Complex values
	]
});

Browser Support

While clamp() has excellent browser support, we recommend using this plugin with postcss-preset-env for maximum compatibility. Place this plugin before postcss-preset-env in your PostCSS config to take advantage of its browser compatibility features.

Performance

This plugin pre-calculates numerical values where possible, resulting in optimized CSS output. Instead of multiple media queries or complex calculations, it generates a single, efficient line of CSS that browsers can process quickly.

License

MIT