tailwindcss icon indicating copy to clipboard operation
tailwindcss copied to clipboard

[v4] Tailwind CSS misinterprets custom text-shadow plugin as text size

Open DarthGigi opened this issue 1 year ago • 8 comments

What version of Tailwind CSS are you using?

v4.0.12

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

SvelteKit 2.18.0

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

https://github.com/DarthGigi/tailwind-v4-text-shadow-mvce

Describe your issue

Using a custom plugin to add text shadows causes tailwindcss to override the text size property, thinking text-shadow is a text size utility while it's not.

Image

This worked fine in v4.0.5 last time I checked, I'm not sure which release introduced this behavior.

Plugin code
import plugin from "tailwindcss/plugin";

const textShadowPlugin = plugin(function ({ matchUtilities, theme }) {
  matchUtilities(
    {
      "text-shadow": (value) => ({
        textShadow: value
      })
    },
    { values: theme("textShadow") }
  );
});

export default textShadowPlugin;
app.css
@import 'tailwindcss';
@plugin "./plugins/text-shadow.ts";

@theme {
	/* Text Shadow */
	--text-shadow-sm: 0 0px 2px var(--tw-shadow-color);
	--text-shadow: 0 0px 4px var(--tw-shadow-color);
	--text-shadow-lg: 0 0px 8px var(--tw-shadow-color);
	--tw-shadow-color: --alpha(oklch(0 0 0) / 50%);
}

DarthGigi avatar Mar 07 '25 15:03 DarthGigi

I had a similar issue so I just put it in @layer utilities which worked for me

@layer utilities {
  .text-shadow-none {
    text-shadow: 0 0px 0px var(--tw-shadow-color)
  }
  .text-shadow-sm {
    text-shadow: 0 1px 2px var(--tw-shadow-color);
  }
  .text-shadow {
    text-shadow: 0 2px 4px var(--tw-shadow-color);
  }
  .text-shadow-lg {
    text-shadow: 0 8px 16px var(--tw-shadow-color);
  }
  .text-shadow-xl {
    text-shadow: 0 10px 20px var(--tw-shadow-color);
  }
}

blaxtonj avatar Mar 13 '25 01:03 blaxtonj

I had a similar issue so I just put it in @layer utilities which worked for me

Does it work with [var(--color)]? For me

@layer utilities {
  .text-shadow-name {
    text-shadow: 0 0 4px var(--tw-shadow-color);
  }
}

works with text-shadow-name shadow-black and

@layer utilities {
  .text-shadow-name {
    text-shadow: 0 0 4px var(--tw-shadow);
  }
}

works with text-shadow-name shadow-shadow-[var(--color1)], but not other way around.

Image

nwsnws123 avatar Mar 13 '25 14:03 nwsnws123

looking through tailwind doc's it looks like it should be setup like this

   <p className="text-shadow-xl text-white shadow-(color:--color-primary)">
          Hello
        </p>

Image

but if your color is already in your theme you can do something like this


@theme {

  --color-primary: #10537c;

  }

   <p className="text-shadow-xl text-white shadow-primary">
          Hello
        </p>

Image

both seem to have the same effect

blaxtonj avatar Mar 13 '25 23:03 blaxtonj

Omg I thought I was going crazy. When I inspect my code, it gets weird.

In Safari (18.4), I get an issue like that where lines don't match up and the inspector shows classes that aren't even applied to the current element. lg:mr-32 is there, but mt-8 and text-sm is on the parent element, but not on the selected one.

Image

If I select the parent element, I get the same phenomenon as OP :

.lg\:text-lg {
width: calc(var(--spacing) * 30);
}

And in Chrome 134 on macos, nothing happens when I uncheck / check classes in the styles tab (there are no other classes or styles of lower specificity and no other classes showing for the element that could be conflicting - unchecking .mt-32 does nothing and no other class named like this is there. Tailwind is not applied twice and vite-plugin-inspect reveals nothing suspicious, the stylesheet seems to be generated proper. Is there a problem with dev sourcemapping?

Using Tailwind v4.0.14 and, in my case, without plugins. Unclear if it's my fault - because of my setup or not... 🤔 I'll try to create a reproduction later.

davidwebca avatar Mar 20 '25 03:03 davidwebca

Has this issue been fixed? I'm still seeing text-shadow-lg be represented as font-size in "tailwindcss": "^4.1.2",.

Image

fletch-r avatar Apr 04 '25 13:04 fletch-r

@fletch-r This seems to work fine in the play example: https://play.tailwindcss.com/ueFWkopNXX

Have you made sure you also updated @tailwindcss/vite or @tailwindcss/postcss (depending on what you're using)

philipp-spiess avatar Apr 04 '25 14:04 philipp-spiess

@philipp-spiess Looks like it was my @tailwindcss/postcss that was out of date. Thought it would auto-update/install everything related to tailwind by doing npm i tailwindcss. Thank you

fletch-r avatar Apr 04 '25 14:04 fletch-r

🐛 Bug Report: Custom utility class with text- prefix gets purged when used with other text-* classes

I'm experiencing an issue in Tailwind CSS v4.1.x where a custom utility class like text-small-semibold (defined in @layer utilities) is purged from the output CSS when used alongside other built-in text-* utilities such as text-white.


🧪 Reproduction Example

<!-- This is purged: only `text-white` and `bg-[#ff3b30]` are rendered -->
<span class="text-small-semibold text-white bg-[#ff3b30]">Text</span>

<!-- This renders correctly -->
<span class="text-small-semibold">Text</span>

gn753 avatar May 29 '25 02:05 gn753