Coding/Learn/css/display property
CSS Beginner Course
01.Introduction to CSS
02.Selectors (Element, Class & ID)
03.3 Ways to Add CSS to HTML
04.Colors & Backgrounds (HEX, RGB, HSL)
05.Typography & Fonts (font-size, font-weight, line-height)
06.The Cascade & Specificity Wars
07.The Sacred CSS Box Model
08.Padding vs Margin & Shorthand Notation
09.Borders & Border Radius (Rounded Corners & Circles)
10.The Magic of box-sizing: border-box
11.Sizing & Units (px, rem, em, %, vh, vw)
12.The Display Property (block, inline, inline-block, none)
13.Flexbox Part 1: Container Powers (justify, align, gap)
14.Flexbox Part 2: Direction, Wrapping & Item Powers
15.Positioning (relative, absolute, fixed, sticky)
16.Z-Index & The 3D Stacking Context
17.Pseudo-Classes (:hover, :active, :focus, :first-child)
18.Smooth Transitions & Box Shadows
19.Responsive Design & Media Queries (@media)
20.Capstone: Crafting a Modern UI Profile Card
Course Certificate0%

Complete all lessons to earn

LearnThe Display Property (block, inline, inline-block, none)
12 / 20 0%
Lesson 12 of 20
5 mins read

The Display Property (block, inline, inline-block, none)

PreviousNext Lesson
In Plain English

The display property is the master switch that controls how an element behaves in the layout flow. You can turn an inline link into a block button, place blocks side-by-side with inline-block, or hide elements completely from the DOM flow with display: none.

The Mental Model

"display: block is like claiming an entire park bench for yourself. display: inline is squeezing onto the bench shoulder-to-shoulder with others. display: none is becoming an invisible ghost."

Deep Dive: How It Works

display: block: Takes up 100% width, starts on a new line, respects width, height, padding, margin.

display: inline: Flows inside text sentences (like <span> or <a>). Ignores vertical width, height, and vertical margins!

display: inline-block: Sits side-by-side like inline text, BUT respects width, height, and vertical padding/margins! (The classic button display mode).

display: none vs visibility: hidden: display: none removes the element from layout space completely; visibility: hidden makes it invisible but preserves the blank gap.

Syntax Blueprint

/* Turn <a> tag into a clickable button with width and padding */
.btn {
  display: inline-block;
  padding: 8px 16px;
}

/* Hide element */
.hidden {
  display: none;
}

Use inline-block for buttons and display: none to toggle visibility.

PointCore Rules to Remember

Point star
inline-block for Buttons: Allows <a> and <span> to accept custom padding, height, and width while sitting inline.
Point star
display: none Collapses Space: Leaves zero blank space on screen when hidden.
Point star
Inline Ignores Top/Bottom Margins: Never try to set margin-top on plain <span>—use inline-block instead.

Common Beginner Traps & How to Fix Them

Mistake:Trying to set width: 200px on a <span> or <a> without inline-block

Why it happens: Inline elements by specification ignore explicit width and height properties.

How to fix: Add display: inline-block; or display: block;.

Pro Tip: In modern CSS, display: flex and display: grid are the ultimate successors for complex multi-column layouts!

Live Interactive Example

Hit Run Code to see it live
Inline-Block Buttons and Toggled Display
CSS3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Live Browser Preview
Click "Preview / Apply" to view the rendered output.
How it works: inline-block allows buttons to sit next to each other while respecting padding and margins.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Convert a link to an inline-block button

  • PointWrite a CSS rule for .btn-link setting display: inline-block; and padding: 10px 20px;
1
2
Browser Preview & Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates