Skip to content

Tailwind CSS v4 Variants Not Working in "@layer components" #16449

Answered by wongjn
iamaliybi asked this question in Help
Discussion options

You must be logged in to vote

Is this an expected behavior change in Tailwind v4?

Yes, see https://tailwindcss.com/docs/upgrade-guide#adding-custom-utilities.

Should variants be applied differently within @layer components?
Are there any workarounds or best practices for handling variants in @layer components?

Variants don't get applied at all anymore. As per above, Tailwind v4 no longer does anything "special" for CSS inside @layers.


So, for equivalent in v4, you'd do:

@utility btn-success {
	@layer components {
		display: flex;
		align-items: center;
		color: rgb(var(--c-white) / 1);
		border: 1px solid transparent;
		background-color: red;
		transition: opacity 250ms ease-in-out;
	}
}

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@iamaliybi
Comment options

@wongjn
Comment options

wongjn Feb 12, 2025
Collaborator

Answer selected by iamaliybi
Comment options

You must be logged in to vote
1 reply
@iamaliybi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants