CHAPTER 26
CSS Inline-block
Learn how inline-block combines features of inline and block elements.
01. What is CSS Inline-block?
inline-block elements can stay on the same line like inline elements.
Unlike normal inline elements, width and height can be applied.
inline-block can be useful for small horizontal components.
02. Syntax
selector {
display: inline-block;
}
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
.card {
display: inline-block;
width: 200px;
padding: 20px;
margin: 10px;
background: #dbeafe;
vertical-align: top;
}
</style>
</head>
<body>
<div class="card">
HTML
</div>
<div class="card">
CSS
</div>
<div class="card">
JavaScript
</div>
</body>
</html>
04. Important Points
✓
inline-block allows width and height.
✓
Multiple inline-block elements can appear on the same line.
✓
vertical-align can control alignment.
✓
Flexbox and Grid are usually better for complex modern layouts.
05. Common Mistakes
⚠
Ignoring whitespace between inline-block elements.
⚠
Using inline-block for complex responsive layouts.
⚠
Forgetting vertical-align when elements have different sizes.
06. Real World Use
inline-block can be used for small cards, badges, buttons, navigation items and legacy layouts.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Create Three Cards
Create three course cards using display: inline-block and give each card a different background color.