Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tips for Tailwind CSS

Avatar for Radoslav Stankov Radoslav Stankov
October 18, 2025
1

Tips for Tailwind CSS

Avatar for Radoslav Stankov

Radoslav Stankov

October 18, 2025
Tweet

Transcript

  1. !

  2. ⚙ utility first ! easy to learn ! small CSS

    bundle ! no thinking about naming ! mobile first ! constancy in UI ! fast prototyping
  3. +

  4. +

  5. const SIZES = { "sm": "text-sm" "base": "text-base" "lg": "text-lg

    font-semibold" } type IProps = { size?: keyof typeof SIZES } function Text({ size: "base" }): IProps { // ... } ! Targeted props
  6. Every custom Tailwind class name gets into your CSS bundle.

    If you have many pages using code-splitting and separate CSS bundles, you might want to avoid custom classnames.
  7. ⚖ Rules - avoid from Tailwind 1/ arbitrary values or

    variables <div class="bg-[#bada55] text-[22px]"> <div class="text-(--my-var)">...</div> 2/ arbitrary properties <div class="[mask-type:luminance]"> 3/ complex selectors <div class="[&>[data-active]+span]:text-blue-600 ..."> (except in prototyping)
  8. ⚖ Rules - when to have custom CSS 1/ What

    I want doesn’t have a Tailwind equivalent. Some fancy grid setups and things are dependent on CSS variables. 2/ Tailwind classes get too interconnected and hard to reason about. Usually involving styling multiple child components. When the “Cascading” part of CSS is needed. 3/ Automatic style. Style is applied when a data attribute is applied to an HTML element. 4/ I want to reuse a class name, not a whole component. Example - inputs, containers and similar
  9. ⚖ Rules - how to have custom CSS In React

    projects, I use the CSS module in the same folder as the component. In Ruby on Rails projects, prefix all classes with “c-”, like “c- input” or “c-button-primary”. Rely on @apply, a directive to reuse Tailwind classes in my custom classes. In this way, I don’t have to remember how much is “gap-2” or “mt-3” or what is in “text-sm”
  10. function MyButton() { const [isHovered, setIsHovered] = useState(false); const className

    = isHovered ? 'button button-hover' : 'button'; const onMouseEnter = () => setIsHovered(true); const onMouseLeave = () => setIsHovered(false); return ( <button className={className} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>Button</button> ); }
  11. <div class="group"> <span class="group-hover:bg-cloud"> When parent element (group) is hovered,

    I change background </span> <span> I don't change color </span> </div>
  12. 0/ ! Learn the basics 1/ ! Setup your environment

    2/ ! Don't use Tailwind without a component system 3/ ! How to parameterize components 4/ ✍ Write CSS when needed 5/ ! Tricks - group and grid ! Recap