01
What does responsive mean?
A responsive website adapts its layout to the size of the screen it’s viewed on.
The same content can be arranged differently on a computer, tablet and phone.
02
The viewport meta tag
You’ve already used this line in your HTML files.
This tag tells the browser to match the page width to the device’s viewport width.
width=device-width sets the viewport width to the device width.
initial-scale=1.0 sets the initial zoom level.
03
Avoid fixed widths
Imagine you write this CSS.
width: 1200px;
}
On a phone, that section could be much wider than the screen.
Here’s a more flexible option.
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
The section can shrink on small screens and is capped at 1,200 pixels on larger screens.
04
Make images flexible too
An oversized image can extend beyond the edge of the screen.
Use this rule to keep it within its container.
max-width: 100%;
height: auto;
}
The image can shrink to fit its container while keeping its original proportions.
05
What are media queries?
Media queries let you apply CSS rules only when specific conditions are met.
Here’s an example.
h1 {
font-size: 40px;
}
}
This is how it works.
06
Adapt your main heading
In the previous lesson, you used a large heading.
font-size: 64px;
}
That size can be too large on a phone.
Add this rule for smaller screens.
h1 {
font-size: 42px;
}
}
07
Reduce spacing on mobile
Generous spacing works on a desktop, but can take up too much room on a smaller screen.
Suppose your sections use this padding.
padding: 90px 30px;
}
You can reduce it on smaller screens with this rule.
section {
padding: 60px 20px;
}
}
08
Switch to a single column
Imagine your services section uses a three-column grid.
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;
}
On mobile, switch to one column.
.services-grid {
grid-template-columns: 1fr;
}
}
The cards will stack vertically.
09
Adapt a simple navigation menu
If your horizontal menu no longer fits, stack the items vertically.
nav {
flex-direction: column;
align-items: flex-start;
gap: 20px;
}
}
Later, you can use JavaScript to build a hamburger menu like the one on Digital Ukhti.
10
Use fluid sizes where they help
CSS provides a useful function called clamp().
Here’s an example.
font-size: clamp(40px, 6vw, 72px);
}
This lets the text size change gradually as the viewport changes.
40px is the minimum size.
6vw is the preferred size, based on viewport width.
72px is the maximum size.
11
Test your website at different widths
You can do this with a single computer.
Browser developer tools can simulate different screen sizes.
Open your page in Chrome or Edge.
Right-click the page and choose Inspect.
Turn on the device toolbar.
Try several screen widths.
Drag the edge of the preview to see how the layout responds between device sizes.
12
What to check on mobile
All content fits within the screen.
The text is large enough to read.
Buttons are easy to tap.
Images keep their proportions.
Columns rearrange as intended.
The navigation is still easy to use.
SUMMARY
What you’ve learned
- A responsive website adapts to the screen size.
- The viewport meta tag is essential on mobile.
- Avoid fixed widths where flexibility is needed.
- Use max-width: 100% to keep images within their containers.
- Media queries apply styles at specific widths.
- Headings should adapt to small screens.
- Spacing can be reduced on small screens.
- Grids can switch from several columns to one.
- Navigation should remain easy to use.
- clamp() lets you set fluid sizes.
- Test your website at several widths.
PUT IT INTO PRACTICE
Make your website responsive
Open the project you built in the previous lessons and adapt its CSS.
- Check that the viewport meta tag is present.
- Add max-width: 100% to images.
- Create a media query for widths of 768px or less.
- Reduce the h1 size on mobile.
- Reduce section padding.
- Switch multi-column layouts to one column.
- Adapt the navigation.
- Check the buttons.
- Test the page at several widths.