20 Tailwind CSS Tips That Will Change How You Code

Advanced Tailwind CSS techniques including custom plugins, responsive patterns, animation utilities, and design system integration.

· 3 min read

Assorted handheld tools in a tool rack
In this article12 sections
  1. Beyond the Basics
  2. Tip 1: Use CVA for Component Variants
  3. Tip 2: Design Tokens in tailwind.config
  4. Tip 3: The @apply Escape Hatch
  5. Tip 4: Group and Peer Modifiers
  6. Tip 5: Container Queries with Tailwind
  7. Tip 6: Arbitrary Values for One-Offs
  8. Tip 7: Custom Animations
  9. Tip 8: Responsive Design Strategy
  10. Tip 9: Dark Mode with CSS Variables
  11. Tip 10: Typography Plugin
  12. The Complete List

Beyond the Basics

If you are still writing Tailwind by memorizing utility classes, you are missing out on the real power of the framework. These tips go beyond the documentation and into the patterns that make Tailwind a genuine productivity multiplier.

Tip 1: Use CVA for Component Variants

Class Variance Authority (CVA) is a must-have companion for Tailwind. Instead of writing conditional class logic with ternary operators, define your variants declaratively. It keeps your component props clean and your class strings maintainable.

Tip 2: Design Tokens in tailwind.config

Do not just use Tailwind's default colors. Define your entire design system in tailwind.config.ts with semantic names like primary, surface, and accent. When your client wants to change the brand color, you update one value instead of hunting through 200 files.

Tip 3: The @apply Escape Hatch

When you find yourself repeating the same 10 utility classes across multiple components, extract them into a CSS class using @apply. But use this sparingly. If you @apply everything, you lose the benefits of utility-first CSS.

Tip 4: Group and Peer Modifiers

The group-hover and peer modifiers let you style elements based on the state of a sibling or parent. This eliminates the need for JavaScript event handlers in many interactive UI patterns. A parent with the group class lets any child use group-hover:opacity-100 to react to the parent's hover state.

Tip 5: Container Queries with Tailwind

Tailwind 3.4+ supports container queries with the @container variant. This lets components respond to their container's width rather than the viewport width. This is game-changing for reusable components that need to work in sidebars and full-width layouts.

Tip 6: Arbitrary Values for One-Offs

Need a very specific value that is not in the default scale? Use arbitrary values like w-[137px] or text-[13px]. But if you find yourself using the same arbitrary value repeatedly, add it to your config instead.

Tip 7: Custom Animations

Define custom animations in your tailwind.config with keyframes and animation utilities. A subtle fade-in-up animation applied to cards on scroll can elevate the feel of an entire page without a single line of JavaScript.

Tip 8: Responsive Design Strategy

Start mobile-first and add complexity at larger breakpoints. Use min-width breakpoints (sm:, md:, lg:) as your default. Only use max-width breakpoints when you specifically need to remove styles at larger sizes.

Tip 9: Dark Mode with CSS Variables

Combine Tailwind's dark mode with CSS custom properties for maximum flexibility. Define your colors as HSL values in CSS variables, then reference them in tailwind.config. This lets you support multiple themes, not just light and dark.

Tip 10: Typography Plugin

The @tailwindcss/typography plugin transforms plain HTML content into beautifully formatted prose. Perfect for blog posts, documentation, and any content coming from a CMS or markdown.

The Complete List

The remaining tips cover clamp() for fluid typography, grid template areas with arbitrary values, debugging with outline instead of border, using aspect-ratio for responsive media, sr-only for accessibility, min/max width constraints for better layouts, layer management with @layer, custom variants for complex selectors, print styles with the print: modifier, and the divide utilities for bordered lists.

  • Tailwind CSS
  • CSS
  • Frontend

Written by Pontus Henriksson

Co-founder and CEO of Walldy in Sundsvall. I have built for the web since I was fourteen, tested games for studios like Netflix and Bungie since 2021, and write about what I use in real projects.

Liked this? Get the next one.

New Claude skills, kits and what I learn building AI for small businesses. Not often, only when it is worth sending. Unsubscribe with one click.

Tools for this.

Claude skills, kits and guides that put ideas like these to work. Many are free with an account.

Visit the shop