hidden

The hidden attribute in HTML conceals an element from view and makes it inaccessible to users and assistive technologies, while still keeping it in the DOM.

hidden Attribute

The hidden attribute in HTML is used to hide elements that are not currently needed or relevant. While the element remains in the DOM, it is not displayed in the browser or accessible to users, including screen readers.

Syntax

index.html
<element hidden>

Example

A hidden paragraph:

This paragraph is visible.

index.html
<p hidden>This paragraph is hidden.</p>  
<p>This paragraph is visible.</p>

Definition and Usage

The hidden attribute is a boolean attribute that prevents an element from being displayed. Even though hidden elements are not visible, they remain part of the HTML structure. This attribute is commonly used to temporarily hide content until triggered by an event, such as user interaction, where JavaScript can remove the attribute to reveal the element.

Applies To

The hidden attribute is a global attributes and can be used on any HTML element.

ElementAttribute
All HTML elementshidden

Conclusion

The hidden attribute is a simple yet effective way to control content visibility while keeping elements in the document structure. It is particularly useful for managing dynamic content, allowing elements to be shown or hidden as needed using JavaScript.