⚠️ This lesson is retired and might contain outdated information.

Scale a Page Correctly for Small Viewports with a <meta> Tag

Rory Smith
InstructorRory Smith
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 2 years ago

There is a certain <meta> tag we need to make use of in order to display content how we want on mobile devices. The tag is going to make sure page content scales in a way that suits small viewports.

Instructor: [00:00] Here in our index.html, we have an example page of Laura Ipsen text split into paragraphs. Let's go to iOS Safari and see how this looks. We can see that all of our text is really small and very difficult to read on a mobile device because of its small viewport. Let's switch over to Chrome on Android to see how that looks and we have a similar situation here. Luckily there's a solution to this.

[00:31] Let's go over to our code, specifically into our head tag. We're going to need a meta tag. We're going to target the viewport, we're going to give it name equals viewport. We're going to use the content attribute. This is going to be a string of settings. We're going to use width equals device width.

[00:54] Let's save this and head back over to iOS Safari. Let's refresh. Instantly the scale of our page is different because of the meta tag that we're using. Everything is a lot more easy to read now. Let's check it out on Android Chrome, and everything is slightly larger. The main difference though can be seen on Safari in our case, because we're comparing an iPhone 5s screen with a Nexus 5x screen. The 5x screen is significantly bigger.

[01:33] We can control the scale of our page on a mobile device using pinch zoom. If we pinch zoom on Safari, we can change the scale. As of Safari 10, we can't affect this with the meta tag that we're using. However, we can affect Chrome.

[01:53] Let's head back over back to our Android simulator. We'll pinch zoom to see that we can change the scale. Let's go back to our meta tag. In the content attribute, we'll pass in maximum scale equals one. Let's save and refresh.

[02:17] Now in Chrome when we pinch zoom, the scale isn't changed. It's worth bearing in mind that by doing this you may be affecting the level of accessibility on the page.

egghead
egghead
~ a minute ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today