LESSON 7.2
Making Elements Disappear with CSS
Hide elements from the page without deleting them from your HTML
Learn how display: none removes elements from the layout entirely, why you would want to hide something, and how it differs from visibility: hidden.
๐ก The Concept
In the previous lesson on The Display Property, you worked with display: block, display: inline, and display: inline-block. This lesson covers one more value: display: none, which removes an element from the layout completely. It takes up no space and is invisible to the user, as if it were not in the HTML at all.
.hidden {
display: none;
}
Why Would You Hide an Element?
It might seem odd to add something to your HTML and then hide it, but there are practical reasons to do this:
- Responsive design. You might want certain elements to show on desktop but hide on mobile, or vice versa. You can use a media query to apply
display: noneat certain screen sizes. - Working in a CMS. When using WordPress or another content management system, you may not have access to edit the HTML directly, but you can still add CSS. If a section of the page is generated by the CMS and you do not want it to show,
display: nonemakes it disappear. - JavaScript show/hide. Many interactive effects work by toggling
display: noneon and off with JavaScript, such as dropdown menus, modals, and accordion panels.
display: none vs. visibility: hidden
These two properties both hide an element, but they behave differently:
display: noneremoves the element from the layout completely. No space is reserved for it.visibility: hiddenhides the element visually but keeps its space in the layout. A blank gap remains where the element would have been.
/* Removes the element and its space */
.gone {
display: none;
}
/* Hides the element but keeps the space */
.invisible {
visibility: hidden;
}
๐ฌ Video Demonstration
This video covers the display property including how to use display: none to hide elements.
Exercise: Try It Yourself
Step 1. Open your JSFiddle from the previous lesson if you still have it. If not, open a new JSFiddle and add this starting code:
<h1>Slow Like a Sloth</h1>
<img src="https://webdevstudents.com/wp-content/uploads/2025/09/sloth.png" width="200" height="200" alt="sloth in a tree">
Step 2. In your CSS, add display: none to the img and run it. The image disappears completely and the heading is all that remains.

Step 3. Change it to visibility: hidden instead and run it again. The image is invisible but the space it occupied is still there โ notice the gap next to the heading.
โ Frequently Asked Questions
It can. Search engines can read hidden content, and Google has historically treated content hidden with display: none with some skepticism โ particularly if it looks like the content is being hidden from users but shown to search engine crawlers, which is a deceptive practice. For legitimate uses like responsive layouts (hiding a mobile menu on desktop) or JavaScript-driven interactions, it is generally fine. The key is that the hidden content should serve the user, not just the search engine.
opacity: 0 makes an element fully transparent but it still occupies space in the layout and can still receive mouse clicks โ users just cannot see it. display: none removes the element from the layout entirely, taking up no space and receiving no interaction. visibility: hidden is in between: the element is invisible and cannot be interacted with, but it still holds its space. Each has its use depending on whether you need the space preserved and whether the element should remain interactive.
Set display back to its appropriate value โ usually display: block for block-level elements or display: inline for inline elements. In CSS you might do this with a class toggle: start with display: none in one rule, then override it with display: block in another rule that applies under certain conditions (like a media query or a JavaScript-added class). This on/off pattern is the foundation of most show/hide interactions on the web.
Yes, and this is one of the most practical uses of display: none. On a small screen you may not have room for decorative sidebar images or large feature photos that work well on desktop. By combining display: none with a media query, you can hide those images on mobile and show them only on larger screens. A media query is a CSS rule that applies only when the screen meets certain conditions, such as being wider than a certain number of pixels. Media queries are covered in a later lesson. For now, the key idea is that display: none is the tool you reach for when something should exist in the HTML but not appear in certain situations.
Use visibility: hidden when you want the element to remain invisible but still hold its space in the layout โ for example, keeping a row of buttons the same width even when one is hidden, so the other buttons do not shift. Use display: none when you want the element completely gone and the surrounding content to reflow as if it were never there. In practice, display: none is more commonly used because the reflow behavior is usually what you want.
โ Key Takeaways
Sometimes you want an element to take up space but be invisible. Other times you want it completely removed from the layout. This lesson covered display: none and visibility: hidden and explained when to use each one. Next, you will dig into the CSS box model and padding, which is the foundation for understanding how every element takes up space.
Google Ads
The costs of this website are partially offset by revenue from Google Ads.Tools of the Trade
HTML/CSS Lessons
-
-
-
1.3. HTML Tag Preview
-
-
-
2.2. The HTML Framework
-
-
2.4. HTML Headings
-
-
-
-
-
-
3.01. Introduction to CSS
-
3.02. How CSS Cascades
-
-
-
-
3.05. CSS Colors
-
3.06. RGBA Colors
-
-
3.08. Font and Text Properties
-
3.09. Classes and IDs
-
-
-
-
-
4.3. HTML Embedded Images
-
-
-
-
-
-
5.1. CSS Borders
-
5.2. CSS Border Radius
-
5.3. CSS Gradients
-
5.4. CSS Box Shadows
-
5.5. CSS Text Shadows
-
7.1. The Display Property
-
-
-
7.4. The Box Model
-
-
-
-
-
-
9.1. Website Tables
-
9.2. HTML Forms
-
-
9.4. Special Form Fields
-
9.5. Embedding Multimedia
-
-
9.7. Keyboard Shortcuts
-
10.1. What Is a Framework?
-
10.2. Font Awesome Icons
-
-
10.4. Bootstrap Grid System
-
-
10.6. Bootstrap Navigation
-
-
11.2. Purchasing a Domain Name
-
11.3. Website Hosting
-
11.4. Nameservers and DNS
-
11.5. FTP
-
11.6. GitHub Pages
