Skip to main content

Introduction

The Tailwind CSS plugin system allows you to extend the framework with custom utilities, variants, components, and base styles. Plugins receive a PluginAPI object with methods to register new styles and access theme configuration.

plugin() Function

Create a plugin by calling the default export from tailwindcss/plugin.
(api: PluginAPI) => void
required
Function that receives the Plugin API and registers custom styles
Partial<Config>
Optional configuration object to extend theme values or add variants

Basic Plugin

Plugin with Configuration

plugin.withOptions()

Create a plugin that accepts configuration options.
(options?: T) => PluginFn
required
Function that returns a plugin handler based on the provided options
(options?: T) => Partial<Config>
Optional function that returns configuration based on the provided options

Example

PluginAPI Interface

The Plugin API provides methods to extend Tailwind CSS:

CssInJs Type

Plugins use a CSS-in-JS object format to define styles:

Features

  • Nested selectors: Use & for the current selector
  • Pseudo-classes: Define :hover, :focus, etc. as nested objects
  • Media queries: Use @media as object keys
  • At-rules: Support for @supports, @keyframes, etc.
  • camelCase properties: Automatically converted to kebab-case
  • Arrays: Multiple values for the same property

Example

Loading Plugins

In CSS Files

In Configuration Files

Type Exports

Plugin handlers are called during build time. Use the design system API to register utilities and variants that are generated on demand.