[v4] How to use fade in/out transition from the hidden
attribute?
#18394
-
Hello, thank you for your work on TailwindCSS! I’ve been enjoying using the https://codepen.io/hiroya_uga/pen/XJbORXP .toast {
transition:
opacity 0.3s ease-out,
visibility 0.3s ease-out;
}
.toast[hidden] {
display: block;
opacity: 0;
visibility: hidden;
pointer-events: none;
} However, in TailwindCSS v4, I noticed the following rule in the base layer: [hidden]:where(:not([hidden="until-found"])) {
display: none !important;
} Because this As a workaround, I’m currently overriding the style like this: @layer base {
.no-hidden {
display: block !important;
}
} <div className="no-hidden" hidden /> or // React
ref.current.style.setProperty('display', 'block', 'important'); Is there a way to achieve this fade in/out transition using only TailwindCSS, without needing to manually override the Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
For fade in, you can use |
Beta Was this translation helpful? Give feedback.
-
To apply a fade-in/out effect when toggling the hidden attribute, you'll need to use CSS transitions combined with opacity and visibility instead of directly relying on the hidden attribute, since hidden instantly removes the element from rendering and doesn’t allow transitions.
This is one way you can maintain the fade-in/out transition while still hiding the element visually and semantically. |
Beta Was this translation helpful? Give feedback.
-
Thank you everyone, I'll follow progressive enhancement to use |
Beta Was this translation helpful? Give feedback.
For fade in, you can use
@starting-style
via thestarting
variant. For fade out, you can usetransition-behavior: allow-discrete
. However, this fade out does not work in Firefox due toallow-discrete
not working fordisplay: none
.https://codepen.io/Wongjn/pen/JodxJyR