Main Article
Primary content area
Modern web layout combines HTML5 semantic elements with CSS techniques like Flexbox and Grid to create responsive, accessible, and maintainable website structures.
HTML5 introduced semantic elements that describe their meaning to browsers and developers.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Semantic Layout Example</title>
</head>
<body>
<header>
<nav>
<!-- Navigation content -->
</nav>
</header>
<main>
<article>
<!-- Main article content -->
</article>
<aside>
<!-- Sidebar content -->
</aside>
</main>
<footer>
<!-- Footer content -->
</footer>
</body>
</html>Primary content area
Container for introductory content or navigation
Navigation links section
Main content of the document
Self-contained composition
Thematic grouping of content
Content indirectly related to main content
Footer for its nearest section
Self-contained content with caption
One-dimensional layout model for flexible content distribution.
/* Flexbox Container */
.flex-container {
display: flex;
flex-direction: row; /* or column */
justify-content: space-between; /* main axis alignment */
align-items: center; /* cross axis alignment */
flex-wrap: wrap; /* allow wrapping */
gap: 20px; /* space between items */
}
/* Flexbox Items */
.flex-item {
flex: 1; /* grow and shrink equally */
min-width: 200px; /* minimum width */
}
/* Responsive Flexbox */
@media (max-width: 768px) {
.flex-container {
flex-direction: column;
gap: 15px;
}
.flex-item {
min-width: 100%;
}
}
/* Practical Example */
<header class="flex-container">
<div class="logo">Logo</div>
<nav class="flex-container">
<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#contact">Contact</a>
</nav>
</header>Two-dimensional layout system for complex layouts.
/* Grid Container */
.grid-container {
display: grid;
grid-template-columns: 1fr 2fr 1fr; /* three columns */
grid-template-rows: auto; /* automatic row sizing */
gap: 20px; /* space between items */
grid-template-areas:
"header header header"
"sidebar main aside"
"footer footer footer";
}
/* Grid Items */
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.aside { grid-area: aside; }
.footer { grid-area: footer; }
/* Responsive Grid */
@media (max-width: 1024px) {
.grid-container {
grid-template-columns: 1fr 3fr;
grid-template-areas:
"header header"
"sidebar main"
"aside aside"
"footer footer";
}
}
@media (max-width: 768px) {
.grid-container {
grid-template-columns: 1fr;
grid-template-areas:
"header"
"sidebar"
"main"
"aside"
"footer";
}
}
/* Practical Example */
<div class="grid-container">
<header class="header">Header</header>
<aside class="sidebar">Sidebar</aside>
<main class="main">Main Content</main>
<aside class="aside">Additional Info</aside>
<footer class="footer">Footer</footer>
</div>Essential for responsive design on mobile devices.
<!-- Essential viewport meta tag -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Additional viewport options -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<!-- For specific device handling -->
<meta name="viewport" content="width=1200"> <!-- Fixed width -->Apply different styles based on device characteristics.
/* Basic media query structure */
@media media-type and (media-feature) {
/* CSS rules */
}
/* Common breakpoints */
@media (max-width: 1200px) {
/* For large tablets and small laptops */
}
@media (max-width: 992px) {
/* For tablets */
}
@media (max-width: 768px) {
/* For mobile devices */
}
@media (max-width: 576px) {
/* For small mobile devices */
}
/* Orientation-based queries */
@media (orientation: landscape) {
/* Landscape mode styles */
}
@media (orientation: portrait) {
/* Portrait mode styles */
}
/* Resolution-based queries */
@media (min-resolution: 2dppx) {
/* High-resolution displays */
}
/* Combined queries */
@media (max-width: 768px) and (orientation: portrait) {
/* Mobile portrait specific styles */
}
/* Mobile-first approach (min-width) */
@media (min-width: 576px) {
/* Small devices and up */
}
@media (min-width: 768px) {
/* Medium devices and up */
}
@media (min-width: 992px) {
/* Large devices and up */
}
@media (min-width: 1200px) {
/* Extra large devices */
}A fully responsive layout using semantic HTML and modern CSS.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Layout Example</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}
/* Header Styles */
header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 1rem 0;
position: sticky;
top: 0;
z-index: 100;
}
.header-content {
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-size: 1.5rem;
font-weight: bold;
}
.nav-menu {
display: flex;
list-style: none;
gap: 2rem;
}
.nav-menu a {
color: white;
text-decoration: none;
transition: opacity 0.3s;
}
.nav-menu a:hover {
opacity: 0.8;
}
/* Main Content */
main {
padding: 2rem 0;
}
.hero {
text-align: center;
padding: 3rem 0;
background: #f8f9fa;
margin-bottom: 2rem;
}
.features {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
margin-bottom: 2rem;
}
.feature-card {
background: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
text-align: center;
}
/* Footer */
footer {
background: #2c3e50;
color: white;
padding: 2rem 0;
text-align: center;
}
/* Responsive Design */
@media (max-width: 768px) {
.header-content {
flex-direction: column;
gap: 1rem;
}
.nav-menu {
flex-direction: column;
gap: 1rem;
text-align: center;
}
.hero {
padding: 2rem 0;
}
.features {
grid-template-columns: 1fr;
}
}
@media (max-width: 480px) {
.container {
padding: 0 15px;
}
.feature-card {
padding: 1.5rem;
}
.hero h1 {
font-size: 1.5rem;
}
}
</style>
</head>
<body>
<header>
<div class="container">
<div class="header-content">
<div class="logo">MyWebsite</div>
<nav>
<ul class="nav-menu">
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</div>
</div>
</header>
<main>
<div class="container">
<section class="hero">
<h1>Welcome to Our Website</h1>
<p>Discover amazing features and services</p>
</section>
<section class="features">
<article class="feature-card">
<h3>Feature One</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
</article>
<article class="feature-card">
<h3>Feature Two</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
</article>
<article class="feature-card">
<h3>Feature Three</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
</article>
</section>
</div>
</main>
<footer>
<div class="container">
<p>© 2024 MyWebsite. All rights reserved.</p>
</div>
</footer>
</body>
</html>| Device Type | Breakpoint | Usage |
|---|---|---|
| Mobile (small) | ≤ 576px | Smartphones portrait |
| Mobile (large) | ≤ 768px | Smartphones landscape, small tablets |
| Tablet | ≤ 992px | Tablets portrait |
| Desktop (small) | ≤ 1200px | Tablets landscape, small laptops |
| Desktop (large) | ≥ 1200px | Large screens, desktops |
Device simulation and responsive testing
Bootstrap, Tailwind CSS, Foundation
BrowserStack, LambdaTest, Responsive Design Checker
Lighthouse, PageSpeed Insights, WebPageTest