What is difference between Display vs. Visibility properties?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
visibilityproperty only tells the browser whether to show an element or not. It’s either visible (visible– you can see it), or invisible (hidden– you can’t see it).The
displayproperty tells the browser how to draw and show an element, if at all – whether it should be displayed as aninlineelement (i.e. it flows with text and other inline elements) or ablock-level element (i.e. it has height and width properties that you can set, it’s floatable, etc), or aninline-block(i.e. it acts like a block box but is laid inline instead) and some others (list-item,table,table-row,table-cell,flex, etc).When you set an element to
display: blockbut also setvisibility: hidden, the browser still treats it as a block element, except you just don’t see it. Kind of like how you stack a red box on top of an invisible box: the red box looks like it’s floating in mid-air when in reality it’s sitting on top of a physical box that you can’t see.In other words, this means elements with
displaythat isn’tnonewill still affect the flow of elements in a page, regardless of whether they are visible or not. Boxes surrounding an element withdisplay: nonewill behave as if that element was never there (although it remains in the DOM).