4
4 Comments

Is there any way to write smaller/cleaner tailwind?

I love the simplicity of tailwind, especially when used with Tailwind UI. I can quickly roll out UIs and unlike more traditional UI kits I can tweak things with unlimited freedom if something isn't quite right.

However, the downside is the TONS of classes in my HTML almost gives me anxiety when opening a file. The readability and maintainability goes out the window. You can combat some of this by making reusable classes for things like buttons, but for most things that's just the side-effect of atomic design.

What I'm wondering is if anyone has found a way to make this any more manageable? I've started using this class sorter which has helped a little bit but it's still a lot. I've also tried using @apply and moving all my tailwind out of the HTML but I feel like that's not a best practice. I've also tried SailUi which puts some of the more common things into simple reusable classes.

Is there any tips or tricks or tools that help keep things cleaner and smaller?

Edit: Just found twin.macro which seems like the closest I'm going to find to pull the CSS out of the HTML and clean some things up.

posted to Icon for group TailwindCSS
TailwindCSS
on April 15, 2022
  1. 2

    Class names sorting is great! I use https://github.com/tailwindlabs/prettier-plugin-tailwindcss and https://github.com/tailwindlabs/tailwindcss/issues/7553#issuecomment-735915659, which conflict with headwind

    Is there any tips or tricks or tools that help keep things cleaner and smaller?

    One thing that helps me a lot is to keep cleaner and smaller frontend (e.g. react) components. Having a 300 line file and TailwindCSS on top of it is not the way to go—consider making more components where it makes sense.

    I've also tried using @apply and moving all my tailwind out of the HTML but I feel like that's not a best practice

    I avoid the @apply directive, and the creators of Tailwind advice against it.

    Finally, sometimes it just takes getting used to with a few months of practice.

  2. 1

    Then why not use Bootstrap? I love botstrap5

  3. 1

    I usually write normal CSS classes and use the @apply directive to use tailwind's pseudo classes, I rarely use it directly on my HTML.

  4. 1

    Are you using any frontend framework?

Trending on Indie Hackers
I spent $0 on marketing and got 1,200 website visitors - Here's my exact playbook User Avatar 58 comments Veo 3.1 vs Sora 2: AI Video Generation in 2025 🎬🤖 User Avatar 29 comments Codenhack Beta — Full Access + Referral User Avatar 21 comments I built eSIMKitStore — helping travelers stay online with instant QR-based eSIMs 🌍 User Avatar 20 comments 🚀 Get Your Brand Featured on FaceSeek User Avatar 18 comments Day 6 - Slow days as a solo founder User Avatar 16 comments