CHAPTER 20
CSS Display
Learn how the display property controls how HTML elements behave and appear in the layout.
01. What is CSS Display?
The display property controls the layout behavior of an element.
Common values include block, inline, inline-block, flex, grid and none.
Display is one of the most important CSS properties for website layouts.
02. Syntax
selector {
display: value;
}
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
.block {
display: block;
background: #dbeafe;
padding: 15px;
margin-bottom: 10px;
}
.inline {
display: inline;
background: #bbf7d0;
padding: 10px;
}
.inline-block {
display: inline-block;
width: 150px;
padding: 15px;
background: #fef3c7;
}
</style>
</head>
<body>
<div class="block">
Block Element
</div>
<span class="inline">
Inline Element
</span>
<div class="inline-block">
Inline Block
</div>
</body>
</html>
04. Important Points
✓
display: block makes an element take available horizontal space.
✓
display: inline keeps elements in the same line when possible.
✓
display: inline-block allows width and height while staying inline.
✓
display: none removes an element from the layout.
✓
display: flex and display: grid are important for modern layouts.
05. Common Mistakes
⚠
Using display: none when visibility is actually required.
⚠
Expecting width and height to work normally on inline elements.
⚠
Using old layout techniques when Flexbox or Grid would be more suitable.
06. Real World Use
Display properties are used in navigation menus, cards, buttons, responsive layouts, dashboards and complete website structures.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Practice Display Properties
Create three boxes and demonstrate block, inline and inline-block display behavior.