Project: Responsive Landing Page
Let's style a complete landing page for a small business, using variables, flexbox, grid, hover effects and a media query. It works on phones and computers.
A landing page is a single page that introduces a business or product and asks visitors to do one thing - call, order, sign up. It's a classic freelance and interview project, and it combines everything from this course. Read through the code section by section, then change the text, colours and images to make it your own.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Chai Corner</title>
<style>
:root { --brand: #b45309; --dark: #1c1917; --light: #fef3c7; --radius: 14px; }
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; color: var(--dark); line-height: 1.6; }
nav { display: flex; justify-content: space-between; align-items: center;
padding: 14px 20px; background: var(--dark); color: #fff; position: sticky; top: 0; }
nav a { color: #fff; text-decoration: none; margin-left: 16px; }
.hero { text-align: center; padding: 70px 20px;
background: linear-gradient(135deg, var(--light), #fde68a); }
.hero h1 { font-size: clamp(2rem, 6vw, 3.5rem); margin: 0 0 10px; }
.btn { display: inline-block; background: var(--brand); color: #fff; padding: 12px 24px;
border-radius: 999px; text-decoration: none; transition: transform .2s; }
.btn:hover { transform: translateY(-3px); }
.menu { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px; padding: 40px 20px; max-width: 1000px; margin: auto; }
.item { background: #fff; border-radius: var(--radius); padding: 20px;
box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.item b { color: var(--brand); }
footer { text-align: center; padding: 20px; background: var(--dark); color: #d6d3d1; }
@media (max-width: 600px) {
nav { flex-direction: column; gap: 8px; }
nav a { margin: 0 8px; }
}
</style>
</head>
<body>
<nav>
<strong>☕ Chai Corner</strong>
<div><a href="#menu">Menu</a><a href="#visit">Visit</a></div>
</nav>
<section class="hero">
<h1>Fresh chai, every morning</h1>
<p>Masala, ginger and cardamom chai made with love in Lucknow.</p>
<a class="btn" href="#menu">See the menu</a>
</section>
<section class="menu" id="menu">
<div class="item"><h3>Masala chai</h3><p>Spiced and strong.</p><b>₹20</b></div>
<div class="item"><h3>Adrak chai</h3><p>Fresh ginger kick.</p><b>₹20</b></div>
<div class="item"><h3>Elaichi chai</h3><p>Sweet cardamom.</p><b>₹25</b></div>
<div class="item"><h3>Bun maska</h3><p>Soft bun, lots of butter.</p><b>₹30</b></div>
</section>
<footer id="visit">Open 7 am - 10 pm · Hazratganj, Lucknow</footer>
</body>
</html>▶ Try it yourselfWhat you used
- CSS variables for the colours and corner radius
- A sticky flexbox navigation bar
clamp()for a heading that grows with the screen but stays between two sizes- An
auto-fitgrid that changes the number of columns by itself - A media query for small phones
- A smooth hover lift on the button
Challenge
- Add a dark mode with
@media (prefers-color-scheme: dark)by changing the variables. - Add pictures to the menu cards with
aspect-ratioandobject-fit: cover. - Style your HTML portfolio page from the HTML project in the same way.
📝 Test yourself
1. What does clamp(2rem, 6vw, 3.5rem) do?
2. Why use repeat(auto-fit, minmax(200px, 1fr))?
3. Fill in the at-rule used for phone-only styles:
@ (max-width: 600px) { ... }
