SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
Lesson 25 of 30

CSS Website Layout

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

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

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 30 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.

AI & ML with Azure AI, AWS AI & Generative AI
₹10,000
View
WordPress Website Development Course (10 Days)
₹399
View
AI Power Skills in 2 Days | Learn AI Text, Image, Video and Voice Tools
View
Browse all courses
CSS — Lessons
1. CSS Introduction 2. CSS Syntax 3. CSS Selectors 4. CSS How To 5. CSS Colors 6. CSS Backgrounds 7. CSS Borders 8. CSS Margins 9. CSS Padding 10. CSS Height and Width 11. CSS Box Model 12. CSS Text 13. CSS Fonts 14. CSS Links 15. CSS Lists 16. CSS Tables 17. CSS Display 18. CSS Position 19. CSS Overflow 20. CSS Float 21. CSS Pseudo-classes 22. CSS Pseudo-elements 23. CSS Forms 24. CSS Navigation Bar 25. CSS Website Layout 26. CSS Flexbox 27. CSS Grid 28. CSS Responsive 29. CSS Transitions and Animations 30. CSS Variables
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...
🛡️ 7-Day Money-Back Guarantee
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Download karne ke liye login karo. Login ke baad yahi page pe rahoge!

Naya ho? Register karo →