Basic HTML Page layout using Div tags

A page layout divides the page into parts like header, menu, content, sidebar and footer. The modern way is to use <div> tags (or semantic tags) with CSS Flexbox.

HTML and CSS code

<style>
  * { box-sizing: border-box; }
  body { margin: 0; font-family: Arial, sans-serif; }
  .header, .footer { background: #0073aa; color: #fff; padding: 15px; text-align: center; }
  .menu { background: #333; }
  .menu a { display: inline-block; color: #fff; padding: 12px 16px; text-decoration: none; }
  .wrapper { display: flex; }
  .content { flex: 3; padding: 15px; }
  .sidebar { flex: 1; background: #f1f1f1; padding: 15px; }

  @media (max-width: 600px) {
    .wrapper { flex-direction: column; }
  }
</style>

<div class="header"><h1>My Website</h1></div>

<div class="menu">
  <a href="#">Home</a>
  <a href="#">About</a>
  <a href="#">Contact</a>
</div>

<div class="wrapper">
  <div class="content">
    <h2>Main Content</h2>
    <p>This is the main area of the page.</p>
  </div>
  <div class="sidebar">
    <h3>Sidebar</h3>
    <p>Links or ads go here.</p>
  </div>
</div>

<div class="footer">&copy; 2025 My Website</div>

Output in the browser:

Output in the browser
My Website
Main Content
This is the main area of the page.
Sidebar
Links or ads go here.
© 2025 My Website

How it works

  • .wrapper uses display: flex, so the content and sidebar sit side by side.
  • flex: 3 and flex: 1 give the content three times the width of the sidebar.
  • The media query stacks them on small phone screens.

Related: HTML Responsive Design and the older table layout.


Learn more about the similar topics:
Tutorials
HTML Semantic Elements
HTML Responsive Design
Exercises & Assignments
Write an HTML program to create a navigation menu
Write an HTML program to create a page layout with semantic elements
Interview Questions & Answers
What are semantic elements in HTML5? Give examples
What is the difference between div and section in HTML?
How do you make a web page responsive using HTML and CSS?
What is web accessibility and how does HTML help with it?