
CSS Layout is like arranging furniture inside a room.
HTML gives the structure of the house, but CSS decides:
Which item goes where
Which item stays beside another
Which item remains fixed
Which item moves while scrolling
A beautiful website is not only about colors and fonts.
Its real strength is layout management.
1. What is CSS Layout?
A layout means:
“How elements are arranged on a webpage.”
For example:
Navbar at top
Sidebar on left
Content in center
Footer at bottom
CSS provides different techniques to control this arrangement.
2. Display Property
The display property decides:
“How an element behaves on the webpage.”
It controls whether an element:
takes full width
stays in one line
hides completely
behaves like a container
Syntax
selector{
display:value;
}
Common Display Values
| Value | Meaning |
|---|---|
| block | Takes full width |
| inline | Takes only needed width |
| inline-block | Inline + can set width/height |
| none | Completely hides element |
Example 1 — Block Element
<div>Box 1</div>
<div>Box 2</div>
div{
background:lightblue;
margin:10px;
}
Output
Box 1 and Box 2 appear on separate lines.
Because <div> is naturally a block element.
Example 2 — Inline Element
<span>HTML</span>
<span>CSS</span>
<span>JavaScript</span>
span{
background:yellow;
}
Output
All stay in the same line.
Because <span> is naturally an inline element.
3. Inline vs Block
This is one of the most important CSS concepts.
Block Elements
A block element:
starts from new line
takes full width
can have width and height
Examples
<div></div>
<p></p>
<h1></h1>
<section></section>
Visual Logic
Think of block elements like:
Big cupboards placed one below another.
Inline Elements
Inline elements:
stay in same line
take only needed space
width and height usually don’t work properly
Examples
<span></span>
<a></a>
<b></b>
<i></i>
Visual Logic
Think of inline elements like:
Words inside a sentence.
Example Comparison
<div class="box">Block Element</div>
<span class="text">Inline Element</span>
.box{
background:skyblue;
}
.text{
background:pink;
}
4. Positioning in CSS
Positioning controls:
“Where exactly an element should appear.”
CSS has 5 major position types:
Static
Relative
Absolute
Fixed
Sticky
Position Syntax
selector{
position:value;
}
5. Static Position
This is the default position.
position:static;
Logic
Element stays in normal webpage flow.
No special movement happens.
Example
.box{
position:static;
}
Usually we don’t write it because every element is already static by default.
Real Life Example
Students sitting normally in classroom rows.
Nobody changes position.
6. Relative Position
position:relative;
Relative means:
Move relative to original position.
Example
<div class="box">Relative Box</div>
.box{
position:relative;
top:20px;
left:30px;
background:orange;
}
What Happens?
The box moves:
20px down
30px right
BUT its original space still remains reserved.
Visual Logic
Imagine moving your chair slightly forward,
but your original classroom space is still counted.
Important Properties
| Property | Meaning |
|---|---|
| top | move down |
| bottom | move up |
| left | move right |
| right | move left |
7. Absolute Position
position:absolute;
Absolute positioning removes element from normal flow.
It positions relative to nearest positioned parent.
Example
<div class="parent">
<div class="child">Box</div>
</div>
.parent{
position:relative;
width:300px;
height:300px;
background:lightgray;
}
.child{
position:absolute;
top:50px;
left:100px;
background:red;
}
Logic
The child box moves inside parent box exactly at:
50px from top
100px from left
Real Life Example
Think of a sticker pasted at exact position on a notebook cover.
Important Point
Absolute elements:
leave normal flow
other elements ignore them
8. Fixed Position
position:fixed;
Fixed element stays fixed on screen even while scrolling.
Example
.chat{
position:fixed;
bottom:20px;
right:20px;
}
Real Example
WhatsApp floating button
Customer support icon
Sticky mobile call button
These remain visible while scrolling.
Logic
Element attaches to browser screen, not webpage content.
9. Sticky Position
position:sticky;
Sticky behaves like:
relative at first
fixed after scrolling
Example
.navbar{
position:sticky;
top:0;
background:black;
color:white;
}
What Happens?
Navbar scrolls normally initially.
After reaching top:
it sticks there.
Real Example
YouTube top header.
Many news websites use sticky navigation bars.
Difference Between Fixed and Sticky
| Fixed | Sticky |
|---|---|
| Always fixed | Becomes fixed after scrolling |
| Ignores normal flow | Starts in normal flow |
| Attached to screen | Attached after reaching position |
10. Float Property
Before Flexbox and Grid, float was heavily used for layouts.
float:left;
or
float:right;
Logic
Float pushes elements left or right.
Other content wraps around it.
Example
<img src="image.jpg">
<p>This is paragraph text...</p>
img{
float:left;
margin-right:15px;
}
Output
Text wraps around image.
Like newspaper article layouts.
Real Life Example
Image in newspaper with text around it.
Float Left Example
.box1{
float:left;
}
Moves box to left side.
Float Right Example
.box2{
float:right;
}
Moves box to right side.
11. Clear Property
Sometimes float creates layout problems.
clear fixes those issues.
Example
.footer{
clear:both;
}
Logic
Footer moves below floated elements.
Clear Values
| Value | Meaning |
|---|---|
| left | Clears left float |
| right | Clears right float |
| both | Clears both sides |
Real Example
Without clear:
footer may move beside floated sidebar.
With clear:
footer comes properly below.
Complete Layout Example
HTML
<div class="header">Header</div>
<div class="sidebar">Sidebar</div>
<div class="content">Content Area</div>
<div class="footer">Footer</div>
CSS
.header{
background:black;
color:white;
padding:20px;
}
.sidebar{
float:left;
width:30%;
background:lightblue;
height:200px;
}
.content{
float:left;
width:70%;
background:lightgreen;
height:200px;
}
.footer{
clear:both;
background:gray;
padding:20px;
}
Output Structure
-------------------
Header
-------------------
Sidebar | Content
-------------------
Footer
-------------------
Real Website Usage
| Feature | CSS Layout Used |
|---|---|
| Navbar | Sticky / Fixed |
| Sidebar | Float / Position |
| Popup | Absolute / Fixed |
| Chat Button | Fixed |
| Banner Text | Absolute |
| News Layout | Float |
Common Beginner Mistakes
| Mistake | Problem |
|---|---|
| Using absolute everywhere | Layout breaks |
| Forgetting clear | Footer overlaps |
| Confusing inline/block | Alignment issues |
| Using fixed too much | Mobile problems |
| No parent relative | Absolute moves unexpectedly |
Best Practice
✅ Use relative parent with absolute child
✅ Use sticky for navigation bars
✅ Use fixed only when necessary
✅ Understand normal document flow first
✅ Practice layouts by building real pages
Mini Practice Task
Create:
Sticky navbar
Sidebar on left
Content section
Fixed WhatsApp button
Footer below everything
This single project teaches most layout concepts.
Learning Outcome
After completing this module, students will:
✅ Understand webpage structure and positioning
✅ Know difference between inline and block elements
✅ Use display property properly
✅ Create layouts using float and positioning
✅ Build sticky headers and fixed buttons
✅ Understand professional webpage arrangement logic
Final Understanding
CSS Layout is the architecture of a webpage.
Colors make website beautiful.
Fonts make website readable.
But layout makes website usable.
A strong frontend developer is recognized not by fancy colors…
…but by clean, balanced, responsive layouts.
