TExcelTAD
Home › Tailwind CSS › Tailwind Plugins

Tailwind Plugins

Plugins add extra utilities, components or variants to Tailwind. In v3 plugins were the main extension mechanism. In v4 most simple extensions are written directly in CSS with @utility and @custom-variant, but JavaScript plugins are still supported — including the popular official ones.

Loading a plugin

Install the package, then load it in your CSS with the @plugin directive:

bash · try it yourself
npm install -D @tailwindcss/typography
added 6 packages, and audited 39 packages in 2s

found 0 vulnerabilities
css
@import "tailwindcss";
@plugin "@tailwindcss/typography";

In v3 the same thing was done in tailwind.config.js with plugins: [require('@tailwindcss/typography')].

Official plugins

Plugin Adds Status in v4
@tailwindcss/typography prose classes that style whole articles still a plugin, widely used
@tailwindcss/forms a reset that makes form controls easy to style with utilities still a plugin
@tailwindcss/container-queries @container, @md: built in to v4 — not needed
@tailwindcss/aspect-ratio aspect-w-* replaced by native aspect-*
@tailwindcss/line-clamp line-clamp-* built in since v3.3

The Typography plugin

Markdown or CMS content arrives as plain <h2>, <p>, <ul> with no classes, and Preflight has removed their default styles. Put prose on the wrapper and the plugin styles everything inside with good typographic defaults:

html
<article class="prose lg:prose-xl dark:prose-invert">
  <h1>Release notes</h1>
  <p>Plain HTML from Markdown, styled automatically.</p>
  <ul><li>Headings, lists, quotes, code and tables</li></ul>
</article>
Class Effect
prose base article styles
prose-sm / prose-lg / prose-xl size scale
prose-slate / prose-zinc … grey palette used
dark:prose-invert light-on-dark version
prose-a:text-sky-600 / prose-headings:font-serif element modifiers
not-prose opt a section out

You can get a feel for what it does without the plugin: the playground below styles raw HTML from the parent using arbitrary variants — a hand-made mini "prose".

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
</head>
<body class="p-5">
  <article class="max-w-prose text-gray-700 [&_a]:text-sky-600 [&_a]:underline [&_blockquote]:border-l-4 [&_blockquote]:border-sky-300 [&_blockquote]:pl-3 [&_blockquote]:italic [&_h1]:text-2xl [&_h1]:font-bold [&_h1]:text-gray-900 [&_li]:ml-5 [&_li]:list-disc [&>*+*]:mt-3">
    <h1>Unstyled Markdown output</h1>
    <p>This HTML has <em>no classes</em>. Every style comes from the <a href="#">parent element</a>.</p>
    <ul><li>Lists get bullets back</li><li>Spacing between blocks</li></ul>
    <blockquote>Quotes get a coloured bar.</blockquote>
  </article>
</body>
</html>

The Forms plugin

@tailwindcss/forms resets inputs, selects, checkboxes and radios to a simple, consistent look so utilities like rounded-md border-gray-300 focus:ring-sky-500 behave the same in every browser. Use strategy: "class" (opt in with form-input, form-checkbox …) if you don't want it to touch every element:

css
@plugin "@tailwindcss/forms" {
  strategy: "class";
}

Writing your own plugin

A plugin is a JavaScript function that receives helper functions:

js
// plugins/stack.js
import plugin from "tailwindcss/plugin";

export default plugin(function ({ addUtilities, matchUtilities, addVariant, theme }) {
  addUtilities({
    ".stack": { display: "flex", "flex-direction": "column" },
  });
  matchUtilities(
    { "stack-gap": (value) => ({ gap: value }) },
    { values: theme("spacing") }
  );
  addVariant("hocus", ["&:hover", "&:focus"]);
});
css
@plugin "./plugins/stack.js";

Prefer CSS in v4

Everything in that plugin can now be written in CSS, with no build-time JavaScript:

html · try it yourself
<!DOCTYPE html>
<html>
<head>
  <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.11"></script>
  <style type="text/tailwindcss">
    @utility stack {
      display: flex;
      flex-direction: column;
    }
    @utility stack-gap-* {
      gap: calc(var(--spacing) * --value(integer));
    }
    @custom-variant hocus (&:hover, &:focus);
  </style>
</head>
<body class="p-6">
  <div class="stack stack-gap-3 w-56">
    <button class="rounded-lg bg-gray-200 py-2 hocus:bg-teal-500 hocus:text-white">hocus: hover or focus</button>
    <button class="rounded-lg bg-gray-200 py-2 hocus:bg-teal-500 hocus:text-white">Tab through us</button>
    <button class="rounded-lg bg-gray-200 py-2 hocus:bg-teal-500 hocus:text-white">Same style</button>
  </div>
</body>
</html>
JS plugin API v4 CSS equivalent
addUtilities @utility name { … }
matchUtilities @utility name-* { … --value() … }
addVariant @custom-variant name (…);
addBase @layer base { … }
addComponents @layer components { … }
theme() CSS variables like var(--spacing)

Tip: Reach for a JavaScript plugin only when you need real logic — generating many utilities from data, or distributing a package to other teams.

Test yourself

How do you load a plugin in a Tailwind v4 project?

  1. plugins: [] in package.json
  2. @plugin "@tailwindcss/typography"; in your CSS
  3. <script type="plugin">
  4. @import plugin;

Which official plugin is no longer needed in v4 because the feature is built in?

  1. @tailwindcss/typography
  2. @tailwindcss/forms
  3. @tailwindcss/container-queries
  4. None

What is the CSS-first replacement for the plugin API's addVariant?

  1. @utility
  2. @custom-variant
  3. @apply
  4. @layer variants