Overview
Tailwind v4 extends through CSS first: @utility defines utilities, @custom-variant defines variants, and @theme defines tokens. @plugin still exists to load JavaScript plugins, including the official typography and forms plugins. The hub is tailwind.
Load official plugins with @plugin
Install the package, then declare it after the import.
@import "tailwindcss";
@plugin "@tailwindcss/typography";
@plugin "@tailwindcss/forms";- Typography adds
prosefor HTML you do not control (Markdown, CMS output). Usedark:prose-invertfor dark mode,max-w-noneto remove the built-in max width, andnot-proseto opt a subtree out. - Forms resets form controls to a baseline that utilities can override.
Customize prose colors by defining a theme as a utility:
@utility prose-brand {
--tw-prose-body: var(--color-ink);
--tw-prose-headings: var(--color-ink);
--tw-prose-links: var(--color-brand);
}Then write class="prose prose-brand".
Define custom utilities with @utility
Use @utility, not @layer utilities, so the class works with variants such as hover: and lg:.
@utility scrollbar-hidden {
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
@utility tab-* {
tab-size: --value(--tab-size-*);
}The second form is a functional utility that reads theme values. Keep multi-rule component classes in @layer components.
Define custom variants with @custom-variant
@custom-variant hocus (&:is(:hover, :focus-visible));
@custom-variant theme-midnight (&:where([data-theme="midnight"] *));hocus:text-brand then applies on hover or keyboard focus. Variants such as rtl: and print: already exist; do not redefine them.
Share extensions as CSS
Put @theme, @utility, and @custom-variant blocks in a CSS file and import it from each project: @import "../brand/theme.css";. Use @plugin only for packages that need JavaScript.
Skip plugins that v4 made redundant
- Container queries (
@container,@md:) are built in; see tailwind-responsive. Do not install@tailwindcss/container-queries. line-clamp-*andaspect-*are core utilities; the separate line-clamp and aspect-ratio plugins are unnecessary.theme(spacing.12)is deprecated; use theme variables or--spacing(12).