Skip to content

bug: @apply btn btn-primary inside @layer base is overridden by Tailwind preflight (sublayer base.daisyui has lower priority) #4812

Open

Description

@Predota

Reproduction URL (Required)

https://play.tailwindcss.com/tr1t08Ts6q

What version of daisyUI are you using?

5.7.50

Which browsers are you seeing the problem on?

Chrome

Describe your issue

When daisyUI classes are used with @apply inside @layer base, the resulting styles are placed in a nested sublayer (base.daisyui). Under CSS cascade layer rules, styles declared directly in a parent layer beat styles in its nested sublayers, so Tailwind's preflight (declared in base) overrides the daisyUI styles regardless of specificity or source order.

I reproduced this with btn btn-primary. I haven't tested other daisyUI classes, so I don't know whether the problem is specific to some classes or affects all of them.

Activity

  1. github-actions commented on Oct 14, 2026

    @github-actions

    Thank you @Predota for reporting issues. It helps daisyUI a lot 💚
    I'll be working on issues one by one. I will help with this one as soon as a I find a solution.
    In the meantime providing more details and reproduction links would be helpful.

  2. pdanpdan commented on Oct 14, 2026

    @pdanpdan
    Contributor

    Neither daisyui not tailwind promote the use of complex classes using @apply.
    The mechanism to use @apply works like this - it includes the rules to be applied in the place where the @apply rule is present.
    But what is the point of what you are doing, maybe there is a simple normal solution?
    If you want to just create shortcuts then put them in the components layer which is between base and utility

  3. Predota commented on Oct 15, 2026

    @Predota
    Author

    The goal is to define overridable defaults for buttons, links, etc. This use case was supported before 5.3.0.

    Working (pre-5.3.0): https://stackblitz.com/edit/daisyui5-jmumostu

    Moving the rule to @layer components works as a workaround, but then the defaults are no longer overridable by other base-level rules, which was the point of putting them in base.

  4. pdanpdan commented on Oct 15, 2026

    @pdanpdan
    Contributor

    the order is:

    • base
    • components
    • utilities

    you can overwrite them if you want like in https://play.tailwindcss.com/hxQ4G3TuIZ

  5. Predota commented on Oct 15, 2026

    @Predota
    Author

    Thanks, I know the components layer works. My point is that defining overridable defaults for elements (buttons, links, etc.) in base was supported before 5.3.0 and no longer is. Was that change intentional?

  6. pdanpdan commented on Oct 15, 2026

    @pdanpdan
    Contributor

    It was never supposed to be used like that.

  7. Predota commented on Oct 15, 2026

    @Predota
    Author

    To be clear on the scope: is @apply of daisyUI classes (e.g. @apply btn btn-primary) in @layer components supported, or is @apply of daisyUI classes not supported at all?

  8. pdanpdan commented on Oct 15, 2026

    @pdanpdan
    Contributor

    From my pov it is not supported neither by tailwind nor by daisyui, except for simple utilities.
    tailwindlabs/tailwindcss#7651

    But it probably works on condition that:

    • you use it in the components layer (so that it can be overridden by utilities)
    • you check that all interactions work as expected

    The normal design is to create components that apply the desired classes.

  9. Predota commented on Oct 15, 2026

    @Predota
    Author

    Ok, it felt like a regression to me. I'll go a different route.

  10. pdanpdan commented on Nov 15, 2026

    @pdanpdan
    Contributor

    i think this can be closed - the daisyui sublayer is a design decision needed to allow tailwind utilities to have priority, and tailwind addComponents does not add to components layer but to utilities layer (so there is no way to place css in components layer from plugin)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions