Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to change color in tailwind dynamically

I getting hex color code from database, I am trying to apply that color in div.

className={bg-[${color}]}

but the color is not applying, How can we change the color in tailwind dynamically from the color code getting from API

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can’t dynamically apply the color using tailwind. Because tailwind utility classes are generated at build time. But maybe you can achieve this quite easily with inline style like below.

<div style={{ backgroundColor: color }}>Content here</div>

I hope it helps.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading