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
In this article12 sections
- Beyond the Basics
- Tip 1: Use CVA for Component Variants
- Tip 2: Design Tokens in tailwind.config
- Tip 3: The @apply Escape Hatch
- Tip 4: Group and Peer Modifiers
- Tip 5: Container Queries with Tailwind
- Tip 6: Arbitrary Values for One-Offs
- Tip 7: Custom Animations
- Tip 8: Responsive Design Strategy
- Tip 9: Dark Mode with CSS Variables
- Tip 10: Typography Plugin
- 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.