How to Create a Responsive Website Using HTML and CSS (Beginner-Friendly Guide)
Want to build a website that looks great on desktops, tablets, and smartphones?
You don't need complicated frameworks or advanced programming skills to get started.
With just HTML and CSS, you can create a simple responsive website from scratch.
In this tutorial, we'll build a basic responsive webpage step by step.
What Does Responsive Web Design Mean?
Responsive web design means creating websites that automatically adapt to different screen sizes.
For example:
- Desktop users see a wider layout.
- Tablet users get an adjusted layout.
- Mobile users see a compact, easy-to-read design.
The goal is to provide a good experience regardless of the device.
Step 1: Create Your Project Files
First, create a folder called responsive-website.
Inside it, create two files:
responsive-website/
├── index.html
└── style.css
The HTML file will contain the website structure, while CSS will control its appearance.
Step 2: Write the HTML Structure
Open index.html and add the following code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Responsive Website</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>My Website</h1>
<nav>
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</nav>
</header>
<main>
<section class="hero">
<h2>Welcome to My Website</h2>
<p>A simple website built with HTML and CSS.</p>
<button>Get Started</button>
</section>
</main>
<footer>
<p>© 2026 My Website. All rights reserved.</p>
</footer>
</body>
</html>
This creates the basic structure of our website.
Step 3: Add CSS Styling
Now open style.css and add:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
line-height: 1.6;
background: #f4f6f9;
color: #333;
}
header {
background: #222;
color: white;
padding: 20px 8%;
display: flex;
justify-content: space-between;
align-items: center;
}
nav a {
color: white;
text-decoration: none;
margin-left: 20px;
}
.hero {
text-align: center;
padding: 100px 20px;
}
.hero h2 {
font-size: 36px;
margin-bottom: 15px;
}
.hero p {
margin-bottom: 25px;
}
button {
background: #2563eb;
color: white;
border: none;
padding: 12px 25px;
border-radius: 6px;
cursor: pointer;
}
footer {
text-align: center;
padding: 20px;
background: #222;
color: white;
}
At this point, your website should have a clean and simple layout.
Step 4: Make It Responsive
This is the most important part.
Add the following media query at the bottom of your CSS file:
@media (max-width: 600px) {
header {
flex-direction: column;
gap: 15px;
}
nav a {
margin: 0 8px;
}
.hero {
padding: 60px 15px;
}
.hero h2 {
font-size: 28px;
}
}
This tells the browser to adjust the layout when the screen width is 600 pixels or smaller.
The navigation becomes vertically arranged, and the heading gets smaller to fit mobile screens.
Step 5: Test Your Website
Save both files and open index.html in your browser.
To test the responsive layout:
- Open your website in Chrome.
- Right-click and select Inspect.
- Click the device toolbar icon.
- Switch between different device sizes.
- Check whether the content fits properly.
You can also resize your browser window manually.
Final Thoughts
Creating a responsive website doesn't have to be complicated.
HTML provides the structure, while CSS controls the design and responsiveness.
Once you understand these fundamentals, you can move on to more advanced techniques such as CSS Grid, Flexbox, animations, and JavaScript.
The best way to improve is to keep building small projects and experimenting with different layouts.
Have you built your first responsive website yet? Share your experience in the comments!
Top comments (0)