What exactly is the difference between the inline
and inline-block
values of CSS display
?

- 20,799
- 66
- 75
- 101

- 7,600
- 3
- 26
- 23
7 Answers
A visual answer
Imagine a <span>
element inside a <div>
. If you give the <span>
element a height of 100px and a red border for example, it will look like this with
display: inline
display: inline-block
display: block
Code: http://jsfiddle.net/Mta2b/
Elements with display:inline-block
are like display:inline
elements, but they can have a width and a height. That means that you can use an inline-block element as a block while flowing it within text or other elements.
Difference of supported styles as summary:
- inline: only
margin-left
,margin-right
,padding-left
,padding-right
- inline-block:
margin
,padding
,height
,width

- 102,760
- 52
- 202
- 249
-
11Great intuition. So the only difference is that the height attribute of inline elements cannot be set? – user2316667 Jun 18 '14 at 20:26
-
8@user2316667 and width – Oscar Calderon Jan 06 '16 at 14:32
-
3@user2316667 and @OscarCalderon: also, inline elements don't care vertical margins & paddings and the next element will be placed at the same line (no line break after it). the block elements like as `p`, `div` get a whole width line (force a line break) but respect width/height and all horizontal/vertical padding/margins. Inline-block elements have same behavior as block but without whole line break (other elements can be placed beside them) – S.Serpooshan Jan 04 '17 at 07:43
-
2padding-top and padding-right also affects the inline element's display effect, causing some mess. – tomwang1013 Aug 09 '17 at 09:35
-
So does it means that we always have to use inline-block and control CSS properties? – José Manuel Blasco Nov 23 '17 at 12:32
-
3@manuman94 No, it doesn't mean that. There are use cases for all the different display types. – splattne Nov 23 '17 at 13:20
-
Thanks for your response. It's only that it seems you can do all you want with inline-block, but you can't with inline. – José Manuel Blasco Nov 23 '17 at 14:36
-
Also, I think `display:inline` adds a bit of padding by default and `display:inline-block` fits exactly to the content – Viraj Jan 29 '20 at 18:24
-
```display: inline```, which is the default for the span tag. It means that even if you don't explicitly declare it, the span will be shown like in the first visual. – U.Savas May 10 '20 at 15:55
display: inline;
is a display mode to use in a sentence. For instance, if you have a paragraph and want to highlight a single word you do:
<p>
Pellentesque habitant morbi <em>tristique</em> senectus
et netus et malesuada fames ac turpis egestas.
</p>
The <em>
element has a display: inline;
by default, because this tag is always used in a sentence.
The <p>
element has a display: block;
by default, because it's neither a sentence nor in a sentence, it's a block of sentences.
An element with display: inline;
cannot have a height
or a width
or a vertical margin
. An element with display: block;
can have a width
, height
and margin
.
If you want to add a height
to the <em>
element, you need to set this element to display: inline-block;
. Now you can add a height
to the element and every other block style (the block
part of inline-block
), but it is placed in a sentence (the inline
part of inline-block
).
-
13Great answer! **tl;dr** - If you want to resize *inline* elements you could be using *inline-block* as the display type. – errorprone Aug 01 '13 at 07:25
-
8Small correction: inline elements *can* have horizontal margin (right, left), but *not* vertical margin (top, bottom) – whyleee Feb 06 '14 at 23:09
-
1Good answer because you mentioned about what we can/can't do when choosing one of the `display` values. – ha9u63a7 Aug 16 '15 at 22:06
One thing not mentioned in answers is inline element can break among lines while inline-block can't (and obviously block)! So inline elements can be useful to style sentences of text and blocks inside them, but as they can't be padded you can use line-height instead.
<div style="width: 350px">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<div style="display: inline; background: #F00; color: #FFF">
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<hr/>
<div style="width: 350px">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<div style="display: inline-block; background: #F00; color: #FFF">
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
-
Also as mentioned in [this answer](https://stackoverflow.com/a/59254119/5289334), In bidirectional text, where there is a mix of both RTL and LTR text, the order of text and elements can be different depending on the display property of those elements. the [Unicode Bidirectional Algorithm](https://www.w3.org/International/articles/inline-bidi-markup/uba-basics) (UBA) is not directly responsible for determining the layout or positioning of multiple inline-block elements when they are adjacent to each other, whereas UBA is involved in the correct rendering of characters within inline elements. – c0m1t May 22 '23 at 20:44
All answers above contribute important info on the original question. However, there is a generalization that seems wrong.
It is possible to set width and height to at least one inline element (that I can think of) – the <img>
element.
Both accepted answers here and on this duplicate state that this is not possible but this doesn’t seem like a valid general rule.
Example:
img {
width: 200px;
height: 200px;
border: 1px solid red;
}
<img src="#" />
The img
has display: inline
, but its width
and height
were successfully set.

- 29,210
- 11
- 96
- 131

- 321
- 4
- 14
-
2Actually, img-tag has display-inline as their default display value. So that's why it is possible to set width and height. – Alex Aug 15 '17 at 13:13
-
img is an inline element--> https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements... So basically you are saying more or less exactly the same thing I am saying and you are downvoting?? – alexandros84 Aug 16 '17 at 05:18
-
7No, I'm not. img-tags are a "replaced elements" which basically means the content is replaced so it behaves like an inline-block element. And yes the actual default property (the by the browser computed property is inline). But the only reason for that is because inline-block wasn't introduced until CSS2 and there for it is an "inline element behaving like an inline-block element" because it is replaced by its content. i.e you are not setting height/width to the element, you are setting it on its content - Wierd, yes. I know. https://drafts.csswg.org/css2/conform.html#replaced-element – Alex Aug 17 '17 at 05:13
-
That is actually interesting what you are saying. Give me some time to research and re-edit and maybe take back the downvote and upvote instead..! In the end of the day I honestly feel already that this discussion is contributing to the completeness of the whole debate. – alexandros84 Aug 17 '17 at 08:17
splattne's answer probably covered most of everything so I won't repeat the same thing, but: inline
and inline-block
behave differently with the direction
CSS property.
Within the next snippet you see one two
(in order) is rendered, like it does in LTR layouts. I suspect the browser here auto-detected the English part as LTR text and rendered it from left to right.
body {
text-align: right;
direction: rtl;
}
h2 {
display: block; /* just being explicit */
}
span {
display: inline;
}
<h2>
هذا عنوان طويل
<span>one</span>
<span>two</span>
</h2>
However, if I go ahead and set display
to inline-block
, the browser appears to respect the direction
property and render the elements from right to left in order, so that two one
is rendered.
body {
text-align: right;
direction: rtl;
}
h2 {
display: block; /* just being explicit */
}
span {
display: inline-block;
}
<h2>
هذا عنوان طويل
<span>one</span>
<span>two</span>
</h2>
I don't know if there are any other quirks to this, I only found about this empirically on Chrome.

- 1,472
- 23
- 33
-
I think this is related to [directional runs](https://www.w3.org/International/articles/inline-bidi-markup/uba-basics#directionalruns). When `display: inline` is set, the browser uses [Unicode Bidirectional Algorithm](https://www.w3.org/International/articles/inline-bidi-markup/uba-basics) to determine the order of the characters, which is not the same as the order in memory(HTML). When `display: inline-block` is set, the browser does not use the mentioned algorithm and just displays the blocks in the logical order(HTML). – c0m1t May 22 '23 at 20:28
inline elements
- Have respect for their left & right margin and padding. not for top/bottom.
- Cannot set width or height.
- Allow other elements to sit to their left and right.
Inline-Block elements:
- Respect all sides for margin and padding.
- Can set width and height.
- Allow other elements to sit to their left & right.
Block elements:
- Respect all sides for margin and padding
- Acquire full-width (in case the width is not defined)
- Force a line break after them
A visual example looks like this:
Check out the snippet below for an extra visualization example
.block{
background: green;
width: 50px;
height: 50px;
margin-top: 10px;
margin-bottom: 10px;
display: block;
}
.inline-block{
background: green;
width: 50px;
height: 50px;
margin-top: 10px;
margin-bottom: 10px;
display: inline-block;
}
.inline{
background: green;
width: 50px;
height: 50px;
margin-top: 10px;
margin-bottom: 10px;
display: inline;
}
<div class="block">
block
</div>
<div class="block">
block
</div>
<div class="inline-block">
inline block
</div>
<div class="inline-block">
inline block
</div>
<div class="inline">
inline
</div>
<div class="inline">
inline
</div>

- 14,906
- 5
- 47
- 53
Block - Element take complete width.All properties height , width, margin , padding work
Inline - element take height and width according to the content. Height , width , margin bottom and margin top do not work .Padding and left and right margin work. Example span and anchor.
Inline block - 1. Element don't take complete width, that is why it has *inline* in its name. All properties including height , width, margin top and margin bottom work on it. Which also work in block level element.That's why it has *block* in its name.

- 806
- 6
- 10