{"id":1842,"date":"2016-06-15T14:12:46","date_gmt":"2016-06-15T19:12:46","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=1842"},"modified":"2016-06-15T14:12:46","modified_gmt":"2016-06-15T19:12:46","slug":"css-visibility-hidden-vs-display-none","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/css-visibility-hidden-vs-display-none\/","title":{"rendered":"CSS visibility: hidden vs. display: none"},"content":{"rendered":"<p>At first glance it might seem like CSS&#8217;s display: none rule and it&#8217;s visibility: hidden rule have the exact same function, but that&#8217;s not entirely accurate. While it&#8217;s true that both rules render an HTML tag invisible, they do so in different ways.<\/p>\n<p>Display: none completely strips an element from the page. This means that if you apply display: none to an element, it won&#8217;t appear on your website and there will be no visible evidence of it ever having existed &#8212; meaning that the surrounding elements will treat the element as empty space and adapt accordingly.<\/p>\n<p>Visibility: hidden simply hides an element from the page, while still rendering the tag in the viewport. This means that even though the element is invisible, there is still space allocated for it on the page, and the surrounding HTML elements will respect that space.<\/p>\n<p>These concepts are probably best explained visually. For an example, let&#8217;s use a standard contact form, like this one:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-1843 aligncenter\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2016\/06\/Screen-Shot-2016-06-15-at-3.07.47-PM.png\" alt=\"Screen Shot 2016-06-15 at 3.07.47 PM\" width=\"363\" height=\"146\" \/><\/p>\n<p>If we set display: none to that first input field, it would look like this:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-1844 aligncenter\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2016\/06\/Screen-Shot-2016-06-15-at-3.08.03-PM.png\" alt=\"Screen Shot 2016-06-15 at 3.08.03 PM\" width=\"376\" height=\"110\" \/><\/p>\n<p>If we set the input field to visibility: hidden, it would look like this:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-1845 aligncenter\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2016\/06\/Screen-Shot-2016-06-15-at-3.08.24-PM.png\" alt=\"Screen Shot 2016-06-15 at 3.08.24 PM\" width=\"373\" height=\"151\" \/><\/p>\n<p>The difference here is pretty clear. Visibility: hidden hides the element from view while still allocating space for it on the page, while display: none makes the element entirely invisible and leaves no trace of it behind.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>At first glance it might seem like CSS&#8217;s display: none rule and it&#8217;s visibility: hidden rule have the exact same function, but that&#8217;s not entirely accurate. While it&#8217;s true that both rules render an HTML tag invisible, they do so [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/css-visibility-hidden-vs-display-none\/\" title=\"Click to read 'CSS visibility: hidden vs. display: none'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":2745,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[173,174,175],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1842"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=1842"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1842\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/2745"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=1842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=1842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=1842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}