Fluid

Scale type, spacing, and layout fluidly between a minimum and maximum viewport without breakpoints.

The fluid preset is enabled by default. Classes use the fluid- prefix, pixel values, and a viewport range of 320px to 1920px.

uno.config.ts
import { presetVinicunca } from '@vinicunca/unocss-preset';
import { defineConfig } from 'unocss';

export default defineConfig({
  presets: [presetVinicunca()]
});

Set both endpoints with a slash, or use the three explicit classes:

<div class="fluid-w-100/200">...</div>
<div class="fluid-w fluid-w-min-100 fluid-w-max-200">...</div>

The computed size is clamp(min, fluid, max): 100px at or below 320px viewport width, a linear interpolation in between, and 200px at or above 1920px. The container reference is 100vw unless you switch it to container query width.

The in-package src/presets/fluid/README.md still shows an f- prefix. The runtime default is fluid-. Override it with fluid: { prefix: 'f-' } if you want the short form.

Options

Pass a fluid object to change defaults. See Options for the full list.

uno.config.ts
presetVinicunca({
  fluid: {
    minContainerWidth: 320,
    maxContainerWidth: 1920,
    defaultBaseUnit: 'px',
    prefix: 'fluid-'
  }
});

defaultBaseUnit: 'rem' makes fluid-w-1/2 scale from 1rem to 2rem. fluid-w-base-rem changes the unit for that utility only.

Add a CSS property that is not built in:

presetVinicunca({
  fluid: {
    utilities: [['stroke', ['stroke-width']]]
  }
});

Then fluid-stroke-1/3 scales stroke-width from 1px to 3px.

Modifiers

For a utility fluid-pt (or any name in the utilities list):

ClassEffect
fluid-pt-32/64Shortcut for min 32 and max 64
fluid-ptApply the clamp using current min/max custom properties
fluid-pt-min-32Set the minimum size
fluid-pt-max-64Set the maximum size
fluid-pt-min-container-480Start scaling at container width 480
fluid-pt-max-container-1440Stop scaling at container width 1440
fluid-pt-base-remUse 1rem as the unit for this utility

Container query width

fluid-$<name>-container sets the container reference to 100cqw instead of 100vw. Variable names can only contain letters:

<div class="fluid-$px-24/32 fluid-$px-container">...</div>

CSS variables

$ stores the clamp on a custom property --fluid-<name>. When <name> matches a built-in utility (px, mt, text, …), the preset also applies that variable to the matching CSS properties:

<div class="fluid-$px-24/32"></div>
<div class="fluid-$mt-16/24"></div>
<div class="fluid-$myvar-8/12"></div>

Use a custom variable in your own CSS: --other: calc(var(--fluid-myvar) * 1.5).

Variable names can only contain letters. fluid-$myvar works; fluid-$my-var does not.

Theme shortcuts

Named sizes generate shortcuts such as fluid-p-lg → fluid-p-32/48. Set disableTheme: true or themeShortcuts: false to turn them off.

Spacing (fluid-{utility}-{name})

Applies to every utility except text and rounded.

NameMinMax
2xs812
xs1216
sm1624
md2432
lg3248
xl4872
2xl7296
3xl96128
4xl128144
5xl144200

Font size (fluid-text-{name})

NameMinMax
3xs911
2xs1012
xs1214
sm1416
md1616
lg1618
xl1822
2xl2226
3xl2632
4xl3244

Radius (fluid-rounded-{name})

NameMinMax
xs24
sm46
md68
lg812
xl1216
2xl1624

See examples for live previews.