inline-blockThe inline-block value lets elements sit in one line like inline, but still allows you to set width and height like a block element. It’s great for simple horizontal layouts such as buttons, cards, or navbar items.
width, height, padding, and margin normally.To use inline-block, apply it to an element with the display property:
/* Make boxes line up horizontally but keep block sizing */
.box {
display: inline-block;
width: 120px;
height: 100px;
background-color: #007bff;
color: #ffffff;
text-align: center;
line-height: 100px;
margin: 10px;
}
Here, each .box behaves like a block (fixed size, padding, margin), but because of display: inline-block;, multiple boxes can sit on the same line.
This example shows three boxes aligned horizontally using inline-block.
<!-- HTML + CSS inline-block demo -->
<style>
.inline-box {
display: inline-block;
width: 120px;
height: 80px;
background-color: #2563eb;
color: #ffffff;
text-align: center;
line-height: 80px;
margin: 6px;
border-radius: 8px;
}
</style>
<div class="inline-box">Box 1</div>
<div class="inline-box">Box 2</div>
<div class="inline-box">Box 3</div>
All three boxes appear on the same line (like inline elements), but each keeps its own width and height (like block elements). If you shrink the window, they will wrap onto the next line when there isn’t enough space.
inline-block for simple horizontal layouts like buttons, tags, or small cards.text-align: center; and vertical alignment with line-height or flexbox.flexbox or grid are usually easier to manage.inline-block and try changing their width and height. Observe how they stay on the same line.text-align: center; to the parent container and see how the inline-block boxes are centered.display: inline-block; with display: block; and display: inline; to see the difference.