text-2xl md:text-4xl or regular CSS, with no new syntax and no config. Whenever two breakpoints set a value, the value grows smoothly between them. Browsers that don’t support CSS @functions stay as they are.$ npm install -D postcss-autofluid
Prompt: Add postcss-autofluid to this project. Install it as a dev dependency with npm install -D postcss-autofluid, then add 'postcss-autofluid': {} to the plugins in postcss.config.js, after Tailwind. If the project uses @tailwindcss/vite, create postcss.config.js with just this plugin. Don't change any markup or classes.
<main class="flex flex-col gap-5 lg:gap-12 p-5 pb-8 lg:p-14 lg:pb-24">
<div class="grid grid-cols-2 h-[220px] lg:h-[440px] gap-1 lg:gap-5">
<img src="cabin.jpg" alt="" class="size-full rounded-xl lg:rounded-[20px] object-cover">
<img src="cabin-2.jpg" alt="" class="size-full rounded-xl lg:rounded-[20px] object-cover">
</div>
<div class="grid grid-cols-[1fr_auto] gap-x-4 lg:gap-x-10">
<p class="col-span-2 text-xs md:text-base xl:text-lg font-bold uppercase tracking-wider text-zinc-500 mb-2 lg:mb-5">
2 bedrooms
</p>
<h1 class="text-[32px] md:text-[48px] xl:text-[72px] font-semibold tracking-tighter text-balance leading-none">
A log cabin deep in the snowy pines
</h1>
<a href="#book" class="inline-flex items-center text-sm md:text-xl xl:text-[26px] gap-[.55em] rounded-full bg-zinc-900 font-medium text-white transition-colors hover:bg-zinc-700 px-4 lg:px-9 xl:px-12 py-2 lg:py-5 xl:py-6">
<svg class="size-[1.15em]" …><!-- calendar --></svg> Book
</a>
<p class="col-span-2 flex mt-3 lg:mt-7 text-sm md:text-xl xl:text-2xl text-zinc-900 tabular-nums divide-x *:px-[.9em] first:*:pl-0">
<span class="inline-flex items-center gap-[.4em]"><svg class="size-[1.05em]" …><!-- star --></svg> <b class="font-semibold">4.92</b> (62)</span>
<span class="inline-flex items-center gap-[.4em]"><svg class="size-[1.05em]" …><!-- pin --></svg> Pallas, Lapland</span>
</p>
<p class="col-span-2 mt-3 lg:mt-7 text-base md:text-[19px] xl:text-2xl text-pretty text-zinc-500 max-w-[32em]">
Wood stove, a loft under the dormer windows and a deck that looks
into the forest. Mornings are quiet enough to hear snow slide off
the roof, and evenings end in the sauna, ten steps from the back
door. Ski trails start at the gate; the village is a short walk. Two
nights minimum.
</p>
</div>
</main>
/* Tailwind's output for the h1 and main, unchanged */.p-5 { padding: calc(var(--spacing) * 5) }.text-\[32px\] { font-size: 32px }@media (width >= 48rem) { .md\:text-\[48px\] { font-size: 48px }}@media (width >= 64rem) { .lg\:p-14 { padding: calc(var(--spacing) * 14) }}@media (width >= 80rem) { .xl\:text-\[72px\] { font-size: 72px }} /* Appended by postcss-autofluid */@supports (top: --fl()) { @function --fl(--v0, --v48rem, --v64rem, --v80rem) { /* one shared interpolator */ } @function --fl-font-size() { result: --fl(var(--fl-font-size-0), var(--fl-font-size-48rem), var(--fl-font-size-80rem)); } @function --fl-padding() { result: --fl(var(--fl-padding-0), var(--fl-padding-64rem)); } @layer utilities { .p-5 { --fl-padding-0: calc(var(--spacing) * 5); padding: --fl-padding() } .lg\:p-14 { --fl-padding-64rem: calc(var(--spacing) * 14) } .text-\[32px\] { --fl-font-size-0: 32px; font-size: --fl-font-size() } .md\:text-\[48px\] { --fl-font-size-48rem: 48px } .xl\:text-\[72px\] { --fl-font-size-80rem: 72px } @media (width >= 48rem) { .md\:text-\[48px\] { font-size: --fl-font-size() } } @media (width >= 64rem) { .lg\:p-14 { padding: --fl-padding() } } @media (width >= 80rem) { .xl\:text-\[72px\] { font-size: --fl-font-size() } } }}
Type and spacing in px, rem and em: margins, paddings, gaps and insets, font-size, line-height, letter-spacing, border radii, widths and heights. By default, only those in the utilities layer. The fluid styles add about 15% more CSS after compression.
Percentages, viewport units, transforms, opacity.
These are normally used as layout states, and smoothing them would break it. Each group can be opted in. To keep a single value stepped, mark it important, like md:mt-8!, or list the whole property in exclude.
Everything the plugin generates sits behind @supports. Chromium 139+ gets fluid sizing. Unsupported browsers get your original styles, untouched.
All optional. The defaults already cover type and spacing, so most projects don’t need these. Every option is explained in the README.md.
// postcss.config.js
export default {
plugins: {
'@tailwindcss/postcss': {},
'postcss-autofluid': {
prefix: 'fl', // token and function names: `--fl-<name>-<bp>`, `--fl_<hash>()`
minWidth: '20rem', // viewport where the base (unprefixed) value sits; a number is px
containerMinWidth: …, // container width where the base value sits for `@md:` and friends; defaults to `minWidth`
include: [], // opt-in groups like `percentages` or `transforms`; `all` for every group
properties: [...], // replaces the default type-and-spacing list (see `lib/options.js`)
exclude: [], // properties to leave out
layers: ['utilities'], // layer names to read; `null`: every rule; `auto`: `utilities` if present, else all
},
},
}
Keep @tailwindcss/vite and add a postcss.config.js with the plugin. Don’t switch the CSS transformer to Lightning CSS.
// postcss.config.js
// vite.config.js keeps tailwindcss()
export default {
plugins: {
'postcss-autofluid': {}, },
}
List it after @tailwindcss/postcss, because it reads Tailwind’s output. Works with the defaults.
// postcss.config.js
export default {
plugins: {
'@tailwindcss/postcss': {},
'postcss-autofluid': {}, },
}
For postcss-loader in Webpack, Laravel Mix and Gulp. Same rule: after Tailwind.
// postcss.config.js
module.exports = {
plugins: [
require('@tailwindcss/postcss'),
require('postcss-autofluid'), ],
}