HTML Layout – Learn to Structure Web Pages with HTML
HTML layout defines the structure of a webpage. It organizes the content and helps users navigate it effectively. By combining HTML elements like <header>, <nav>, <section>, <article>, <footer>, and others, you can create clear and responsive layouts.
Key HTML Layout Elements
| Element | Description | Usage Example |
|---|---|---|
<header> |
Defines the top section of a webpage (e.g., logo, title, navigation). | <header>Website Header</header> |
<nav> |
Defines a navigation bar/menu. | <nav>Navigation links</nav> |
<section> |
Defines a thematic grouping of content. | <section>Main content</section> |
<article> |
Defines an independent piece of content (e.g., blog post, news). | <article>Blog Post</article> |
<aside> |
Defines content aside from the main content (e.g., sidebar). | <aside>Sidebar content</aside> |
<footer> |
Defines the footer of a webpage (e.g., copyright, links). | <footer>Footer content</footer> |
<div> |
Defines a container for content (used for styling/layout). | <div>Generic container</div> |
<main> |
Defines the primary content of the webpage. | <main>Main section of the page</main> |
Basic HTML Layout Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basic HTML Layout</title>
</head>
<body>
<header>
<h1>My Website</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="home">
<h2>Welcome to My Website</h2>
<p>This is the main content area.</p>
</section>
<aside>
<h3>Related Links</h3>
<ul>
<li><a href="#link1">Link 1</a></li>
<li><a href="#link2">Link 2</a></li>
</ul>
</aside>
<section id="about">
<h2>About Us</h2>
<p>Information about the website.</p>
</section>
</main>
<footer>
<p>© 2025 My Website. All rights reserved.</p>
</footer>
</body>
</html>
Responsive Layout with CSS
A good layout should be responsive, adapting to different screen sizes.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive HTML Layout</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
}
header {
background: #007acc;
color: white;
padding: 10px;
text-align: center;
}
nav ul {
display: flex;
justify-content: center;
list-style-type: none;
padding: 0;
}
nav ul li {
margin: 0 15px;
}
nav ul li a {
color: white;
text-decoration: none;
}
main {
display: flex;
flex-wrap: wrap;
padding: 20px;
}
section {
flex: 2;
margin: 10px;
padding: 20px;
background: #f9f9f9;
}
aside {
flex: 1;
margin: 10px;
padding: 20px;
background: #f0f0f0;
}
footer {
background: #333;
color: white;
text-align: center;
padding: 10px;
}
@media (max-width: 600px) {
main {
flex-direction: column;
}
aside {
order: -1;
}
}
</style>
</head>
<body>
<header>
<h1>Responsive Website</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section id="home">
<h2>Welcome</h2>
<p>This section adjusts based on screen size.</p>
</section>
<aside>
<h3>Sidebar</h3>
<p>Additional information goes here.</p>
</aside>
<section id="about">
<h2>About</h2>
<p>This section also adapts responsively.</p>
</section>
</main>
<footer>
<p>© 2025 Responsive Website. All rights reserved.</p>
</footer>
</body>
</html>
Best Practices for Layout Design
- Use Semantic Tags: Prefer
<header>,<main>,<section>, etc., over<div>for clarity. - Responsive Design: Use CSS media queries to ensure your layout looks good on all devices.
- Accessibility: Include proper ARIA roles and labels for better usability.
- Consistent Structure: Keep navigation, headers, and footers consistent across all pages.
A well-structured layout improves both usability and aesthetics. By using semantic HTML and applying CSS for responsiveness, you can create professional and functional designs.