Skip to content

Commit dc9e786

Browse files
thecrypticacephilipp-spiessWiicolas
authored
Add details about hidden attribute preflight rules (#2321)
In v4 we made a change that makes elements with a hidden attribute `display: none !important`. A consequence of this is that `<div hidden class="block">test</div>` will be invisible in v4 where it was visible in v3. The intent is that you must *remove* this attribute if the element isn't actually meant to be hidden but we didn't document this in the upgrade guide or the preflight page. Closes tailwindlabs/tailwindcss#18653 --------- Co-authored-by: Philipp Spiess <[email protected]> Co-authored-by: Nicolas <[email protected]>
1 parent c7dadc3 commit dc9e786

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/docs/preflight.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@ This prevents them from overflowing their containers and makes them responsive b
181181
<img class="max-w-none" src="..." alt="..." />
182182
```
183183

184+
#### Elements with a `hidden` attribute stay hidden
185+
186+
```css
187+
/* [!code filename:CSS] */
188+
[hidden]:where(:not([hidden='until-found'])) {
189+
display: none !important;
190+
}
191+
```
192+
193+
This enforces that elements with a `hidden` attribute stay invisible unless using `hidden="until-found"`. Remove the `hidden` attribute if you want an element to be visible to the user.
194+
184195
## Extending Preflight
185196

186197
If you'd like to add your own base styles on top of Preflight, add them to the `base` CSS layer in your CSS using `@layer base`:

src/docs/upgrade-guide.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,10 @@ If you still want dialogs to be centered by default, add this CSS to your projec
564564
}
565565
```
566566

567+
#### Hidden attribute takes priority
568+
569+
Display classes like `block` or `flex` no longer take priority over the `hidden` attribute on an element. Remove the `hidden` attribute if you want an element to be visible to the user. Note that this does not apply to `hidden="until-found"`.
570+
567571
### Using a prefix
568572

569573
Prefixes now look like variants and are always at the beginning of the class name:

0 commit comments

Comments
 (0)