0Pricing
CSS Academy · Lesson

Visibility vs Display None

Learn when to use visibility: hidden versus display: none and how each affects layout.

Visibility vs Display None is a free CSS Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Three Ways to Hide Elements

CSS provides three common methods to hide elements, each with different effects on layout, accessibility, and interaction:

  1. display: none
  2. visibility: hidden
  3. opacity: 0

display: none

The element is completely removed from layout. It occupies no space, is not interactive, and is not read by screen readers (for most implementations). The element still exists in the DOM.

.hidden {
  display: none;
  /* element disappears from layout */
}

visibility: hidden

The element is invisible but still occupies space in the layout. It cannot be clicked and is not read by screen readers. Good for hiding something without causing layout shifts.

.invisible {
  visibility: hidden;
  /* space is preserved, element is invisible */
}

opacity: 0

The element is invisible but fully interactive. It still occupies space and responds to events (clicks, hovers). Screen readers may still read it.

.transparent {
  opacity: 0;
  /* invisible, still clickable */
}

visibility: visible Override

A child element can override a parent's visibility: hidden by setting visibility: visible. This is not possible with display: none — children inherit it absolutely.

.parent { visibility: hidden; }
.child  { visibility: visible; } /* this works! */

Comparison Table

Quick reference:

  • display: none: no space, no clicks, not read
  • visibility: hidden: takes space, no clicks, not read
  • opacity: 0: takes space, still clickable, may be read

Transitioning Visibility

display cannot be transitioned. To fade elements in/out, combine visibility with opacity:

.dropdown {
  opacity: 0;
  visibility: hidden;
  transition: opacity 300ms, visibility 300ms;
}

.dropdown.open {
  opacity: 1;
  visibility: visible;
}

Accessible Hiding with SR-only

The screen-reader only pattern hides content visually but keeps it accessible to assistive technology:

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

hidden Attribute vs CSS

The HTML hidden attribute applies display: none via the browser's user-agent stylesheet. It is accessible and semantic but can be overridden by CSS specificity.

<div hidden>This is hidden</div>

content-visibility

content-visibility: hidden skips rendering of off-screen sections but preserves their accessibility tree and layout. A modern performance technique for long pages.

.offscreen-section {
  content-visibility: auto;
  contain-intrinsic-size: 0 500px;
}

pointer-events: none

To keep an element visible but non-interactive, use pointer-events: none. Clicks and hovers pass through the element to elements beneath it.

.overlay {
  pointer-events: none;
}

Quick Check

Which technique hides an element while preserving the layout space it occupies?

Recap

display: none removes an element from layout entirely. visibility: hidden hides it while preserving space. opacity: 0 hides it but keeps it interactive. For accessible hiding, use the .sr-only pattern. Combine visibility + opacity for fade transitions.

Frequently asked questions

Is the “Visibility vs Display None” lesson free?

Yes — the full text of “Visibility vs Display None” is free to read here on the web, and the CSS Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO.

What will I learn in “Visibility vs Display None”?

Learn when to use visibility: hidden versus display: none and how each affects layout. You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CSS Academy?

No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Visibility vs Display None” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CSS Academy lesson?

Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Block vs Inline vs Inline-Block
  2. Visibility vs Display None
  3. Overflow: Scroll Clip and Auto
  4. CSS Reset and Normalize
← Back to CSS Academy