Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between visual viewport and layout viewport?

What is the Difference between visual viewport and layout viewport for a mobile device like iPhone/iPad?

I have gone through a lot of online resources, but am still unclear about it.

like image 407
copenndthagen Avatar asked Jun 13 '11 17:06

copenndthagen


People also ask

What is visual viewport?

The visual viewport is the visual portion of a screen excluding on-screen keyboards, areas outside of a pinch-zoom area, or any other on-screen artifact that doesn't scale with the dimensions of a page.

What are the different viewports?

The web contains two viewports, the layout viewport and the visual viewport.

Is viewport a CSS or HTML?

The viewport can be imported in HTML in two ways: One is directly using in the document and the other way is by referencing CSS files. Specifying using the CSS file is done at the beginning of the file to display the output perfectly.

What is a viewport used for?

A viewport is a term for the visible area of a webpage on a display device. It is used in both code and analog design as a way to refer to the display screen and how layout fits into that screen.


2 Answers

The visual viewport is the part of the page that’s currently shown on-screen.

The layout viewport can be considerably wider than the visual viewport, and contains elements that appear and do not appear on the screen.

Imagine the layout viewport as being a large image which does not change size or shape. Now imagine you have a smaller frame through which you look at the large image. The small frame is surrounded by opaque material which obscures your view of all but a portion of the large image. The portion of the large image that you can see through the frame is the visual viewport. You can back away from the large image while holding your frame (zoom out) to see the entire image at once, or you can move closer (zoom in) to see only a portion. You can also change the orientation of the frame, but the size and shape of the large image (layout viewport) never changes.

For a great treatment of the issue, see: http://www.quirksmode.org/mobile/viewports2.html

like image 102
George Cummins Avatar answered Oct 05 '22 07:10

George Cummins


A very good explanation of the two is found here.

In summary:

Visual viewport

The visual viewport is the part of the page that’s currently shown on-screen. The user may scroll to change the part of the page he sees, or zoom to change the size of the visual viewport.

Layout viewport

However, the CSS layout, especially percentual widths, are calculated relative to the layout viewport, which is considerably wider than the visual viewport.

Thus the element takes the width of the layout viewport initially, and your CSS is interpreted as if the screen were significantly wider than the phone screen. This makes sure that your site’s layout behaves as it does on a desktop browser.

How wide is the layout viewport? That differs per browser. Safari iPhone uses 980px, Opera 850px, Android WebKit 800px, and IE 974px.

In short, the layout viewport is generally the width of the viewport when the screen is zoomed all the way out.

like image 23
simshaun Avatar answered Oct 05 '22 07:10

simshaun