</> Code Corner

CSS · CSS Tutorial · Lesson 26

CSS Inline-block

Inline elements that accept width and height.

Compared to inline, display: inline-block allows setting width and height, and respects top/bottom margins and padding. Compared to block, it does not add a line break.

Example

<style>
span.a { display: inline; width: 100px; height: 40px; padding: 5px; border: 1px solid blue; background: yellow; }
span.b { display: inline-block; width: 100px; height: 40px; padding: 5px; border: 1px solid blue; background: yellow; }
</style>
<p>Inline: <span class="a">Aliquam</span> <span class="a">venenatis</span> (width ignored)</p>
<p>Inline-block: <span class="b">Aliquam</span> <span class="b">venenatis</span> (width works)</p>

Keep reading “CSS Inline-block”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