CSS: CSS Responsive Basics

Last updated: 2026-10-13

Responsive design makes web pages look good on all devices — from mobile phones to desktop monitors.

Properties in this section: font-size

1. Viewport Meta Tag

Must-have tag for responsive design:

HTML
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Without this tag, mobile browsers render pages at desktop width (usually 980px) and shrink to fit — text becomes unreadable.


2. Media Queries

Apply different styles at different screen sizes:

▶ Example

▶ Try it Yourself

3. Relative Units

Unit Reference Best For
% Parent element Container widths
em Parent font size Padding, margins
rem Root font size Font sizes
vw Viewport width Full-width elements
vh Viewport height Full-screen sections

▶ Example

▶ Try it Yourself

4. Mobile-First Approach

Design for mobile first, then enhance for larger screens:

CSS
/* Base styles (mobile) */
.container {
  width: 100%;
  padding: 10px;
}

/* Tablet */
@media (min-width: 768px) {
  .container {
    width: 750px;
    margin: 0 auto;
  }
}

/* Desktop */
@media (min-width: 1200px) {
  .container {
    width: 1170px;
  }
}

▶ Example

Mobile-first responsive typography:

▶ Try it Yourself

5. Flexible Images

Make images responsive:

CSS
img {
  max-width: 100%;
  height: auto;
}

Properties in this section: font-size

❓ FAQ

Q What happens without viewport meta tag?
A Mobile browsers render at desktop width (usually 980px), then shrink to fit phone screen. Text becomes unreadable, requiring pinch-zoom. The viewport meta tag is the foundation of responsive design.
Q How to choose media query breakpoints?
A Write mobile styles first (mobile-first), then enhance with min-width. Common breakpoints: mobile < 576px, tablet 768px, laptop 992px, desktop 1200px. Don't be constrained by these numbers — choose breakpoints based on your actual content.
Q Must responsive design use rem?
A Not necessarily. rem suits font sizes; layout dimensions use %, fr, vw/vh. The key is not using fixed px for layout sizes. Font sizes: rem; containers: %; spacing: em or rem.

📖 Summary

📝 Exercises

  1. Create a page: three columns on desktop, two on tablet, one on mobile (using media queries).
  2. Set font sizes with rem, then modify root font-size in media query to see proportional scaling.
  3. Create a responsive navbar: horizontal on desktop, hidden (or hamburger) on mobile.
  4. Set max-width: 100% on images, resize browser to see responsive behavior.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