Display Properties
display decides how an element behaves in the layout: does it start a new line, can it have a width, is it shown at all? It is the switch between all CSS layout modes.
On this page · 5 min · Beginner
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Beginner
- Updated
- Oct 28, 2026
Learning objectives#
- Explain block, inline and inline-block
- Hide elements with display: none vs visibility: hidden
- Know that flex and grid are display values
- Change an element’s default display
Explanation#
block: starts on a new line and takes the full width. Width, height, margin and padding all work. Default for div, p, h1, ul.
inline: flows in a line of text. Width and height are ignored and vertical margins do nothing. Default for span, a, strong.
inline-block: sits in a line like inline, but accepts width, height and vertical padding like block. Great for buttons and badges.
none: removes the element completely — no space is kept. visibility: hidden makes it invisible but keeps its space.
flex and grid turn an element into a layout container for its children — covered in the Flexbox and Grid lessons.
Code example: Comparing display values#
<style>
body { font-family: sans-serif; }
.box { background: #dbeafe; border: 1px solid #2965f1; margin: 4px; padding: 6px; width: 120px; }
.block { display: block; }
.inline { display: inline; }
.ib { display: inline-block; }
.gone { display: none; }
.hidden { visibility: hidden; }
</style>
<p><b>block</b> (new line, width works):</p>
<span class="box block">A</span><span class="box block">B</span>
<p><b>inline</b> (same line, width ignored):</p>
<div class="box inline">A</div><div class="box inline">B</div>
<p><b>inline-block</b> (same line, width works):</p>
<span class="box ib">A</span><span class="box ib">B</span>
<p><b>none vs hidden</b>:</p>
<span class="box ib">1</span><span class="box ib gone">2</span><span class="box ib">3</span><br>
<span class="box ib">1</span><span class="box ib hidden">2</span><span class="box ib">3</span>
Block boxes stack vertically at 120px; inline boxes sit on one line ignoring width; inline-block boxes sit side by side at 120px. With none, box 2 vanishes; with hidden, an empty gap remains.
Step-by-step explanation#
- Spans with display: block stack like divs.
- Divs with display: inline lose their width and sit in a line.
- inline-block gives you both: side by side and sized.
- display: none removes box 2 so 1 and 3 touch.
- visibility: hidden keeps box 2’s space.
Real-world use case#
Navigation links (inline <a>) are often made display: block or inline-block so the whole padded area is clickable. Mobile menus are hidden with display: none until opened.
Common mistakes#
width does nothing on a span or a. Change it to inline-block or block first.
display: none also hides content from screen readers. For “visually hidden but readable” text, use a .sr-only utility class.
Whitespace in the HTML creates small gaps between inline-block elements. Flexbox with gap avoids this.
Best practices#
- Use flex or grid for laying out groups of items
- Use inline-block for single badges or buttons in text
- Use the hidden HTML attribute or display: none to hide content
- Check the computed display value in DevTools when layout looks wrong
Remember this#
block = brick (stacks). inline = word (flows). inline-block = word you can resize.
none = gone (no space). hidden = invisible (space kept).
flex and grid are display values too — the gateway to layouts.
Practice exercise#
Your task: Turn a row of <a> links into clickable buttons, each 100px wide with 10px padding, sitting side by side.
Need a hint?
Show solution
nav a {
display: inline-block;
width: 100px;
padding: 10px;
text-align: center;
}
Mini quiz#
Which display value keeps elements on one line but allows width and height?
Want more? Practise all CSS MCQs · CSS interview questions
My notes#
Saved in this browser.