One Page.
Three Layouts.
Learn how to make a web page adapt to different screen sizes using CSS media queries. You will start with a simple student portfolio wireframe and transform it for desktop, tablet, and mobile.
What is responsive design?
People visit websites on laptops, tablets, and phones. These screens have different amounts of space. A layout that looks good on a laptop might feel crowded on a phone.
Responsive design means a page can adjust its layout to fit the screen. We can change the number of columns, spacing, and arrangement of content with CSS.
Today’s goal
Build one page and use @media screen to change its layout at different screen widths. We are creating a wireframe, so focus on structure rather than color, decoration, or polished graphics.
01 / What is a media query?
A media query lets CSS apply only when a condition is met. For responsive web layouts, we commonly check the width of the browser’s viewport.
@media screen and (max-width: 600px) { .example { background-color: lightblue; } }
Read this as: “When the output is a screen and the viewport is 600 pixels wide or narrower, apply these styles to .example.”
@media screen
Targets screen-based displays, such as a computer, tablet, or phone.
max-width
Applies the rules at the stated width and below.
CSS rules
Define what changes, such as columns, spacing, or alignment.
02 / Three screen sizes
For this exercise, we will use three layout states. These are practice breakpoints, not universal rules: real websites choose breakpoints based on when their content needs to change.
| View | Viewport width | Portfolio layout |
|---|---|---|
| Regular / desktop | Above 850px | Two-column introduction; three project columns. |
| Tablet | 601–850px | Two-column introduction; two project columns. |
| Mobile | 600px and below | Stacked introduction; one project column. |
Important: The browser viewport is the visible area where the page appears, not necessarily the physical size of the device. You can test it by resizing your browser or the CodePen preview.
03 / See the layout as a wireframe
A wireframe is a simplified plan for a page. It uses basic shapes to show where content belongs before we decide on the final visual design.
Regular / desktop
Tablet
Mobile
These diagrams illustrate the intended layout. Your own CodePen page will change automatically as its viewport changes.
04 / How CSS changes the layout
We will use CSS Grid to arrange our content. A desktop layout can use three equal columns. At a narrower width, a media query changes the grid to two columns. On mobile, it becomes one.
.projects { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media screen and (max-width: 850px) { .projects { grid-template-columns: repeat(2, 1fr); } }
@media screen and (max-width: 600px) { .projects { grid-template-columns: 1fr; } }
Notice: We do not need to create three different pages. We have one HTML document, and the CSS changes its layout when the viewport reaches a breakpoint.
Build a Responsive Student Portfolio
Your task: Create a simple, single-page portfolio for a fictional student. Use a wireframe approach: basic rectangles, simple text, and clear organization. Your main goal is to demonstrate how @media screen changes the page at regular, tablet, and mobile sizes.
What your page needs
- A header with the student’s name and simple navigation.
- An introduction section with a short bio and a placeholder for a profile image.
- A projects section with three sample projects.
- A footer with a contact line.
- A responsive layout using two media queries.
Part 1 / Set up CodePen
Open CodePen and create a new Pen. Put all of your HTML and CSS in the HTML panel, including the <style> tags. You do not need a separate CSS panel for this activity.
Part 2 / Start with this wireframe
Copy the starter code below into your HTML panel. It includes the basic page structure and the regular desktop layout. Your job is to complete the tablet and mobile media queries and test all three views.
<!-- Responsive Student Portfolio --> <style> * { box-sizing: border-box; } body { margin: 0; font-family: Arial, sans-serif; line-height: 1.5; background: #f2f2f2; color: #222; } header, footer { padding: 20px; background: #d5d5d5; } nav { display: flex; gap: 16px; flex-wrap: wrap; } nav a { color: #222; } main { max-width: 1000px; margin: 0 auto; padding: 20px; } .intro { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; margin-bottom: 24px; } .panel { background: #fff; border: 1px solid #bbb; padding: 18px; min-width: 0; } .projects { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; } .project { min-height: 120px; background: #e0e0e0; border: 1px solid #bbb; padding: 16px; } /* TABLET: add your media query here */ /* MOBILE: add your media query here */ </style> <header> <h1>Alex Morgan</h1> <nav> <a href="#about">About</a> <a href="#projects">Projects</a> <a href="#contact">Contact</a> </nav> </header> <main> <section class="intro" id="about"> <div class="panel"> <h2>About Me</h2> <p> I am a student exploring design, technology, and creative ideas. </p> </div> <div class="panel"> <p>[ Profile Image Placeholder ]</p> </div> </section> <section id="projects"> <h2>My Projects</h2> <div class="projects"> <article class="project"> Project 01 </article> <article class="project"> Project 02 </article> <article class="project"> Project 03 </article> </div> </section> </main> <footer id="contact"> Contact: alex@example.com </footer>
Part 3 / Add the tablet layout
Find the tablet comment inside the CSS. Write a media query that applies when the screen is 850 pixels wide or narrower.
- Change
.projectsfrom three columns to two. - Keep the introduction side by side for now.
- Resize the preview to see when the new rule takes effect.
Part 4 / Add the mobile layout
Find the mobile comment. Write a second media query for screens 600 pixels wide or narrower.
- Change
.projectsto one column. - Change
.introto one column. - Make sure all text and project panels fit within the screen.
Part 5 / Test all three views
Use the CodePen preview and resize it. Check the layout at approximately these widths:
- Regular: 1000px wide — three project columns.
- Tablet: 768px wide — two project columns.
- Mobile: 390px wide — one project column and a stacked introduction.
Before you finish
Do not make three separate pages. The same HTML should adapt through your media queries. Your goal is to show that you understand how and when the layout changes.
05 / Submission checklist
- I created one single-page student portfolio in CodePen.
- I used
@media screenfor the tablet and mobile views. - The regular view shows three project columns.
- The tablet view shows two project columns.
- The mobile view shows one project column.
- The introduction changes from two columns to one on mobile.
- I tested the layout at all three widths.
- I saved my Pen and can share its URL.
What to submit
Submit the shareable URL to your CodePen. Your instructor should be able to open the Pen and resize the preview to verify all three layouts.
Remember
Responsive design is not about shrinking everything to fit. It is about making thoughtful decisions about how content should be arranged at different screen sizes.
Start with a clear structure, use media queries to change the layout, and test your work at multiple widths.
One page. One set of content. Three responsive layouts.