Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is viewport in HTML.

What is viewport in HTML? Could you give some examples on how to access the viewport details?

like image 503
minil Avatar asked May 30 '10 17:05

minil


People also ask

What is the use of viewport in CSS?

The viewport is the user's visible area of a web page. The viewport varies with the device, and will be smaller on a mobile phone than on a computer screen. Before tablets and mobile phones, web pages were designed only for computer screens, and it was common for web pages to have a static design and a fixed size.

What is viewport and why is it needed?

The viewport meta tag allows you to simply use max and min-width that span from desktop to mobile devices. "The viewport meta tag allows you to simply use max and min-width that span from desktop to mobile devices." How does omitting the tag prevent you from doing this?

What is meant by viewport and view width?

In an SVG document, the viewport is the visible area of the SVG image. You can set any height and width on an SVG, but the whole image might not be visible. The area that is visible is called the viewport. The size of the viewport can be defined using the width and height attributes of the <svg> element.

What is a viewport size?

A viewport is defined by the size of the rectangle filled by a web page on your screen. The viewport is the size of the browser window, minus the scroll bars and toolbars. Browsers use “CSS pixels.” For many devices, such as those with retina screens, the viewport is smaller than the advertised device resolution.


3 Answers

The viewport is the part of the webpage that the user can currently see. The scrollbars move the viewport to show other parts of the page.

Follow this article's instructions to get the viewport dimensions in Javascript.

if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
like image 144
Matchu Avatar answered Oct 03 '22 22:10

Matchu


I think the ViewPort is just an area to display the web content in the browser. And different browsers have their own setting for the size of ViewPort, For example, the default ViewPort width of Safari is 980 pixels. So, if the actual web page you want to see is smaller than 980 pixels, there should be a blank display area in the Safari when accessing the web page in the Safari by default. Hence, that is the reason sometimes we need to configure the ViewPort for better web content display in the browser.

Like below, for example:

<meta name="viewport" content="width=device-width">

And also please read Paul's answer. I think he already explained the usage of ViewPort.

like image 35
Joe.wang Avatar answered Oct 01 '22 22:10

Joe.wang


The viewport is a virtual area used by the browser rendering engine to determine how content is scaled and sized when it is initially rendered on the current screen. This will help you:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

like image 41
vicky Avatar answered Sep 30 '22 22:09

vicky