TechnicalEasy HTML & CSS
How do you make a website responsive?
Asked for Frontend Developer, Full-Stack Developer
Why they ask this: Most users in Nepal browse on mobile phones, so responsive design is a must-have skill.
Answer
- Add the viewport meta tag:
<meta name="viewport" content="width=device-width, initial-scale=1">. - Design mobile-first: write base styles for small screens, then add
min-widthmedia queries for larger ones. - Use flexible layouts (Flexbox, Grid with
frandminmax()) and relative units (%,rem,vw) instead of fixed pixel widths. - Make media fluid:
img { max-width: 100%; height: auto; }, and usesrcsetfor different image sizes. - Test on real devices and in the browser DevTools device mode.
css
.grid { display: grid; gap: 1rem; }
@media (min-width: 768px) {
.grid { grid-template-columns: repeat(2, 1fr); }
}Can you explain this in your own words?