Picture this:
You're working on a painting with a white background, meticulously adding intricate details to an apple over the course of an hour. Then, you cover it all up with another layer of white paint.
That's what visibility
is like.
display:none
is akin to never starting the painting at all. It may be quicker to load initially.
However, using display:none
has its drawbacks: when switching back to block
(or inline
, etc.), you have to start from scratch on the painting. With visibility, the browser simply removes that last coat of paint and everything is back as before. In this case, visibility
is faster.
Just keep in mind that when you use visibility:hidden
, the element maintains its position in the layout, so the surrounding elements remain unaffected.
If you want a more technical explanation, check out David Baron's talk.