4

I can use predefined tailwind classes to set color in HTML like:

<div class="border border-purple-500"></div>

But I also would like to use the same color in my custom CSS, like:

.my-class {
    border: 1px solid $purple-500;
}

Is it possible to get tailwind color value in CSS?

2 Answers 2

10

It is. You can use theme() directive.

.my-class {
    border: 1px solid theme('colors.purple.500');
}

or via @apply

.my-class {
    @apply border border-purple-500;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, thanks! I know about @apply but it does not work on pseudo classes like :before or :after. That's why I need to access values directly.
0

You can also add exact color to tailwind.css inside [ ]. For example

 <div class="border border-[#4231d]"></div>

You can use the same color in css class:

.my-class {
    border: 1px solid #4231d;
}

    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.