CSS DISPLAY /// BLOCK /// INLINE /// INLINE-BLOCK /// VISIBILITY HIDDEN /// DISPLAY NONE /// CSS DISPLAY /// BLOCK ///

Display & Visibility

Control the document flow. Master how elements stack, sit side-by-side, or completely vanish from your layouts.

layout.css
1 / 14
12345
📦

Tutor:Every element in HTML is essentially a rectangular box. The 'display' property determines how this box behaves in the document flow.


Layout Matrix

UNLOCK NODES BY MASTERING THE DOCUMENT FLOW.

Concept: Block vs Inline

Block elements clear their surroundings and take full width. Inline elements hug their content.

System Check

Which property values are ignored by a pure `display: inline` element?


Community Holo-Net

Share Layout Tricks

ACTIVE

Mastered the dark art of centering divs? Share your codepens and get feedback from peers!

CSS Display & Visibility: Controlling the Flow

Frontend Instructor in Code Syllabus

Pascual Vila

Frontend Instructor // Code Syllabus

The layout of the entire web relies on how elements interact with each other. By mastering the display property, you take total control over whether elements stack like bricks or flow like text.

The Foundation: Block vs Inline

Every HTML element has a default display value depending on its semantic purpose. Understanding the difference between Block and Inline is the first step in CSS layout.

Block elements (like <div>, <p>, <h1>) always start on a new line and stretch to take up the full width available to them. Think of them as stacked wooden blocks.

Inline elements (like <span>, <a>, <strong>) do not start on a new line. They flow alongside text and only take up as much width as necessary. Crucially, they ignore width, height, and vertical margins.

The Hybrid: Inline-Block

Sometimes you need elements to sit next to each other (like inline), but you also want to give them specific widths, heights, and padding (like block). This is where display: inline-block; shines.

Before Flexbox and Grid became standard, inline-block was the primary way developers created multi-column layouts and navbars!

The Vanishing Act: None vs Hidden

There are two main ways to hide an element with CSS, and they behave very differently in the document flow:

  • display: none;: The element is completely removed from the visual page flow. It's as if the element doesn't exist. Other elements will collapse and fill the space it left behind.
  • visibility: hidden;: The element becomes invisible, but it still takes up its original space. It leaves a "hole" or blank gap in your layout.
View Accessibility Tip+

Screen Readers and Hiding: Both display: none and visibility: hidden will hide content from screen readers. If you want to visually hide something but keep it accessible for visually impaired users (like a skip link), you should use a utility class (often called .sr-only) that uses absolute positioning and zero-clipping instead!

Frequently Asked Questions

Why does my `span` element ignore width and margin-top?

Because <span> elements have display: inline; by default. Inline elements are designed to flow with text, so the browser ignores their dimension properties (width, height) and vertical margins to avoid breaking the text line height.

Solution: Change the element to display: inline-block; or display: block; depending on whether you want it to stay on the same line or wrap to the next.

What's the main difference between display: none and visibility: hidden?

display: none; completely removes the element from the document flow. The space it occupied disappears and other elements shift to fill the gap.

visibility: hidden; makes the element transparent/invisible, but the browser still reserves its exact space (width and height). You'll see a blank "hole" in your layout.

What happens if I animate display: none with a transition?

The display property is not animatable with CSS transitions. If you try to fade out by changing from block to none, the element will disappear instantly.

To animate an element disappearing, you must transition the opacity property from 1 to 0, and then use JavaScript (or certain advanced CSS techniques) to change display to none once the transition completes.

Layout Glossary

display: block
Takes up the full width available and starts on a new line. Allows width, height, margin, and padding.
snippet.css
display: inline
Takes only necessary width. Flows with text. Ignores width, height, and top/bottom margins.
snippet.css
display: inline-block
Sits inline with other elements but respects width, height, and margins like a block element.
snippet.css
display: none
Completely removes the element from the document flow. No space is reserved.
snippet.css
visibility: hidden
Makes the element invisible but it continues to occupy its original layout space.
snippet.css
visibility: visible
The default state. The element is visible and rendered normally in the document.
snippet.css