In CSS, there are several display properties that control how elements are rendered within the document flow. Three common display values are inline, inline-block, and block.
Understanding these display properties is essential for controlling the layout and behavior of HTML elements.
In this article, we’ll delve into the differences between inline
, inline-block
, and block
elements and when to use each one.
1. “block” Elements:
Block elements are displayed as blocks, taking up the entire width of their parent container and stacking vertically on top of each other. They create line breaks before and after themselves, effectively starting on a new line.
Common block
elements include <div>
, <p>
, <h1>
, <ul>
, and <li>
. Here’s an example:
<div>
<p>This is a <strong>block</strong> element.</p>
<p>It stacks vertically below the previous one.</p>
</div>
div {
padding: 5px 20px;
background-color: lightblue;
}
p {
background-color: lightcoral;
}
In this example, both <p>
elements are displayed as block
, causing them to stack vertically within the <div>
container.

Key characteristics of block elements:
- They create line breaks before and after themselves.
- They take up the entire available width of their parent container.
- Margins and padding can be applied horizontally and vertically.
- They can have a fixed width and height.
2. “inline” Elements:
Inline elements, as the name suggests, are elements that are displayed inline with the surrounding text or content. They flow within the content, and their width and height are determined by their content.
Common inline
elements include <span>
, <a>
, <strong>
, and <em>
. Here’s an example:
<div>
<p>This is an <strong>inline</strong> element.</p>
</div>
div {
padding: 5px 20px;
background-color: lightblue;
}
p {
background-color: lightcoral;
}
strong {
background-color: lightgreen;
}
In this example, the <strong>
element is displayed inline with the text, and it only takes up as much space as its content requires.

Key characteristics of inline elements:
- They do not create line breaks before or after themselves.
- They only take up as much width as necessary for their content.
- You can apply margins and padding horizontally, but not vertically.
- They cannot have a fixed width or height.
3. “inline-block” Elements:
Inline-Block elements combine the features of both inline
and block
elements. They flow within the content like inline elements but allow you to control their width, height, margins, and padding like block elements.
Common use cases for inline-block
elements include creating navigation menus, displaying lists horizontally, and forming grid layouts. Here’s an example:
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
</ul>
li {
display: inline-block;
margin-right: 10px;
}
In this example, the <li>
elements are displayed as inline-block, allowing them to form a horizontal list with spacing between the items.
Key characteristics of inline-block elements:
- They do not create line breaks before or after themselves.
- They can have a fixed width and height.
- You can apply margins and padding both horizontally and vertically.
- They take up as much width as necessary for their content or as specified.
4. Differences Between CSS “inline” and “inline-block”
inline | inline-block |
---|---|
Elements with display: inline; behave as if they are part of the text flow within a paragraph or block-level element. | Elements with display: inline-block; also participate in the text flow, but they allow setting a fixed width and height. |
They don’t start on a new line and only occupy as much width as necessary for their content. | They start on the same line as the previous element but respect the specified width and height. |
Margins and padding only affect the left and right sides, not the top and bottom. | Margins and padding affect all sides of the element. |
<!DOCTYPE html>
<html>
<head>
<style>
.inline {
display: inline;
width: 100px; /* This won't affect the width */
height: 100px; /* This won't affect the height */
margin: 10px; /* Only affects left and right */
background-color: lightblue;
}
.inline-block {
display: inline-block;
width: 100px; /* Affects width */
height: 100px; /* Affects height */
margin: 10px; /* Affects all sides */
background-color: lightcoral;
}
</style>
</head>
<body>
<div class="inline">Inline</div>
<span class="inline-block">Inline-Block</span>
<span class="inline">Inline</span>
</body>
</html>

5. When to Use Each Display Value
Choosing between inline
, inline-block
, and block
depends on your layout and design requirements:
- Use
inline
elements when you want elements to flow within the text or content, such as within paragraphs or headings. - Use
inline-block
elements when you want elements to flow within the content but need control over their dimensions and spacing. This is handy for creating navigation menus or inline lists. - Use
block
elements when you want elements to stack vertically, create line breaks before and after themselves, or take up the entire width of their parent container. This is typical for structuring the layout of a webpage.
It’s worth noting that you can change the display value of an element using CSS. For example, you can set an inline
element to display: block;
if you want it to behave as a block
element, and vice versa.
span {
display: block; /* Changes an inline element to block */
}
div {
display: inline; /* Changes a block element to inline */
}
Conclusion:
Understanding the differences and use cases of inline, inline-block, and block elements will help you control the layout and behavior of your web pages more effectively. Each display value has its place in web design, allowing you to create visually appealing and structurally sound layouts.