Ask A Question


You’re not receiving notifications from this thread.

How to use CSS Variables with Ruby on Rails Discussion

I asked a question on discord and thought it might be good for it to be here for future reference.

I was wondering of a way to dynamically change which class you are calling. ie:
'<%= "text-#{color} bg-#{color}" %>' << this code is not recommended since tailwind needs the full class name to build.

you can supply a custom color to Tailwind in the config
module.exports = {
colors: {
'primary': 'var(--primary-color)',
same thing as a regular color there


Thank you for visiting here.


Very informative, thank you Chris and Willard!

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 77,200+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.