mcpField
T
tailwindcss-best-practices

tailwindcss-best-practices

github.com/biggoraDesign & UI252 installsUpdated today
Repository

About tailwindcss-best-practices

tailwindcss-best-practices is a reference skill for applying Tailwind CSS v4 in existing projects. It covers setup choices, CSS-first conventions, migration pitfalls, and ways to verify styling changes.

Key features

  1. 01Project and integration inspection guidance
  2. 02CSS-first v4 directives and theming
  3. 03Utility selection and class detection guidance
  4. 04v3-to-v4 migration notes
  5. 05Build, lint, and UI verification steps

Use cases

  1. 01Adding Tailwind CSS v4 to a project
  2. 02Migrating styles from Tailwind v3
  3. 03Troubleshooting utility detection and build setup

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/biggora/claude-plugins-registry --skill tailwindcss-best-practices

After installing, type/tailwindcss-best-practicesin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
best-practices-utility-patterns.md
core-installation.md
core-preflight.md
core-responsive.md
core-source-detection.md
core-theme.md
core-utility-classes.md
core-variants.md
effects-form-controls.md
effects-mask.md
effects-scroll-snap.md
effects-scrollbars.md
effects-text-shadow.md
effects-transition-animation.md
effects-visibility-interactivity.md
features-content-detection.md
features-custom-styles.md
features-dark-mode.md
features-functions-directives.md
features-upgrade.md
layout-aspect-ratio.md
layout-columns.md
layout-display.md
layout-flexbox.md
layout-grid.md
layout-height.md
layout-inset.md
layout-logical-properties.md
layout-margin.md
layout-min-max-sizing.md

Details

From the project README

Tailwind CSS v4 Best Practices

Documentation snapshot: Tailwind CSS v4.3.3, verified against the npm latest tag and official documentation on 2026-08-29. Recheck https://tailwindcss.com/docs and the npm tag when the user asks for the latest version.

Tailwind v4 is CSS-first: @theme defines design tokens, @utility registers utilities, and @custom-variant registers variants. Legacy JavaScript configuration is still available through @config, but it is not detected automatically and some v3 options are unsupported.

Working Method

  1. Inspect the project before editing. Identify the installed tailwindcss version, package manager, build integration, main CSS entry point, legacy config or plugins, source roots, and existing design tokens/components. Do not upgrade a project merely because this skill documents a newer version.
  2. Choose the integration that matches the stack. Prefer the framework's official guide when one exists. Use @tailwindcss/vite for Vite-based stacks, @tailwindcss/postcss for PostCSS-based stacks such as Next.js, @tailwindcss/webpack as a webpack loader, or @tailwindcss/cli for a standalone build. Read installation before changing build configuration.
  3. Use the smallest styling mechanism that fits. Prefer an existing utility or component; use an arbitrary value for a true one-off; add an @theme token when a design value is reused; add @utility only for a reusable CSS capability; use custom CSS for third-party overrides or rules that are clearer as CSS.
  4. Keep candidates statically detectable. Map props and states to complete class strings. Do not construct fragments such as `bg-${color}-500`. Read source detection for monorepos, external packages, exclusions, and safelists.
  5. Preserve the existing design system. Reuse its spacing, color, typography, radius, component, and class-merging conventions. Avoid introducing arbitrary values when a matching token already exists.
  6. Verify the observable result. Run the relevant build/type/lint/tests, confirm expected utilities appear in compiled CSS when detection is in question, and inspect responsive, state, dark-mode, focus, and reduced-motion behavior in the rendered UI when applicable.

v4.3 Additions

CapabilityUse
Scrollbarsscrollbar-auto, scrollbar-thin, scrollbar-none, scrollbar-thumb-*, scrollbar-track-*, and scrollbar-gutter-*; see scrollbars
Size containers@container-size or @container-size/{name} when queries or container units need block-size information; see responsive design
Zoomzoom-*, zoom-[value], and zoom-(--property) for CSS zoom; see transforms
Tab sizetab-*, tab-[value], and tab-(--property) for rendered tab width; see typography
Variants in CSS@variant hover:focus for stacked variants and @variant hover, focus for a shared block
Functional utilities--default(...) inside --value(...) or --modifier(...) when the bare utility needs a fallback; see functions and directives

