🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Web & Software Development › HTML, CSS, and JavaScript for Web Development › Lesson 6
TEC-WEB46-02 · Lesson 6 · 14 clock hours · lab

Responsive Web Design and Media Queries

Objective. Students implement a mobile-first responsive design using CSS media queries, viewport meta tag, flexible units, and fluid images so a page displays correctly on at least three viewport sizes.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

Responsive Web Design and Media Queries

A responsive website adjusts its layout, typography, and images so it looks correct and functions well on any screen — from a 375 px smartphone to a 1280 px desktop monitor. Responsive design is not a single feature; it is a combination of the viewport meta tag, flexible units, fluid images, and CSS media queries working together.

The Viewport Meta Tag

Without the viewport meta tag, mobile browsers render a page at a desktop width and then scale it down, making text tiny and tap targets unreachable. Place this tag in the `<head>` of every page:

```html

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

```

`width=device-width` tells the browser to use the device's actual pixel width. `initial-scale=1` sets the default zoom to 100 %. This single line is the prerequisite for every other responsive technique.

Mobile-First Design

Mobile-first means you write your base CSS for the narrowest screen first, then layer on styles for wider screens using `min-width` media queries. This approach is preferred because:

A mobile-first workflow looks like this:

```css

/ Base styles — applied to all screens, including phones /

body {

font-size: 1rem;

padding: 1rem;

}

/ Tablet and wider /

@media (min-width: 768px) {

body {

padding: 2rem;

}

}

/ Desktop and wider /

@media (min-width: 1280px) {

body {

max-width: 1200px;

margin: 0 auto;

}

}

```

When you refactor a desktop-only CSS file, remove fixed pixel widths from the base rules, replace them with flexible units, and move desktop-specific rules into a `min-width: 1280px` block. Comment every breakpoint decision so other developers understand your reasoning.

CSS Media Queries

A media query is a conditional block that applies CSS only when a condition is true. The most common condition is viewport width:

```css

@media (min-width: 768px) {

/ rules here apply only at 768 px and wider /

}

```

Common breakpoints in industry practice are roughly 768 px (tablet) and 1280 px (desktop), though you should choose breakpoints where your content breaks, not based on specific device names. Document your reasoning in comments.

Flexible Units

Avoid fixed pixel values for layout dimensions. Prefer:

Using these units means your layout stretches and compresses naturally without requiring a breakpoint for every small adjustment.

Fluid Images

Images with a fixed pixel width overflow narrow viewports and break layouts. Apply these two rules to any image that should scale with its container:

```css

img {

max-width: 100%;

height: auto;

}

```

`max-width: 100%` prevents the image from exceeding its container. `height: auto` maintains the original aspect ratio. Apply this to hero images and any content image. Test at 375 px, 768 px, and 1280 px using Chrome DevTools Device Mode.

Using Chrome DevTools Device Mode

In Chrome, press F12 (or right-click → Inspect), then click the device-toolbar icon (a phone/tablet outline). You can type any pixel width into the dimension field. Use 375 px, 768 px, and 1280 px to match the three required breakpoints. Take screenshots at each size for your lab log. DevTools Device Mode simulates viewport dimensions; it does not emulate all aspects of real hardware, so treat it as a fast first check rather than a replacement for testing on real devices when possible.

Accessibility and Usability Safety Points

Responsive design has direct accessibility consequences. Failing to meet these points means real users — including users with disabilities — cannot use your site:

Checking Your Work

Use the 15-point responsive checklist provided in the lab to audit your own page and a classmate's. The pass mark for the instructor audit is 13 of 15 checklist items passing across all three viewports (375 px, 768 px, and 1280 px). Treat a failed item as a bug, not a style preference — document it in your written summary with a specific fix recommendation.

Key terms8

Viewport meta tagAn HTML `<meta>` element placed in `<head>` that instructs the mobile browser to set the layout width to the device's actual screen width and apply a default zoom of 100 %, enabling responsive layouts to render correctly.
Media queryA CSS conditional rule that applies a block of styles only when a specified condition — most commonly a minimum or maximum viewport width — is true.
Mobile-firstA design and coding strategy in which base CSS styles target the narrowest (phone) screen by default, and wider-screen styles are added with `min-width` media queries, ensuring the lightest stylesheet is delivered to small devices.
BreakpointA specific viewport width at which a media query fires and the layout changes; breakpoints should be chosen where the content visually breaks, not by device brand name.
Fluid imageAn image that scales proportionally within its container using `max-width: 100%` and `height: auto`, preventing overflow on narrow screens while maintaining aspect ratio.
Flexible unitA CSS length unit — such as `%`, `em`, `rem`, `vw`, or `vh` — whose computed value depends on context (parent size, root font size, or viewport), allowing layouts to adapt without fixed pixel dimensions.
Chrome DevTools Device ModeA panel in Chrome's developer tools that simulates specific viewport widths so developers can quickly inspect responsive behavior at multiple screen sizes without physical devices.
Tap targetAny interactive element (button, link, form control) that a user activates by touching a touchscreen; accessibility guidelines recommend a minimum physical size so fingers can activate targets accurately.
In class: Mobile-first refactor lab: students take a desktop-only CSS file and restructure it mobile-first — writing base styles for narrow screens, then adding min-width breakpoints for tablet and desktop — and document each breakpoint decision in code comments. · Responsive image exercise: students implement a hero image section using max-width: 100%, height: auto for fluid scaling and test it at 375px, 768px, and 1280px in Chrome DevTools Device Mode, recording screenshots for the lab log. · Cross-device checklist review: using a provided 15-point checklist (text legible without zoom, tap targets meet minimum size guidance, no horizontal scroll), students audit a classmate's responsive page and write a written summary of findings.
Materials: VS Code, Chrome DevTools Device Mode, MDN Responsive Design guide, provided desktop-only CSS starter file, responsive checklist handout, viewport meta tag reference
Check: Instructor audits the mobile-first file using DevTools at 375px, 768px, and 1280px; all 15 checklist items must pass at each width; pass mark 13 of 15 items passing across all three viewports.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

Web fundamentals / HTML
1. Which HTML element is required in the `<head>` to prevent mobile browsers from rendering a page at a full desktop width before scaling it down?
Web fundamentals / CSS
2. A developer writes base CSS for narrow screens and then uses `@media (min-width: 768px)` to add tablet styles. Which design strategy does this describe?
Web fundamentals / CSS
3. Which pair of CSS declarations makes an image scale fluidly within its container without distorting its aspect ratio?
Web fundamentals / CSS
4. A student's page shows a horizontal scrollbar at 375 px viewport width. What is the most likely cause?
Web fundamentals / CSS
5. In a mobile-first stylesheet, where should desktop-specific layout rules such as a three-column grid be placed?
Web fundamentals / CSS
6. Which CSS unit is relative to the `html` element's font size and remains consistent across nested components?
Web fundamentals / professional practice
7. When auditing a classmate's responsive page with the 15-point checklist, a student finds that three checklist items fail across three viewports. According to the lab pass mark, which of the following statements is correct?
Web fundamentals / accessibility
8. A responsive checklist item states that tap targets must meet a minimum size guidance. Why is this requirement considered an accessibility concern rather than just a visual preference?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.