this post was submitted on 11 Apr 2025
11 points (76.2% liked)

Programming

22170 readers
52 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
 

There's a big caveat to Tailwind: It generates styles at build time.

So if you try styling your elements with dynamic classes like bg-${color}, it just won't work, you need to write out the full class name for Tailwind to pick it up.

That's fine for a lot of apps, but it becomes a real challenge when you're building things like visual editors, customizable dashboards, or anything that needs dynamic, interactive styling.

The good news is that you can still make it work if you understand how Tailwind works under the hood.

That's why I wrote this blog post, where I show how to:

  • Understand how Tailwind generates styles
  • Mix inline styles with utility classes
  • Use safelisting in v4.0
  • Apply all this for visual editors like Puck
you are viewing a single comment's thread
view the rest of the comments
[–] fedeboto@programming.dev 0 points 4 months ago

Just a quick heads-up since writing this, Tailwind 4.1 was released which introduced a new way to safelist classes using brace expansion. It works pretty much the same as what I show in the blog, but instead of using a .txt file, you can do it inline directly in the @source directive.

Both approaches are totally valid depending on what you need.

You can check it out here: https://tailwindcss.com/blog/tailwindcss-v4-1#safelist-specific-utilities-with-source-inline