---
title: "Let the hidden attribute always hide · Agent Wranglers"
url: https://agentwranglers.se/playbook/html-css/naming-and-state/hidden-attribute-wins
id: CSS-36
level: Recommended
updated: 2026-10-22
build: a2a6bdfed830
tokens: 953
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Let the hidden attribute always hide

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Naming and state](https://agentwranglers.se/playbook/html-css/naming-and-state.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: CSS-36
- Level: Recommended
- Chapter: [Naming and state](https://agentwranglers.se/playbook/html-css/naming-and-state.md)
- Rule: Make the `hidden` attribute hide an element whatever its classes set. One rule in the utilities layer gives `[hidden]` the value `display: none !important`, except `hidden="until-found"`.
- Check: A browser test sets `hidden` on the root of every component in the catalogue and reads its computed `display`. Every one is `none`.
- How: The browser hides `hidden` elements through its own stylesheet, so any author rule that sets `display` beats it. A component root with `display: flex` then stays on screen after a script sets `hidden`. A dismissed message or a closed panel never goes away. The utilities layer is the one place `!important` may appear, as [Keep !important inside the utilities layer](https://agentwranglers.se/playbook/html-css/the-cascade/important-only-in-utilities.md) says. Leave out `until-found`, because the browser keeps that content in the page with `content-visibility: hidden` so find-in-page can reach it. Toggling `hidden` is one of the states from [Show state through attributes](https://agentwranglers.se/playbook/html-css/naming-and-state/state-in-attributes.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### CSS example

```css
/* utilities/hidden.css */
[hidden]:not([hidden="until-found" i]) {
  display: none !important;
}
```

### JavaScript example

```js
// Browser test with Playwright: every component root obeys hidden
for (const root of await page.locator('[data-catalogue] > *').all()) {
  await root.evaluate(element => { element.hidden = true; });
  expect(await root.evaluate(element => getComputedStyle(element).display)).toBe('none');
}
```

### Python example

```python
# The same test with Playwright for Python
for root in page.locator("[data-catalogue] > *").all():
    root.evaluate("element => { element.hidden = true }")
    assert root.evaluate("element => getComputedStyle(element).display") == "none"
```

## Sources

- [HTML Standard on the hidden attribute](https://html.spec.whatwg.org/multipage/interaction.html#the-hidden-attribute)
- [HTML Standard on hidden elements](https://html.spec.whatwg.org/multipage/rendering.html#hidden-elements)

## Related rules

- CSS-9 [Keep !important inside the utilities layer](https://agentwranglers.se/playbook/html-css/the-cascade/important-only-in-utilities.md) in HTML and CSS
- CSS-15 [Show state through attributes](https://agentwranglers.se/playbook/html-css/naming-and-state/state-in-attributes.md) in HTML and CSS

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/html-css/naming-and-state/hidden-attribute-wins">Agent Wranglers HTML and CSS playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Show state through attributes](https://agentwranglers.se/playbook/html-css/naming-and-state/state-in-attributes.md)
- Next: [Select elements by their own class](https://agentwranglers.se/playbook/html-css/naming-and-state/no-position-selectors.md)
- [Naming and state](https://agentwranglers.se/playbook/html-css/naming-and-state.md)
