Fluid
The fluid preset is enabled by default. Classes use the fluid- prefix, pixel values, and a viewport range of 320px to 1920px.
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.
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.
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):
| Class | Effect |
|---|---|
fluid-pt-32/64 | Shortcut for min 32 and max 64 |
fluid-pt | Apply the clamp using current min/max custom properties |
fluid-pt-min-32 | Set the minimum size |
fluid-pt-max-64 | Set the maximum size |
fluid-pt-min-container-480 | Start scaling at container width 480 |
fluid-pt-max-container-1440 | Stop scaling at container width 1440 |
fluid-pt-base-rem | Use 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).
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.
| Name | Min | Max |
|---|---|---|
2xs | 8 | 12 |
xs | 12 | 16 |
sm | 16 | 24 |
md | 24 | 32 |
lg | 32 | 48 |
xl | 48 | 72 |
2xl | 72 | 96 |
3xl | 96 | 128 |
4xl | 128 | 144 |
5xl | 144 | 200 |
Font size (fluid-text-{name})
| Name | Min | Max |
|---|---|---|
3xs | 9 | 11 |
2xs | 10 | 12 |
xs | 12 | 14 |
sm | 14 | 16 |
md | 16 | 16 |
lg | 16 | 18 |
xl | 18 | 22 |
2xl | 22 | 26 |
3xl | 26 | 32 |
4xl | 32 | 44 |
Radius (fluid-rounded-{name})
| Name | Min | Max |
|---|---|---|
xs | 2 | 4 |
sm | 4 | 6 |
md | 6 | 8 |
lg | 8 | 12 |
xl | 12 | 16 |
2xl | 16 | 24 |
See examples for live previews.