Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
AI-powered UI styling skill with 67 UI styles and 161 reasoning rules for professional interface design.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/tailwind-customization.md
1# Tailwind CSS Customization23Config file structure, custom utilities, plugins, and theme extensions.45## @theme Directive67Modern approach to customize Tailwind using CSS:89```css10@import "tailwindcss";1112@theme {13/* Custom colors */14--color-brand-50: oklch(0.97 0.02 264);15--color-brand-500: oklch(0.55 0.22 264);16--color-brand-900: oklch(0.25 0.15 264);1718/* Custom fonts */19--font-display: "Satoshi", "Inter", sans-serif;20--font-body: "Inter", system-ui, sans-serif;2122/* Custom spacing */23--spacing-18: calc(var(--spacing) * 18);24--spacing-navbar: 4.5rem;2526/* Custom breakpoints */27--breakpoint-3xl: 120rem;28--breakpoint-tablet: 48rem;2930/* Custom shadows */31--shadow-glow: 0 0 20px rgba(139, 92, 246, 0.3);3233/* Custom radius */34--radius-large: 1.5rem;35}36```3738**Usage:**39```html40<div class="bg-brand-500 font-display shadow-glow rounded-large">41Custom themed element42</div>4344<div class="tablet:grid-cols-2 3xl:grid-cols-6">45Custom breakpoints46</div>47```4849## Color Customization5051### Custom Color Palette5253```css54@theme {55/* Full color scale */56--color-primary-50: oklch(0.98 0.02 250);57--color-primary-100: oklch(0.95 0.05 250);58--color-primary-200: oklch(0.90 0.10 250);59--color-primary-300: oklch(0.85 0.15 250);60--color-primary-400: oklch(0.75 0.18 250);61--color-primary-500: oklch(0.65 0.22 250);62--color-primary-600: oklch(0.55 0.22 250);63--color-primary-700: oklch(0.45 0.20 250);64--color-primary-800: oklch(0.35 0.18 250);65--color-primary-900: oklch(0.25 0.15 250);66--color-primary-950: oklch(0.15 0.10 250);67}68```6970### Semantic Colors7172```css73@theme {74--color-success: oklch(0.65 0.18 145);75--color-warning: oklch(0.75 0.15 85);76--color-error: oklch(0.60 0.22 25);77--color-info: oklch(0.65 0.18 240);78}79```8081```html82<div class="bg-success text-white">Success message</div>83<div class="border-error">Error state</div>84```8586## Typography Customization8788### Custom Fonts8990```css91@theme {92--font-sans: "Inter", system-ui, sans-serif;93--font-serif: "Merriweather", Georgia, serif;94--font-mono: "JetBrains Mono", Consolas, monospace;95--font-display: "Playfair Display", serif;96}97```9899```html100<h1 class="font-display">Display heading</h1>101<p class="font-sans">Body text</p>102<code class="font-mono">Code block</code>103```104105### Custom Font Sizes106107```css108@theme {109--font-size-xs: 0.75rem;110--font-size-sm: 0.875rem;111--font-size-base: 1rem;112--font-size-lg: 1.125rem;113--font-size-xl: 1.25rem;114--font-size-2xl: 1.5rem;115--font-size-3xl: 1.875rem;116--font-size-4xl: 2.25rem;117--font-size-5xl: 3rem;118--font-size-jumbo: 4rem;119}120```121122## Spacing Customization123124```css125@theme {126/* Add custom spacing values */127--spacing-13: calc(var(--spacing) * 13);128--spacing-15: calc(var(--spacing) * 15);129--spacing-18: calc(var(--spacing) * 18);130131/* Named spacing */132--spacing-header: 4rem;133--spacing-footer: 3rem;134--spacing-section: 6rem;135}136```137138```html139<div class="p-18">Custom padding</div>140<section class="py-section">Section spacing</section>141```142143## Custom Utilities144145Create reusable utility classes:146147```css148@utility content-auto {149content-visibility: auto;150}151152@utility tab-* {153tab-size: var(--tab-size-*);154}155156@utility glass {157background: rgba(255, 255, 255, 0.1);158backdrop-filter: blur(10px);159border: 1px solid rgba(255, 255, 255, 0.2);160}161```162163**Usage:**164```html165<div class="content-auto">Optimized rendering</div>166<pre class="tab-4">Code with 4-space tabs</pre>167<div class="glass">Glassmorphism effect</div>168```169170## Custom Variants171172Create custom state variants:173174```css175@custom-variant theme-midnight (&:where([data-theme="midnight"] *));176@custom-variant aria-checked (&[aria-checked="true"]);177@custom-variant required (&:required);178```179180**Usage:**181```html182<div data-theme="midnight">183<div class="theme-midnight:bg-navy-900">184Applies in midnight theme185</div>186</div>187188<input class="required:border-red-500" required />189```190191## Layer Organization192193Organize CSS into layers:194195```css196@layer base {197h1 {198@apply text-4xl font-bold tracking-tight;199}200201h2 {202@apply text-3xl font-semibold;203}204205a {206@apply text-blue-600 hover:text-blue-700 underline-offset-4 hover:underline;207}208209body {210@apply bg-background text-foreground antialiased;211}212}213214@layer components {215.btn {216@apply px-4 py-2 rounded-lg font-medium transition-colors;217}218219.btn-primary {220@apply bg-blue-600 text-white hover:bg-blue-700;221}222223.btn-secondary {224@apply bg-gray-200 text-gray-900 hover:bg-gray-300;225}226227.card {228@apply bg-white rounded-xl shadow-md p-6 hover:shadow-lg transition-shadow;229}230231.input {232@apply w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent;233}234}235236@layer utilities {237.text-balance {238text-wrap: balance;239}240241.scrollbar-hide {242-ms-overflow-style: none;243scrollbar-width: none;244}245.scrollbar-hide::-webkit-scrollbar {246display: none;247}248}249```250251## @apply Directive252253Extract repeated utility patterns:254255```css256.btn-primary {257@apply bg-blue-600 hover:bg-blue-700 active:bg-blue-800 text-white font-semibold px-6 py-3 rounded-lg shadow-md hover:shadow-lg transition-all duration-200 focus:outline-none focus:ring-4 focus:ring-blue-300;258}259260.input-field {261@apply w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed;262}263264.section-container {265@apply container mx-auto px-4 sm:px-6 lg:px-8 max-w-7xl;266}267```268269**Usage:**270```html271<button class="btn-primary">Click me</button>272<input class="input-field" />273<div class="section-container">Content</div>274```275276## Plugins277278### Official Plugins279280```bash281npm install -D @tailwindcss/typography @tailwindcss/forms @tailwindcss/container-queries282```283284```javascript285// tailwind.config.js286export default {287plugins: [288require('@tailwindcss/typography'),289require('@tailwindcss/forms'),290require('@tailwindcss/container-queries'),291],292}293```294295**Typography plugin:**296```html297<article class="prose lg:prose-xl">298<h1>Styled article</h1>299<p>Automatically styled prose content</p>300</article>301```302303**Forms plugin:**304```html305<!-- Automatically styled form elements -->306<input type="text" />307<select></select>308<textarea></textarea>309```310311### Custom Plugin312313```javascript314// tailwind.config.js315const plugin = require('tailwindcss/plugin')316317export default {318plugins: [319plugin(function({ addUtilities, addComponents, theme }) {320// Add utilities321addUtilities({322'.text-shadow': {323textShadow: '2px 2px 4px rgba(0, 0, 0, 0.1)',324},325'.text-shadow-lg': {326textShadow: '4px 4px 8px rgba(0, 0, 0, 0.2)',327},328})329330// Add components331addComponents({332'.card-custom': {333backgroundColor: theme('colors.white'),334borderRadius: theme('borderRadius.lg'),335padding: theme('spacing.6'),336boxShadow: theme('boxShadow.md'),337},338})339}),340],341}342```343344## Configuration Examples345346### Complete Tailwind Config347348```javascript349// tailwind.config.ts350import type { Config } from 'tailwindcss'351352const config: Config = {353darkMode: ["class"],354content: [355'./pages/**/*.{ts,tsx}',356'./components/**/*.{ts,tsx}',357'./app/**/*.{ts,tsx}',358],359theme: {360container: {361center: true,362padding: "2rem",363screens: {364"2xl": "1400px",365},366},367extend: {368colors: {369border: "hsl(var(--border))",370input: "hsl(var(--input))",371ring: "hsl(var(--ring))",372background: "hsl(var(--background))",373foreground: "hsl(var(--foreground))",374primary: {375DEFAULT: "hsl(var(--primary))",376foreground: "hsl(var(--primary-foreground))",377},378brand: {37950: '#f0f9ff',380500: '#3b82f6',381900: '#1e3a8a',382},383},384fontFamily: {385sans: ['Inter', 'system-ui', 'sans-serif'],386display: ['Playfair Display', 'serif'],387},388spacing: {389'18': '4.5rem',390'88': '22rem',391'128': '32rem',392},393borderRadius: {394lg: "var(--radius)",395md: "calc(var(--radius) - 2px)",396sm: "calc(var(--radius) - 4px)",397},398keyframes: {399"slide-in": {400"0%": { transform: "translateX(-100%)" },401"100%": { transform: "translateX(0)" },402},403},404animation: {405"slide-in": "slide-in 0.5s ease-out",406},407},408},409plugins: [require("tailwindcss-animate")],410}411412export default config413```414415## Dark Mode Configuration416417```javascript418// tailwind.config.js419export default {420darkMode: ["class"], // or "media" for automatic421// ...422}423```424425**Usage:**426```html427<!-- Class-based -->428<html class="dark">429<div class="bg-white dark:bg-gray-900">430Responds to .dark class431</div>432</html>433434<!-- Media query-based -->435<div class="bg-white dark:bg-gray-900">436Responds to system preference automatically437</div>438```439440## Content Configuration441442Specify files to scan for classes:443444```javascript445// tailwind.config.js446export default {447content: [448"./src/**/*.{js,jsx,ts,tsx}",449"./app/**/*.{js,jsx,ts,tsx}",450"./components/**/*.{js,jsx,ts,tsx}",451"./pages/**/*.{js,jsx,ts,tsx}",452],453// ...454}455```456457### Safelist458459Preserve dynamic classes:460461```javascript462export default {463safelist: [464'bg-red-500',465'bg-green-500',466'bg-blue-500',467{468pattern: /bg-(red|green|blue)-(100|500|900)/,469},470],471}472```473474## Best Practices4754761. **Use @theme for simple customizations**: Prefer CSS-based customization4772. **Extract components sparingly**: Use @apply only for truly repeated patterns4783. **Leverage design tokens**: Define custom tokens in @theme4794. **Layer organization**: Keep base, components, and utilities separate4805. **Plugin for complex logic**: Use plugins for advanced customizations4816. **Test dark mode**: Ensure custom colors work in both themes4827. **Document custom utilities**: Add comments explaining custom classes4838. **Semantic naming**: Use descriptive names (primary not blue)484