Lesson 4.4 β Display Properties
π¨ Understanding Block, Inline, and Inline-Block Elements in CSS
π― Learning Objectives
After completing this lesson, students will be able to:
β Understand the CSS Display Property
β Differentiate Block and Inline Elements
β Understand Inline-Block Elements
β Use Display Property Effectively
β Create Better Layouts
β Control Element Positioning
β Build Professional Website Structures
π Introduction
Every HTML element behaves differently on a webpage.
For example:
<h1>Welcome</h1>
<p>Learning CSS</p>
Output:
Welcome
Learning CSS
Each element starts on a new line.
Now look at:
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
Output:
Home About Contact
All links appear on the same line.
Why?
Because different HTML elements have different display behaviors.
This behavior is controlled by:
π₯οΈ CSS Display Property
π€ What is Display Property?
The display property controls:
How an element appears on a webpage
Syntax
display:value;
Common Values:
display:block;
Β
display:inline;
display:inline-block;
display:none;
π Types of Display Properties
There are four main display types:
1οΈβ£ Block
2οΈβ£ Inline
3οΈβ£ Inline-Block
4οΈβ£ None
1οΈβ£ Block Elements
Block elements:
β Start on a new line
β Take full available width
β Can have width and height
Examples of Block Elements
<h1>
<p>
<div>
<section>
<header>
<footer>
Example
<h1>HTML</h1>
<h1>CSS</h1>
<h1>JavaScript</h1>
Output
HTML
CSS
JavaScript
Each appears on a new line.
π― Block Display
display:block;
Example
a{
display:block;
}
Result
Links move to separate lines.
Example
HTML
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
CSS
a{
display:block;
}
Output
Home
About
Contact
2οΈβ£ Inline Elements
Inline elements:
β Stay on the same line
β Only take required width
β Width and height usually do not work properly
Examples of Inline Elements
<a>
<strong>
<em>
Example
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
Output
Home About Contact
π― Inline Display
display:inline;
Example
h1{
display:inline;
}
HTML
<h1>HTML</h1>
<h1>CSS</h1>
<h1>JavaScript</h1>
Output
HTML CSS JavaScript
All headings appear on the same line.
π Block vs Inline
| Feature | Block | Inline |
|---|---|---|
| New Line | β Yes | β No |
| Full Width | β Yes | β No |
| Width Works | β Yes | β No |
| Height Works | β Yes | β No |
3οΈβ£ Inline-Block Elements
Inline-block combines:
Block + Inline
Features:
β Stays on same line
β Width works
β Height works
β Margin works
β Padding works
Syntax
display:inline-block;
Example
HTML
<div>HTML</div>
<div>CSS</div>
<div>JavaScript</div>
CSS
div{
display:inline-block;
width:150px;
height:100px;
border:2px solid blue;
}
Output
+-------+ +-------+ +-------+
HTML CSS JavaScript
+-------+ +-------+ +-------+
Boxes appear side by side.
Why Use Inline-Block?
Useful for:
β Cards
β Navigation Menus
β Product Boxes
β Gallery Layouts
π Display None
Sometimes we want to hide elements.
Syntax
display:none;
Example
HTML
<p>
This text will disappear
</p>
CSS
p{
display:none;
}
Result
Text becomes invisible.
Why Use Display None?
Used for:
β Hide Menus
β Show/Hide Sections
β Responsive Design
β JavaScript Effects
π― Practical Example
HTML
<div class="box">
HTML
</div>
<div class="box">
CSS
</div>
<div class="box">
JavaScript
</div>
CSS
.box{
display:inline-block;
width:150px;
height:100px;
background-color:lightblue;
border:2px solid blue;
margin:10px;
text-align:center;
}
Output
Three boxes displayed side by side.
π» Complete Practical Program
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="box">
HTML
</div>
<div class="box">
CSS
</div>
<div class="box">
JavaScript
</div>
</body>
</html>
CSS
.box{
display:inline-block;
width:150px;
height:100px;
background-color:lightyellow;
border:2px solid orange;
margin:10px;
padding:20px;
font-size:20px;
text-align:center;
}
π― Expected Output
Three attractive boxes:
HTML CSS JavaScript
displayed side by side.
π« Real World Examples
Navigation Menu
display:inline;
or
display:inline-block;
Website Cards
display:inline-block;
Hidden Mobile Menu
display:none;
Blog Sections
display:block;
β οΈ Common Beginner Mistakes
Mistake 1
Using Width on Inline Elements
Wrong:
a{
width:200px;
}
Width may not work properly.
Use:
display:inline-block;
Mistake 2
Confusing Block and Inline
Remember:
Block = New Line
Inline = Same Line
Mistake 3
Using Display None Accidentally
display:none;
Element disappears completely.
π Best Practices
β Use block for sections.
β Use inline for text elements.
β Use inline-block for cards and menus.
β Use display:none carefully.
β Understand element behavior before designing layouts.
π Mini Project β Course Boxes
Create three boxes:
HTML
CSS
JavaScript
Apply:
β Width = 150px
β Height = 100px
β Inline-Block Display
β Border
β Background Color
π Practical Activity
Create a navigation menu:
Home
About
Courses
Contact
Display all items on the same line.
Then create:
HTML
CSS
JavaScript
Boxes displayed side by side.
π Assignment
Assignment 4.4
- What is the display property?
- What is a block element?
- What is an inline element?
- What is an inline-block element?
- What does display:none do?
- Create three boxes using inline-block.
- Convert links into block elements.
π§ Quiz
Q1. Which display type starts on a new line?
A. inline
B. inline-block
C. block
D. none
β Answer: C
Q2. Which display type stays on the same line?
A. block
B. inline
C. hidden
D. section
β Answer: B
Q3. Which display type allows width and height while staying on the same line?
A. block
B. inline
C. inline-block
D. none
β Answer: C
Q4. Which value hides an element completely?
A. hidden
B. invisible
C. display:none
D. remove
β Answer: C
Q5. Which element is normally inline?
A. div
B. p
C. h1
D. a
β Answer: D
π Lesson Summary
β Display property controls how elements appear.
β Block elements start on a new line.
β Inline elements stay on the same line.
β Inline-block combines features of both.
β Display none hides elements completely.
β Display properties are essential for webpage layouts.