Performance: Hidden and visibility control
Controls how elements appear or disappear on the page, affecting rendering and layout stability.
Jump into concepts and practice - no test required
<div class="invisible">Content</div><div class="hidden">Content</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| hidden (display:none) | Element removed from layout | Triggers 1 reflow | Paint cost reduced (not painted) | [X] Bad |
| invisible (visibility:hidden) | Element remains in layout | No reflow | Paint cost for invisible element | [OK] Good |
hidden do to an element?hidden class effecthidden class in Tailwind CSS sets display: none;, which hides the element completely.hidden = hides + removes space [OK]invisible class sets visibility: hidden;, which hides the element but keeps its space.hidden removes element and space, opacity-0 makes element transparent but still interactive, sr-only hides visually but accessible to screen readers.invisible = hide but keep space [OK]<div class="w-24 h-24 bg-blue-500 hidden">Box</div> <div class="w-24 h-24 bg-red-500 invisible">Box</div>
hiddenhidden, so it is not visible and its space is removed from layout.invisiblehidden removes element; invisible hides but keeps space [OK]sr-only hides the element visually but keeps it readable by screen readers, unlike hidden or invisible.sr-only = hide visually, keep screen reader access [OK]hidden hides element by default (mobile), md:block shows element as block on medium screens and larger.invisible md:hidden hides but keeps space on mobile and hides on medium, so menu never visible. block md:hidden shows on mobile but hides on medium, opposite of requirement. hidden md:hidden hides always.