Critical v4 Migration Gotchas

These are the most common mistakes when working with Tailwind v4. If you're migrating from v3 or using v4 for the first time, read the upgrade guide — but here are the top trip-ups:

v3 (old)v4 (correct)Why it changed
!bg-red-500bg-red-500!Important modifier moved from prefix to suffix
bg-opacity-75bg-red-500/75Opacity modifiers removed; use slash syntax on the color
shadowshadow-smShadow scale shifted down one step
shadow-smshadow-xsShadow scale shifted down one step
roundedrounded-smBorder radius scale shifted down one step
rounded-smrounded-xsBorder radius scale shifted down one step
ringring-3Default ring width changed from 3px to 1px
outline-noneoutline-hiddenRenamed for clarity
flex-shrink-0shrink-0Shorter alias is now the only form
flex-growgrowShorter alias is now the only form
overflow-ellipsistext-ellipsisRenamed for consistency
blurblur-smBlur scale shifted down one step
@tailwind base/components/utilities@import "tailwindcss"Single CSS import replaces three directives
Automatically detected tailwind.config.jsCSS-first directives, or explicit @config for compatibilityJS config is no longer auto-detected
darkMode: 'class'@custom-variant dark (&:where(.dark, .dark *));Dark mode config moves to CSS
bg-[--var]bg-(--var)CSS variable arbitrary values use parentheses
theme(screens.xl)theme(--breakpoint-xl)Theme function uses CSS variable names
@layer utilities { }@utility name { }Custom utilities use dedicated directive
start-* / end-*inset-s-* / inset-e-*Deprecated in v4.2

Core References

TopicDescriptionReference
InstallationVite, PostCSS, Webpack, CLI, and CDN setupcore-installation
Utility ClassesUnderstanding Tailwind's utility-first approachcore-utility-classes
Theme VariablesDesign tokens, @theme directive, theme variable namespacescore-theme
Responsive DesignMobile-first breakpoints, responsive variants, container queriescore-responsive
VariantsConditional styling with state, pseudo-class, media query, and pointer variantscore-variants
PreflightTailwind's base styles and how to extend or disable themcore-preflight
Source DetectionHow Tailwind detects classes, @source, @source not, @source inline()core-source-detection

Layout

Display & Flexbox & Grid
TopicDescriptionReference
Displayflex, grid, block, inline, hidden, sr-only, flow-root, contentslayout-display
Flexboxflex-direction, justify, items, gap, grow, shrink, wrap, orderlayout-flexbox
Gridgrid-cols, grid-rows, gap, place-items, col-span, row-span, subgridlayout-grid
Aspect RatioControlling element aspect ratio for responsive medialayout-aspect-ratio
ColumnsMulti-column layout for magazine-style or masonry layoutslayout-columns
Positioning
TopicDescriptionReference
PositionControlling element positioning with static, relative, absolute, fixed, and stickylayout-position
InsetPlacement of positioned elements with inset, logical inset (inset-s-*, inset-bs-*), and deprecated start-*/end-*layout-inset
Sizing
TopicDescriptionReference
WidthSetting element width with spacing scale, fractions, container sizes, viewport unitslayout-width
HeightSetting element height with spacing scale, fractions, viewport unitslayout-height
Min & Max Sizingmin-width, max-width, min-height, max-height constraintslayout-min-max-sizing
Logical SizingWriting-mode-aware sizing: inline-*, block-*, min-inline-*, max-block-* (v4.2)layout-logical-properties
Spacing
TopicDescriptionReference
MarginMargins with spacing scale, negative values, logical properties (mbs-*, mbe-*)layout-margin
PaddingPadding with spacing scale, logical properties (pbs-*, pbe-*)layout-padding
Overflow
TopicDescriptionReference
OverflowControlling how elements handle content that overflowslayout-overflow
Images & Replaced Elements
TopicDescriptionReference
Object Fit & PositionControlling how images and video are resized and positionedlayout-object-fit-position
Tables
TopicDescriptionReference
Table Layoutborder-collapse, table-auto, table-fixedlayout-tables

