Space sensitivity in inline variable declarations #18034
-
What version of Tailwind CSS are you using? v4.1.6 What build tool (or framework if it abstracts the build tool) are you using? Vite 6.2.0 What version of Node.js are you using? v22.13.1 What browser are you using? Chrome 136 What operating system are you using? Ubuntu Linux Describe your issue I’ve hit this a few times now.. there’s an inconsistency in how Tailwind handles CSS variable declarations inline versus in For example, in the following code: <div class="[--gap:40px] flex flex-col gap-[--gap]">
<div class="size-5 bg-red-500"></div>
<div class="size-5 bg-green-500"></div>
</div> The above works as expected. However, introducing a space in the declaration, like so: <div class="[--gap: 40px] flex flex-col gap-[--gap]"> causes the variable to no longer be recognized. This behavior is inconsistent with @theme {
--gap:40px;
}
@theme {
--gap: 40px;
} It would be helpful if the space between the property name and value in the inline context is made insignificant to align with the standard CSS variable syntax and avoid potential confusion. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
@functasti The problem is that in the HTML markup, a space is the separator of a class name so if you do |
Beta Was this translation helpful? Give feedback.
-
@philipp-spiess Hmm... I see what you’re saying. It’s not that I need a space there - it just slips in accidentally, and it’s a pain to debug. :) |
Beta Was this translation helpful? Give feedback.
-
@philipp-spiess I get the explanation about the browser treating the space as a separator between class names, but what’s the actual impact in development time vs. runtime? I understand why spaces matter within the value itself, but why does the space between the colon and the value matter? Couldn’t Tailwind just strip it out at build time? That way, it wouldn’t split into separate class names, and it would prevent a whole class of bugs slipping in accidentally. |
Beta Was this translation helpful? Give feedback.
-
@thecrypticace Idea: Could the VS Code IntelliSense plugin warn about cases where there’s a space between the variable declaration and value? It would effectively act as a linter and help catch these issues before they cause problems. |
Beta Was this translation helpful? Give feedback.
@functasti We don't rewrite your template files though, in that case in your template it would still be two classes so it wouldn't be able to map the CSS file accordingly.