Today I Learned - Rocky Kev

TIL HTML's native hidden attribute

POSTED ON:

TAGS:

To hide a DOM element: there's a native HTML attribute called hidden.

The effect is similar to adding a style display: none;.

The hidden attribute must not be used to hide content just from one presentation. If something is marked hidden, it is hidden from all presentations, including, for instance, screen readers.


<p hidden>This content is not relevant to this page right now, so should not be seen. Nothing to see here. Nada.</p>

Heads up:

Changing the value of the CSS display property on an element with the hidden attribute overrides the behavior. For instance, elements styled display: flex will be displayed despite the hidden attribute's presence.

Via the MDN:
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden


Related TILs

Tagged:

TIL Gmail has a 102KB size-limit for HTML

PLACEHOLDER

TIL how Error correction works in HTML

You never get an 'Invalid Syntax' error on an HTML page. Browsers fix any invalid content and go on.

TIL what DOCTYPE means

tl;dr: DOCTYPE declaration in the first line of the HTML file, to instruct the browser to run the code in Standard mode.