
Responsive web design ensures your web pages look and function well on every screen size, from small smartphones to large desktop monitors. While frameworks and builders can help, understanding how to create responsive layouts with pure HTML and CSS gives you complete control, lighter pages, and skills that transfer to any project. In this step-by-step tutorial you will build a responsive web page in HTML and CSS, including a navigation bar with a mobile menu, a hero section, a feature grid, responsive images, and a footer.
Professional Responsive Development from AAMAX.CO
Hand-coding responsive layouts is a valuable skill, but production websites require rigorous testing, performance optimization, and polished design. AAMAX.CO is a full service digital marketing company that offers web development, digital marketing, and SEO services worldwide. Their developers write clean, semantic HTML and modern CSS to build responsive websites that load quickly and adapt flawlessly across devices. They combine technical precision with SEO expertise, ensuring your site performs well for users and search engines alike.
Step 1: Set Up the HTML Document
Begin with a well-structured HTML file including the viewport meta tag, which is essential for responsive behavior:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Responsive Page</title> <link rel="stylesheet" href="styles.css"></head><body></body></html>Step 2: Build the Semantic Structure
Add the page content using semantic elements:
<header class="header"> <a href="/" class="brand">Brand</a> <button class="menu-toggle" aria-expanded="false" aria-controls="nav">Menu</button> <nav id="nav" class="nav"> <a href="#features">Features</a> <a href="#about">About</a> <a href="#contact">Contact</a> </nav></header><main> <section class="hero"> <div class="hero-text"> <h1>Build for every screen</h1> <p>Responsive design made simple.</p> </div> <img src="hero.webp" alt="Devices showing a responsive layout" width="800" height="600"> </section> <section id="features" class="features"> <article class="feature">...</article> <article class="feature">...</article> <article class="feature">...</article> </section></main><footer class="footer">...</footer>Step 3: Add a CSS Reset and Base Styles
Normalize box sizing and set fluid foundations:
*, *::before, *::after { box-sizing: border-box; }body { margin: 0; font-family: system-ui, sans-serif; line-height: 1.6; }img { max-width: 100%; height: auto; display: block; }.container { width: min(100% - 2rem, 1200px); margin-inline: auto; }The min() function keeps a comfortable gutter on small screens while capping width on large displays.
Step 4: Style the Mobile Layout First
Write default styles for small screens. Stack elements vertically and hide the navigation behind a toggle:
.header { display: flex; justify-content: space-between; align-items: center; padding: 1rem; flex-wrap: wrap; }.nav { display: none; width: 100%; flex-direction: column; gap: 0.75rem; padding-top: 1rem; }.nav.open { display: flex; }.hero { display: grid; gap: 2rem; padding: 3rem 1rem; }.features { display: grid; gap: 1.5rem; padding: 2rem 1rem; }Step 5: Make the Mobile Menu Work
A few lines of JavaScript toggle the menu and update accessibility attributes:
const toggle = document.querySelector(".menu-toggle");const nav = document.getElementById("nav");toggle.addEventListener("click", () => { const open = nav.classList.toggle("open"); toggle.setAttribute("aria-expanded", open);});The aria-expanded attribute tells screen reader users whether the menu is open.
Step 6: Add Tablet Breakpoint Styles
At medium widths, display features in two columns:
@media (min-width: 640px) { .features { grid-template-columns: repeat(2, 1fr); }}Step 7: Add Desktop Breakpoint Styles
On larger screens, show the full navigation, place the hero text beside the image, and expand features to three columns:
@media (min-width: 1024px) { .menu-toggle { display: none; } .nav { display: flex; flex-direction: row; width: auto; padding-top: 0; gap: 2rem; } .hero { grid-template-columns: 1fr 1fr; align-items: center; padding: 5rem 2rem; } .features { grid-template-columns: repeat(3, 1fr); }}Step 8: Use Fluid Typography
Instead of setting different font sizes at each breakpoint, use clamp() for smooth scaling:
h1 { font-size: clamp(2rem, 4vw + 1rem, 3.75rem); line-height: 1.15; }p { font-size: clamp(1rem, 0.5vw + 0.9rem, 1.125rem); }Step 9: Serve Responsive Images
Deliver smaller files to mobile devices with srcset and sizes:
<img src="hero-800.webp" srcset="hero-400.webp 400w, hero-800.webp 800w, hero-1600.webp 1600w" sizes="(min-width: 1024px) 50vw, 100vw" alt="Devices showing a responsive layout" width="800" height="600">The browser chooses the most appropriate file, saving bandwidth and improving load times.
Step 10: Test and Refine
Open the page in your browser and slowly resize the window, watching for awkward line breaks, overflowing elements, or cramped spacing. Use device emulation in developer tools and test on actual phones. Check keyboard navigation and focus styles for the menu. Polished website design refines these details so every breakpoint looks intentional.
Best Practices to Remember
- Write mobile styles first and enhance with
min-widthmedia queries. - Use relative units like
rem,%, andfrrather than fixed pixels. - Set width and height on images to prevent layout shift.
- Keep touch targets at least 44 pixels tall.
- Avoid horizontal scrolling at any width.
- Choose breakpoints based on content rather than device names.
As your project grows into multiple templates, CMS integration, or interactive features, structured website development keeps responsive code maintainable and consistent.
Conclusion
Creating responsive web design in HTML and CSS comes down to a solid semantic structure, the viewport meta tag, a mobile-first stylesheet, flexible grids, fluid images and typography, and well-placed media queries. With a small amount of JavaScript for the mobile menu, you can build a complete responsive page that works beautifully everywhere. Practice these techniques, and you will be able to make any design adapt to any screen.