Introduction
The Tailwind CSS plugin system allows you to extend the framework with custom utilities, variants, components, and base styles. Plugins receive aPluginAPI object with methods to register new styles and access theme configuration.
plugin() Function
Create a plugin by calling the default export fromtailwindcss/plugin.
Function that receives the Plugin API and registers custom styles
Optional configuration object to extend theme values or add variants
Basic Plugin
Plugin with Configuration
plugin.withOptions()
Create a plugin that accepts configuration options.Function that returns a plugin handler based on the provided options
Optional function that returns configuration based on the provided options
Example
PluginAPI Interface
The Plugin API provides methods to extend Tailwind CSS:| Method | Description |
|---|---|
addUtilities() | Register static utility classes |
matchUtilities() | Register dynamic utilities that accept values |
addVariant() | Register a static variant |
matchVariant() | Register a dynamic variant that accepts values |
addBase() | Add base styles to the @layer base |
addComponents() | Add component styles (alias for addUtilities) |
theme() | Access theme configuration values |
config() | Access arbitrary configuration values |
prefix() | Apply the configured prefix to a class name |
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
@mediaas 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.