Three Approaches to Web Layout
🎯 Introduction
Page layout is a fundamental web development skill. You will often hear about three approaches: fixed layouts, fluid layouts, and responsive layouts. How do they differ, and when should you use each? These terms can be confusing when you are starting out.
By the end of this article, you will understand each approach and be able to build layouts yourself. Whether you are building a desktop website, a mobile page, or a responsive site for multiple devices, you will be able to choose an approach that fits your needs.
🧱 Fixed Layout
What is a Fixed Layout?
A fixed layout is the simplest, most traditional approach. Element widths and positions are fixed and do not adjust when the browser window changes. Pixels (px) are commonly used for sizing.
Characteristics
| Characteristic | Description |
|---|---|
| Fixed dimensions | Elements have fixed sizes |
| Does not adapt to devices | Different devices may show horizontal scrolling or broken layouts |
| Simple to write | Suitable for beginner exercises |
| Limited flexibility | Cannot accommodate a wide range of screen sizes |
Use Cases
- Administration dashboards
- Internal tools
- Pages that do not need mobile support
Example Code
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Fixed Layout Example</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<div class="header">Header</div>
<div class="content">Content Area</div>
<div class="footer">Footer</div>
</div>
</body>
</html>
.container {
width: 960px;
margin: 0 auto;
}
.header,
.content,
.footer {
width: 960px;
padding: 20px;
border: 1px solid #000;
}
📐 Fluid Layout
What is a Fluid Layout?
The central idea of a fluid layout is to let the page adjust automatically to the available width.
It uses values such as percentages (%), auto, em, and rem to let elements resize automatically and fit different screen widths. The overall arrangement stays the same across devices rather than switching to a different structure.
Characteristics
| Characteristic | Description |
|---|---|
| Fills the available width | Uses percentages or fluid sizing |
| Does not require media queries | Keeps styling logic simple |
| Preserves the arrangement | Does not restructure the layout as the screen changes |
| Common in small and medium projects | Suitable for getting a page online quickly |
Common Fluid Sizing Values
| Unit or value | Purpose |
|---|---|
| % | A percentage of the parent container's width |
| em/rem | Units relative to font size |
| auto | Sizes based on content or the available container width |
| vw/vh | Units relative to viewport width and height |
Example Code
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Fluid Layout Example</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<div class="box">Content 1</div>
<div class="box">Content 2</div>
</div>
</body>
</html>
.container {
width: 100%;
display: flex;
}
.box {
width: 50%;
padding: 2em;
box-sizing: border-box;
border: 1px solid #ccc;
}
📱 Responsive Layout
What is a Responsive Layout?
A responsive layout is more flexible. It uses media queries to adapt to conditions such as screen size, resolution, and device characteristics, for example by changing the number of columns, hiding sections, or adjusting font sizes.
It goes beyond resizing a page: it changes the layout's arrangement to suit the available space.
Characteristics
| Characteristic | Description |
|---|---|
| Uses media queries | Changes the layout based on the available width |
| Can change the arrangement | Can hide or reposition content |
| More complex but more capable | Suitable for pages that support many device types |
| Often incorporates fluid sizing | Combines relative sizing with media queries |
Example (A First Look)
@media screen and (max-width: 768px) {
.box {
width: 100%;
}
}
❓ Knowledge Check
Q1: Can a fixed layout adapt to different screens?
No. Its widths are fixed, so smaller screens may show horizontal scrollbars.
Q2: Why doesn't a fluid layout require media queries?
It adjusts widths automatically using percentages and relative units such as em and rem, without explicit conditions for each screen width.
Q3: Are responsive and fluid layouts the same?
No. A fluid layout resizes while preserving its arrangement; a responsive layout can change that arrangement when conditions change.
Q4: Why learn fluid layouts?
They are easy to get started with, require little conditional logic, and can quickly accommodate a range of devices.
🧪 Exercises
Exercise 1: Build a Fixed Header and Content Layout
Try creating a fixed-width layout.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Fixed Layout</title>
<style>
.container {
width: 960px;
margin: 0 auto;
}
.header,
.content {
width: 960px;
padding: 20px;
background-color: #eee;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="header">This header has a fixed width</div>
<div class="content">This is the content area</div>
</div>
</body>
</html>
Copy the code into your editor and preview the result!
Exercise 2: Build a Fluid Two-Column Layout
Use percentages to create left and right columns.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Fluid Layout</title>
<style>
.container {
display: flex;
width: 100%;
}
.left {
width: 30%;
background-color: #cfc;
padding: 10px;
}
.right {
width: 70%;
background-color: #ccf;
padding: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="left">Left Sidebar</div>
<div class="right">Right Content</div>
</div>
</body>
</html>
Copy the code into your editor and preview the result!
🎉 You have learned the concepts and implementation basics of fixed, fluid, and responsive layouts!
