Home > Web Front-end > H5 Tutorial > body text

hidden boolean attribute in html5

黄舟
Release: 2017-11-03 11:45:31
Original
2892 people have browsed it

Example

Hidden paragraph:

<p hidden>这个段落应该被隐藏。</p>
Copy after login

Browser support


IE

Firefox

Chrome

Safari

Opera

All major browsers support the hidden attribute, except Internet Explorer.

Definition and usage

The hidden attribute is a Boolean attribute.

If this attribute is set, it specifies that the element is still or no longer relevant.

Browsers should not display elements that have the hidden attribute specified. The

hidden attribute can also be used to prevent the user from viewing an element until certain conditions are matched (such as a certain checkbox being selected). JavaScript can then remove the hidden attribute to make this element visible.

Differences between HTML 4.01 and HTML5

The hidden attribute is new in HTML5.

Differences between HTML and XHTML

In XHTML, attribute abbreviations are prohibited, and the hidden attribute must be defined as

Syntax

<element hidden>
Copy after login

HTML5 brings us many very simple but very powerful HTML attributes: placeholder, download, and autofocus, etc. Another new attribute is the hidden attribute. When a web page element has the hidden attribute, its behavior is very similar to CSS' display: none;. The element will disappear without occupying any page space. The writing method is very simple:

<div hidden>
	You can&#39;t see me!</div>
Copy after login

If you are using an old browser that does not support this attribute, you can add the following code to CSS to support it: :

*[hidden] { display: none; }
Copy after login

So, why? What about using the hidden attribute? The meaning is that it is more semantically meaningful and improves the readability of the code. And compared to display:none in CSS, it’s literally simpler!


The above is the detailed content of hidden boolean attribute in html5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!