Features
- Supports all core plugins out of the box (i.e. font size, margin, padding, width)
- Full Intellisense support
- Ensures all fluid type meets accessibility requirements
- Comes with a
fluidize
method to add fluid versions of any custom plugin - Flexible enough to handle advanced use cases
Installation
Install the package
Install
fluid-tailwind
via npm.Add the extractor
The custom extractor lets you use the new
~
prefix in your Tailwind classes.Add the fluid core plugins
Add fluid versions of every enabled core plugin.
(Optional) Use
rem
screens and font sizesIf you’re using Tailwind’s default
fontSize
andscreens
, you can convert them torem
to ensure greater compatibility with core plugins.This will be unnecessary in Tailwind v4
Basic usage
Your browser isn't wide enough to see the full effect
Here’s a quick overview:
- The
~
prefix makes a utility fluid - Fluid utilities have a start and end value, separated by a
/
- Fluid utilities interpolate between their start and end value when the viewport is between the start and end point, respectively
- The start and end points default to the smallest and largest screen, but they can be customized or overridden per-utility
Limitations
All lengths must have the same unit
Due to CSS restrictions, fluid expressions can only be computed if all involved lengths have the same unit. This includes:
- Start value / end value
- Start point / end point
Trying to interpolate between two different units
Trying to set font-size
in rem
when the screens are in px
Using expressions like calc()
Trying to interpolate between non-lengths like colors
Negative values
You can’t use the dash prefix -
to negate fluid utilities like you
can with i.e. -mt-3
, because Tailwind would only negate the start value.
Trying to use -
to negate a fluid utility
Configuration
Customizing default screens
The default start and end screens can be set with a tuple [start, end]
, where each
value is a simple screen width.
Either value can be omitted, in which case the plugin will use your smallest and largest
screen, respectively.
Advanced
Customize screens per-utility
You can change the start/end screens for an individual fluid utility with
the included ~
variant. For example:
Your browser isn't wide enough to see the full effect
You can omit either start or end screen to use your global defaults:
Set start screen to md
, end screen as default
Set end screen to lg
, start screen as default
Arbitrary start screens
If you want to set an arbitrary start screen with the ~
variant, you have to use
~min-[]
(just as you’d have to use min-[]
to set an arbitrary screen breakpoint):
Trying to use ~[]:
to set an arbitrary start screen
Using ~min-[]
to set an arbitrary start screen
Container queries
If you have the official container query plugin
installed, you can make the start/end points relative to the nearest @container
rather than the viewport by using the ~@
variant:
This may look confusing if you use named containers. Sorry about that; there’s only so many ways to get values into Tailwind. In general, when you see the fluid ~
prefix, you know the /
denotes a start/end pair.
Just like the ~
variant, both start and end containers are optional and will use your global defaults if unset.
Set end container to lg
, start container as default
Trying to reference named containers
Browser support for named containers in fluid CSS expressions should arrive soon
Customizing default containers
The default containers can be set in the same way as screens. Either value can be omitted, in which case the plugin will use your smallest and largest container, respectively.
Fluidize other plugins
When adding custom plugins to your tailwind.config.js
, you can run them through
the fluidize
function to automatically add fluid versions of all their utilities and components:
Combining with breakpoints
To really get crazy, you can combine fluid values with container or media queries, as such:
Your browser isn't wide enough to see the full effect
Here’s how this works:
- By default, we interpolate our font-size between
base
and4xl
until the viewport is ourmd
screen - When we get to our
lg
screen, we interpolate between the opposite4xl
andbase
, starting when the viewport is ourlg
screen
Custom prefix and/or separator
If you’re using a custom separator
or
prefix
in your Tailwind config,
you’ll need to pass them in to the custom extractor as well:
Use a custom prefix with fluid type