Course Content
Project file
0/1
Complete Web Designing Course for Beginners

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

  1. What is the display property?
  2. What is a block element?
  3. What is an inline element?
  4. What is an inline-block element?
  5. What does display:none do?
  6. Create three boxes using inline-block.
  7. 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.

Scroll to Top