Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML

Yongyu Zhang
Yongyu Zhang
1,892 Points

I can't understand the "viewport" part of "responsive web design".

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

How does it work?

2 Answers

Erik S.
Erik S.
9,789 Points

Hi, W3Schools explains it quite nicely and has some example images.

As Erik points out W3Schools has a pretty good explanation.

Quoting from their explanation, "the viewport is the visible area of a webpage which varies with devices". Before HTML5 came about, many people just resized their webpage to a smaller scale to fit tablets or mobile phones to fit the screen. Then when HTML5 introduced control over the viewport within the meta tag, it was possible for developers and designers to control that scaling and the dimensions.

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

So now when it came to making a website responsive, HTML5 gave us the ability to set the width of the page to be proportional to the screen width of the device regardless of what it might be, whereas the initial-scale part sets the zoom level when the page is loaded.

Anyways you should really check out that explanation over there, they do a pretty good job explaining it with images