Transforms

TopicDescriptionReference
Transform BaseBase transform utilities, hardware acceleration, custom transform valuestransform-base
TranslateTranslating elements on x, y, z axes with spacing scale and percentagestransform-translate
RotateRotating elements in 2D and 3D spacetransform-rotate
ScaleScaling elements uniformly or on specific axestransform-scale
SkewSkewing elements on x and y axestransform-skew

Typography

TopicDescriptionReference
Font & TextFont size, weight, color, line-height, letter-spacing, decoration, truncate, wrap-break-word, wrap-anywheretypography-font-text
Text AlignControlling text alignment with left, center, right, justifytypography-text-align
List Stylelist-style-type, list-style-position for bullets and markerstypography-list-style

Visual

TopicDescriptionReference
BackgroundBackground color, gradient, image, size, positionvisual-background
BorderBorder width, color, radius, divide, ring, block border utilities (border-bs-*, border-be-*)visual-border
EffectsBox shadow, opacity, mix-blend, backdrop-blur, filter, colored drop shadowsvisual-effects
SVGfill, stroke, stroke-width for SVG and icon stylingvisual-svg
Text ShadowText shadow sizes, colors, and opacity modifiers (v4.1)effects-text-shadow
MaskComposable mask utilities with gradient and radial masks (v4.1)effects-mask
ScrollbarsWidth, thumb/track colors, and stable gutter utilities (v4.3)effects-scrollbars

Effects & Interactivity

TopicDescriptionReference
Transition & AnimationCSS transitions, animation keyframes, reduced motioneffects-transition-animation
Visibility & InteractivityVisibility, cursor, pointer-events, user-select, z-indexeffects-visibility-interactivity
Form Controlsaccent-color, appearance, caret-color, resizeeffects-form-controls
Scroll Snapscroll-snap-type, scroll-snap-align for carouselseffects-scroll-snap

Features

Dark Mode
TopicDescriptionReference
Dark ModeDark mode with dark: variant, @custom-variant, class and data-attribute strategiesfeatures-dark-mode
Migration
TopicDescriptionReference
Upgrade GuideMigrating from v3 to v4, all renamed/removed utilities, scale shifts, config migrationfeatures-upgrade
Customization
TopicDescriptionReference
Custom StylesAdding custom styles, utilities with @utility, variants with @custom-variant, arbitrary valuesfeatures-custom-styles
Functions & DirectivesTailwind's CSS directives (@theme, @utility, @custom-variant, @source) and functionsfeatures-functions-directives
Content DetectionHow Tailwind detects classes, @source configuration, safelisting with @source inline()features-content-detection

Best Practices

TopicDescriptionReference
Utility PatternsManaging duplication, conflicts, important modifier, when to use componentsbest-practices-utility-patterns

Key Recommendations

  • Prefer utilities and existing components over new abstraction layers.
  • Define reusable design tokens with @theme; use :root for CSS variables that should not generate utilities.
  • Treat unprefixed responsive utilities as the mobile baseline and breakpoint variants as overrides.
  • Keep full candidate strings in source; map dynamic inputs to static class lists.
  • Use @custom-variant to define a variant and @variant to apply an existing variant inside CSS.
  • Prefer CSS-first configuration for new v4 work; retain @config or @plugin only when compatibility requires it.
  • Use consistent units for breakpoints; the official defaults use rem, and mixed units can produce unexpected ordering.
  • Do not use Play CDN in production or add Sass/Less/Stylus in front of Tailwind v4.

Comments

Markdown supported