SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
CSS
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10
Try this code live
Lesson 25 of 35

CSS Website Layout Tutorial — Header, Sidebar, Footer

4 min read · Free · No login needed

Every website you visit has the same skeleton: a header at the top with the site name, a navigation bar with the links, a main content area in the middle, often a sidebar on the side, and a footer at the bottom with contact details and copyright. Once you can build this skeleton, you can build almost any page — a blog, a school site, a shop, or a news page.

Diagram — see how it fits together
Diagram: CSS Website Layout

HTML gives you special tags for each part: <header>, <nav>, <main>, <aside> for the sidebar, and <footer>. CSS then decides how wide each part is, where it sits, and what colour it gets. The layout itself is just boxes stacked and placed next to each other.

A two-column layout

The most common layout is two columns: a wide main column for the article and a narrow sidebar for extra links or news. The easy modern way is to wrap both in a container with display: flex. The main column gets flex: 3 and the sidebar gets flex: 1 — the numbers are just shares of the available space, so main takes three quarters and the sidebar takes one quarter.

Syntax — header, columns, footer

header {
  background-color: #04aa6d;
  color: white;
  padding: 20px;
  text-align: center;
}
.container { display: flex; }
main { flex: 3; padding: 20px; }
aside { flex: 1; padding: 20px; background-color: #f1f1f1; }
footer {
  background-color: #333;
  color: white;
  padding: 15px;
  text-align: center;
}

The header and footer stretch across the full width because they are outside the flex container. Only the two columns inside the container sit side by side.

Centring the whole page

On a wide monitor, text stretched across the full screen is hard to read. Most sites limit the page width with max-width: 1000px and centre it with margin: auto. The page then sits in the middle with empty space on both sides, like a book on a table.

Note: Use max-width, not width, for the page wrapper. With max-width the page can still shrink on a small phone screen; with a fixed width it would overflow and force sideways scrolling.

An image gallery inside the layout

A gallery is a row of small boxes, each with an image and a caption underneath. The same flex idea works here: a display: flex container with a gap, and each gallery box given the same flex: 1. The images inside need width: 100% so they fill their box without overflowing it.

Tip: Always add box-sizing: border-box at the top of your stylesheet when building layouts. It makes padding count inside the width, so a column set to 25% with 20px of padding stays at 25% instead of growing wider and breaking the row.

Common mistakes

  • Forgetting box-sizing: border-box — padded columns grow wider than planned and the last column drops to the next line.
  • Using a fixed width for the page wrapper — the page overflows on phones instead of shrinking.
  • Putting the header or footer inside the flex container — they get squeezed into a column instead of stretching across the full width.
  • Forgetting width: 100% on gallery images — a large image overflows its box and breaks the layout.
  • Using <div> for everything — the semantic tags <header>, <main>, <aside> and <footer> make the page easier to read and better for search engines.

Remember

  • A page has five parts: header, nav, main, sidebar (<aside>), and footer.
  • A two-column layout is a flex container with flex: 3 for main and flex: 1 for the sidebar.
  • Centre the page with max-width and margin: auto.
  • Gallery boxes are flex items too, with images at width: 100%.
  • box-sizing: border-box keeps padding inside the width you set.

Example explained

  • header — a green band across the top with the school name, centred white text, and 20px of padding.
  • .container { display: flex; } — the wrapper around the main column and the sidebar, which places them side by side in one row.
  • main { flex: 3; } and aside { flex: 1; } — the article takes three parts of the width and the sidebar takes one part, so the split is roughly 75% and 25%.
  • .gallery { display: flex; gap: 15px; } — the three gallery boxes sit in a row with an even gap; each grey .photo box stands in for a real photo, which would use width: 100% to fill its box.
  • footer — a dark band at the bottom, outside the flex container, so it stretches across the full width of the page.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>School Website Layout</title>
<style>
* { box-sizing: border-box; }
body { font-family: Arial, sans-serif; margin: 0; }
header { background-color: #04aa6d; color: white; padding: 20px; text-align: center; }
nav { background-color: #333; padding: 12px; text-align: center; }
nav a { color: white; text-decoration: none; margin: 0 15px; }
.container { display: flex; max-width: 1000px; margin: auto; }
main { flex: 3; padding: 20px; }
aside { flex: 1; padding: 20px; background-color: #f1f1f1; }
.gallery { display: flex; gap: 15px; }
.gallery div { flex: 1; border: 1px solid #ccc; padding: 10px; text-align: center; }
.gallery .photo { height: 120px; background-color: #ddd; }
footer { background-color: #333; color: white; padding: 15px; text-align: center; }
</style>
</head>
<body>

<header>
<h1>KAMALDNP Academy</h1>
<p>IT Training and Summer Training, Varanasi</p>
</header>

<nav>
<a href="#">Home</a>
<a href="#">Courses</a>
<a href="#">Results</a>
<a href="#">Contact</a>
</nav>

<div class="container">
<main>
<h2>Welcome to Our Campus</h2>
<p>We teach HTML, CSS, Python, and Java to students from all over Uttar Pradesh. Our summer training batches start every June.</p>
<h3>Our Gallery</h3>
<div class="gallery">
<div><div class="photo"></div><p>Classroom</p></div>
<div><div class="photo"></div><p>Computer Lab</p></div>
<div><div class="photo"></div><p>Library</p></div>
</div>
</main>

<aside>
<h3>Latest News</h3>
<p>Admissions open for the July batch.</p>
<p>New CSS course starts Monday.</p>
<h3>Quick Links</h3>
<p>Syllabus</p>
<p>Results</p>
<p>Fees</p>
</aside>
</div>

<footer>
<p>Contact: support@kamaldnp.com | Varanasi, UP</p>
</footer>

</body>
</html>

Output

Output — how it looks in the browser
Output of CSS Website Layout Tutorial — Header, Sidebar, Footer

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What are the five parts of a web page?

Header, nav, main, sidebar (aside), and footer.

2. How do you build a two-column layout?

With a flex container: flex: 3 for the main content and flex: 1 for the sidebar.

3. How do you centre a whole page?

With max-width and margin: auto on the page wrapper.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Advanced Cyber Security Industrial Training
₹5,000
View
Master Python + AI Skills in 30 Days
₹499
View
Summer Training in Python Programming 2026
₹3,000
View
Browse all courses
CSS — Lessons
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →