The display property controls how an element behaves in the layout and how its children are arranged.
Access software development training resources
Here are CSS cheat sheets you should know.
selector {
display: value;
} Example:
.box {
display: flex;
} display: blockTakes the full available width and starts on a new line.
div {
display: block;
} Characteristics:
✅ Starts on a new line
✅ Width defaults to 100%
✅ Can set width/height
✅ Stack vertically
Examples:
<div>One</div>
<div>Two</div> Common block elements:
<div>
<p>
<h1>–<h6>
<section> display: inlineOnly occupies content width.
span{
display:inline;
} Characteristics:
✅ Stays in same line
✅ Width/height ignored
✅ No line break
Example:
<span>Hello</span>
<span>World</span> display: inline-blockHybrid of inline + block.
.card{
display:inline-block;
} Characteristics:
✅ Appears inline
✅ Width and height work
✅ Can have padding/margins
Example:
button{
width:150px;
height:50px;
display:inline-block;
} display: noneCompletely removes element from page flow.
.hidden{
display:none;
} Characteristics:
❌ Not visible
❌ Takes no space
❌ Removed from layout
Example:
.mobile-menu{
display:none;
} Toggle with JS:
menu.style.display="block"; display: flexCreates a flexible one-dimensional layout.
.container{
display:flex;
} Useful properties:
.container{
display:flex;
justify-content:center;
align-items:center;
gap:20px;
} Main axis controls:
justify-content:
center
space-between
space-around
space-evenly
flex-start
flex-end Cross-axis:
align-items:
center
stretch
flex-start
flex-end Example:
<div class="container">
<div>A</div>
<div>B</div>
<div>C</div>
</div> display: inline-flexFlex container behaves inline.
.badge{
display:inline-flex;
align-items:center;
} Useful for:
display: gridCreates a two-dimensional layout.
.container{
display:grid;
} Example:
.container{
display:grid;
grid-template-columns:
repeat(3,1fr);
gap:20px;
} Example HTML:
<div class="container">
<div>1</div>
<div>2</div>
<div>3</div>
</div> Useful properties:
grid-template-columns
grid-template-rows
gap
place-items
grid-column
grid-row display: inline-gridGrid behaves like inline element.
.tags{
display:inline-grid;
} Rarely used but useful in compact layouts.
display: contentsMakes the element disappear visually while keeping children.
.wrapper{
display:contents;
} Before:
<div class="wrapper">
<p>One</p>
<p>Two</p>
</div> Wrapper no longer affects layout.
Use carefully.
display: tableMakes elements behave like HTML tables.
.container{
display:table;
} Related values:
display:table-row;
display:table-cell;
display:table-caption; Example:
.row{
display:table-row;
}
.cell{
display:table-cell;
}
display: list-itemBehaves like <li>.
div{
display:list-item;
} Adds list markers:
div{
display:list-item;
list-style:square;
} display: flow-rootCreates a new block formatting context.
Useful for fixing float issues.
.container{
display:flow-root;
} Instead of:
.clearfix::after{
content:"";
clear:both;
display:block;
} Use:
.container{
display:flow-root;
} | Value | New Line | Width/Height | Layout Type |
|---|---|---|---|
| block | Yes | Yes | Vertical |
| inline | No | No | Content only |
| inline-block | No | Yes | Hybrid |
| none | No | No | Hidden |
| flex | Yes | Yes | 1D Layout |
| grid | Yes | Yes | 2D Layout |
| inline-flex | No | Yes | Inline Flex |
| inline-grid | No | Yes | Inline Grid |
Latest tech news and coding tips.
Context poisoning is a technique where an attacker deliberately places misleading, malicious, or irrelevant information into…
React makes building user interfaces easier, but certain errors appear repeatedly, especially when working with…
The C programming language is a foundational, general-purpose computer programming language created by Dennis Ritchie at Bell Labs in 1972. Originally developed to…
What Is Homebrew? Homebrew is a package manager for macOS and Linux that makes it easy to…
JavaScript gives you several ways to iterate over an array. Some are better for simple…
A web server is the software responsible for receiving requests from clients, processing those requests,…