๐Ÿ“Š We use cookies & analytics to improve your experience. Learn more
Latest

Full-Stack Web Development Bootcamp Module 1 ยท Lesson 3 of 15

0% Exit to course

Module 1 ยท The browser: HTML and CSS Lesson 3 of 15

Mobile-first and the viewport

Learning objective

Most Indian traffic is a phone, so the phone is the design, not the fallback. Start there, then add width.

The concept

Mobile-first means you write the phone layout first and add complexity at wider widths, instead of designing a desktop page and shrinking it. Almost every fresher-portfolio visitor is on a phone, and a page that starts narrow cannot be broken by a narrow screen.

Two lines make it real. In the head: <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> โ€” without it a phone pretends to be a 980px desktop and zooms out. Then in CSS, write your base rules for small screens and add @media (min-width: 720px) { โ€ฆ } for larger ones, never the reverse.

CSS
/* The base rules ARE the phone. Wider screens are the addition. */
.card { padding: 14px; font-size: 15px; }

@media (min-width: 720px) {
  .card { padding: 22px; font-size: 16px; }
}

Common mistakes

The mistake is position: fixed or width: 1200px in the base rules, which produces horizontal scrolling on a phone. Check every page at 360px before you call it finished: a single long word or one wide image is enough to make the whole page slide sideways.

Worked example

Writing base styles for a 390px screen and adding one @media (min-width: 783px) block afterwards produces a better result than shrinking a desktop layout later.

Your practice task

Rebuild one page of your own starting at 390px, and check it at 320px, 390px and 1440px before adding anything.

Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.

Key takeaway

Mobile-first means you write the phone layout first and add complexity at wider widths, instead of designing a desktop page and shrinking it.

Create free account or sign in

Almost there

15 lessons left of 15

Finish every lesson to unlock the certificate. Each one ends in a practice task โ€” do them and the final project brief writes itself.

Next recommended course Data Analytics with SQL & Excel