How to Hide an Element with the hidden Attribute in HTML
Add hidden to any element and the browser doesn't show it. The element stays in the page's code, so a script can show it later, but until then nobody sees it, including people who use screen readers.
Syntax
<element hidden><content></element>
| Part | What it does |
|---|---|
element | The tag name of any element, such as p or div. |
hidden | Hides the element. It needs no value. |
<content> | What's inside the element. It's hidden with it. |
MDN's hidden page describes the attribute, which works on every element.
The Example
The example is an order status page with two messages, Your order is on its way and Your order was cancelled. The second one has hidden, so only the first one shows.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Order status</title>
</head>
<body>
<h1>Order status</h1>
<p>Your order is on its way.</p>
<p hidden>Your order was cancelled.</p>
</body>
</html>
Step 2: Open It in a Browser
Double-click index.html. It opens in your browser:

The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.
What Happened
- The cancelled message isn't on the screen: Chromium gave it
display: none, so it takes up no space either. - It's still in the page: the paragraph and its text were in the page's code, ready to be shown.
- Screen readers skip it too. Chromium's accessibility tree, the information screen readers use, had the heading and the first message, but nothing from the hidden one.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
A CSS rule that sets display on the element, such as p { display: block; } | It shows anyway: the CSS rule overrides hidden, and both messages appeared | Don't set display on elements you hide, or add [hidden] { display: none; } to your CSS: with that rule added, the message was hidden again |
Writing hidden="false" to show the element | It stays hidden: the attribute hides the element whatever its value is | Remove the attribute |
Using hidden for something secret | The text is still in the page's code, where anyone can read it | Leave secret data out of the page |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
An element with hidden still shows | A CSS rule sets its display | Remove that rule, or add [hidden] { display: none; } |
| An element never shows | It has hidden, maybe with a value such as false | Remove the attribute |
FAQ
How do I show the element again?
Remove the attribute, or have a script set the element's hidden property to false. A script that did that removed the attribute, and the message's display went from none to block.
What's the difference between hidden and display: none?
For the browser they look the same, because hidden gets display: none from the browser's own styles. The difference is where it's set: hidden is part of the HTML, display is CSS, and a CSS rule that sets display wins.
Does a hidden element take up space?
No. It's taken out of the layout, so the elements after it move up.
Conclusion
hidden hides an element with nothing but HTML, from the screen and from screen readers, while keeping it in the page for later. If an element with hidden still shows, look for a CSS rule that sets its display.
Additional Resources
- hidden global attribute, on MDN.
