--- name: tailwindcss-plugins description: Tailwind CSS plugins including official plugins and custom plugin development --- # Tailwind CSS Plugins ## Official Plugins ### @tailwindcss/typography Beautiful typographic defaults for content you don't control (Markdown, CMS content). #### Installation ```bash npm install -D @tailwindcss/typography ``` ```css @import "tailwindcss"; @plugin "@tailwindcss/typography"; ``` #### Basic Usage ```html Article Title This content gets beautiful default styles... ``` #### Size Modifiers | Class | Description | |-------|-------------| | `prose-sm` | Smaller text (14px base) | | `prose` | Default (16px base) | | `prose-lg` | Larger text (18px base) | | `prose-xl` | Extra large (20px base) | | `prose-2xl` | Huge (24px base) | ```html ``` #### Color Themes ```html Gray theme Zinc theme Neutral theme Stone theme ``` #### Dark Mode ```html ``` #### Element Modifiers Override specific elements: ```html Content ``` #### Max Width Control ```html Full width content ``` #### Escaping Prose Styles ```html Styled heading Styled paragraph Back to prose styles ``` #### Custom Class Name ```css @plugin "@tailwindcss/typography" { className: wysiwyg; } ``` ```html Content ``` ### @tailwindcss/forms Resets form elements to a consistent, easily-styleable baseline. #### Installation ```bash npm install -D @tailwindcss/forms ``` ```css @import "tailwindcss"; @plugin "@tailwindcss/forms"; ``` #### Styled Elements The plugin applies styles to: - `input[type='text']` - `input[type='email']` - `input[type='password']` - `input[type='number']` - `input[type='url']` - `input[type='date']` - `input[type='datetime-local']` - `input[type='month']` - `input[type='week']` - `input[type='time']` - `input[type='search']` - `input[type='tel']` - `input[type='checkbox']` - `input[type='radio']` - `select` - `select[multiple]` - `textarea` #### Basic Usage ```html Option 1 Option 2 ``` #### Strategy: Class-Based For opt-in styling (doesn't apply global resets): ```css @plugin "@tailwindcss/forms" { strategy: class; } ``` ```html ``` #### Form Classes Reference | Class | Element | |-------|---------| | `form-input` | Text inputs | | `form-textarea` | Textareas | | `form-select` | Selects | | `form-multiselect` | Multiple selects | | `form-checkbox` | Checkboxes | | `form-radio` | Radio buttons | #### Styling Checkboxes/Radios ```html ``` ### @tailwindcss/container-queries Style elements based on their container's size instead of the viewport. #### Installation ```bash npm install -D @tailwindcss/container-queries ``` ```css @import "tailwindcss"; @plugin "@tailwindcss/container-queries"; ``` #### Basic Usage ```html Responsive to container, not viewport ``` #### Container Breakpoints | Prefix | Width | |--------|-------| | `@xs` | 320px | | `@sm` | 384px | | `@md` | 448px | | `@lg` | 512px | | `@xl` | 576px | | `@2xl` | 672px | | `@3xl` | 768px | | `@4xl` | 896px | | `@5xl` | 1024px | | `@6xl` | 1152px | | `@7xl` | 1280px | #### Named Containers ```html Only flex when sidebar container is md Grid when main container is lg ``` #### Arbitrary Container Values ```html Arbitrary breakpoint values ``` ## Creating Custom Plugins (v4) ### CSS-Only Utilities For simple utilities, use the `@utility` directive instead of a JavaScript plugin: ```css /* In your CSS file */ @utility content-auto { content-visibility: auto; } @utility text-balance { text-wrap: balance; } @utility scrollbar-none { scrollbar-width: none; -ms-overflow-style: none; } @utility scrollbar-none::-webkit-scrollbar { display: none; } ``` ### JavaScript Plugins For complex plugins requiring JavaScript: ```javascript // plugins/my-plugin.js import plugin from 'tailwindcss/plugin' export default plugin(function({ addUtilities, addComponents, matchUtilities, theme }) { // Add static utilities addUtilities({ '.content-auto': { 'content-visibility': 'auto', }, '.text-balance': { 'text-wrap': 'balance', }, }) // Add components addComponents({ '.btn': { padding: theme('spacing.2') + ' ' + theme('spacing.4'), borderRadius: theme('borderRadius.lg'), fontWeight: theme('fontWeight.medium'), }, '.btn-primary': { backgroundColor: theme('colors.blue.500'), color: theme('colors.white'), '&:hover': { backgroundColor: theme('colors.blue.600'), }, }, }) // Add dynamic utilities matchUtilities( { 'text-shadow': (value) => ({ textShadow: value, }), }, { values: theme('textShadow') } ) }) ``` Load in CSS: ```css @import "tailwindcss"; @plugin "./plugins/my-plugin.js"; ``` ### Plugin with Theme Extension ```javascript // plugins/gradients.js import plugin from 'tailwindcss/plugin' export default plugin( function({ matchUtilities, theme }) { matchUtilities( { 'text-gradient': (value) => ({ backgroundImage: value, backgroundClip: 'text', color: 'transparent', }), }, { values: theme('textGradient') } ) }, { theme: { textGradient: { primary: 'linear-gradient(to right, #667eea, #764ba2)', secondary: 'linear-gradient(to right, #f093fb, #f5576c)', sunset: 'linear-gradient(to right, #fa709a, #fee140)', }, }, } ) ``` ### Adding Custom Variants ```javascript // plugins/variants.js import plugin from 'tailwindcss/plugin' export default plugin(function({ addVariant }) { // Peer states addVariant('peer-checked', ':merge(.peer):checked ~ &') // Group states addVariant('group-focus-visible', ':merge(.group):focus-visible &') // Data attributes addVariant('data-active', '&[data-active="true"]') addVariant('data-loading', '&[data-loading]') // Custom selectors addVariant('hocus', ['&:hover', '&:focus']) addVariant('not-first', '&:not(:first-child)') addVariant('not-last', '&:not(:last-child)') }) ``` ## Community Plugins ### Popular Plugins | Plugin | Description | |--------|-------------| | `tailwindcss-animate` | Animation utilities | | `tailwindcss-motion` | Advanced motion/animation | | `@headlessui/tailwindcss` | Headless UI variants | | `tailwind-scrollbar` | Scrollbar styling | | `tailwindcss-3d` | 3D transform utilities | | `tailwindcss-fluid-type` | Fluid typography | ### tailwindcss-animate ```bash npm install -D tailwindcss-animate ``` ```css @plugin "tailwindcss-animate"; ``` ```html Animated content Exiting content ``` ## Best Practices ### 1. Load Only What You Need ```css /* Only load plugins you actually use */ @plugin "@tailwindcss/typography"; /* @plugin "@tailwindcss/forms"; -- commented out if not using */ ``` ### 2. Use CSS Utilities First Before creating a JavaScript plugin, try the `@utility` directive: ```css /* Simple custom utility - no JS needed */ @utility glass { backdrop-filter: blur(10px); background: rgba(255, 255, 255, 0.1); } ``` ### 3. Document Custom Plugins ```javascript /** * @name Text Gradient Plugin * @description Adds text gradient utilities * @usage class="text-gradient-primary" */ export default plugin(...) ``` ### 4. Test Plugin Compatibility When upgrading Tailwind, verify all plugins work with the new version: ```bash npm outdated | grep tailwind npm update @tailwindcss/typography @tailwindcss/forms ```
This content gets beautiful default styles...
Styled paragraph
Back to prose styles