Skip to content

[v4] Wrong specificity of media query with a custom breakpoint value #2099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mr-wildcard opened this issue Feb 18, 2025 · 2 comments · Fixed by #2107
Closed

[v4] Wrong specificity of media query with a custom breakpoint value #2099

mr-wildcard opened this issue Feb 18, 2025 · 2 comments · Fixed by #2107

Comments

@mr-wildcard
Copy link

What version of Tailwind CSS are you using?

v4.0.7

What build tool (or framework if it abstracts the build tool) are you using?

@tailwindcss/cli v4.0.7

What version of Node.js are you using?

v22.14.0

What browser are you using?

Chrome

What operating system are you using?

macOS

Reproduction URL

$ git clone git@github.com:mr-wildcard/tailwindcss-v4-bug-ordered-custom-breakpoint-value.git
$ cd tailwindcss-v4-bug-ordered-custom-breakpoint-value
$ npm i
$ npx @tailwindcss/cli -i ./input.css -o ./output.css

Describe your issue

If we customize the value of a breakpoint using px unit:

@theme {
    --breakpoint-2xl: 1600px;
}

the generated media query for that specific breakpoint end up before the other media queries using rem:
Image

This is problematic in case we provide a value that is wider than the other breakpoints using rem: in that case we expect the 2xl variant styles to be applied last but they've in fact less specificity than the other media queries:
Image

Image


I believe that the unit of the value is also sorted because if I use the vh unit, the generated media query is placed at the end, but if I use ch unit, it's placed before.

Not sure if that's really an issue and how it could be fixed, but I think that we can quickly fall into this kind of trap and lose hours debugging.
Maybe add a warning in the documentation?

@AntonioVentilii
Copy link

It happened to me too: my custom breakpoints work in rem but not in px

@philipp-spiess
Copy link
Member

Hey! thanks for the feedback and glad you found out how the sorting works but yeah it only compares breakpoint values within the same units. I think you're right we should mention that in the docs, so I'm keeping this issue open so we don't forget.

@philipp-spiess philipp-spiess transferred this issue from tailwindlabs/tailwindcss Feb 19, 2025
adamwathan added a commit that referenced this issue Feb 21, 2025
This has been causing repeated confusion already so let's add a section
to clarify this.

Closes #2099

---------

Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants