Deprecated
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Note: See https://github.com/w3c/csswg-drafts/issues/4766 for discussion around @viewport's removal from the standards track.
The@viewport
CSS at-rule lets you configure the viewport through which the document is viewed. It's primarily used for mobile devices, but is also used by desktop browsers that support features like "snap to edge" (such as Microsoft Edge).
Lengths specified as percentages are calculated relative to the initial viewport, which is the viewport before any user agent or authored styles have had an opportunity to adjust the viewport. This is typically based on the size of the window on desktop browsers that aren't in full screen mode.
On mobile devices (or desktop devices that are in full screen mode), the initial viewport is usually the portion of a device's screen that is available for application use. This may be either the full screen or the full screen area minus areas controlled by the operating system (such as a taskbar) or the application-available screen area (either the full screen or the screen minus any areas owned by the operating system or other applications).
@viewport { width: 100vw; /*Sets the width of the actual viewport to the device width*/ }
Note: The use of <meta name="viewport">
tag overrides @viewport
The at-rule contains a set of nested descriptors in a CSS block that is delimited by curly braces.
A zoom factor of 1.0
or 100%
corresponds to no zooming. Larger values zoom in. Smaller values zoom out.
Browser support for @viewport
is weak at this time, with support being largely available in Internet Explorer and Edge. Even in those browsers, only a small number of descriptors are available. Browsers will ignore @viewport
if they don't support it, and will ignore any descriptors that they don't recognize.
min-width
max-width
width
min-width
and max-width
.min-height
max-height
height
min-height
and max-height
.zoom
min-zoom
max-zoom
user-zoom
orientation
viewport-fit
@viewport { <group-rule-body> }
@viewport { min-width: 640px; max-width: 800px; } @viewport { zoom: 0.75; min-zoom: 0.5; max-zoom: 0.9; } @viewport { orientation: landscape; }
Specification | Status | Comment |
---|---|---|
CSS Round Display Level 1 The definition of '@viewport' in that specification. | Working Draft | Defined the viewport-fit descriptor. |
CSS Device Adaptation The definition of '@viewport' in that specification. | Working Draft | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
@viewport |
29 — 84
|
12
|
No
|
10
|
16
|
No
|
height descriptor |
29 — 84 | 12
|
No | 10
|
16
|
No |
max-height descriptor |
29 — 84 | 12
|
No | 10
|
16
|
No |
max-width descriptor |
29 — 84 | 12
|
No | 10
|
16
|
No |
max-zoom descriptor |
29 — 84 | 12
|
No | 10
|
16 | No |
min-height descriptor |
29 — 84 | 12
|
No | 10
|
16
|
No |
min-width descriptor |
29 — 84 | 12
|
No | 10
|
16
|
No |
min-zoom descriptor |
29 — 84 | 12
|
No | 10
|
16 | No |
orientation descriptor |
No | 12 — 79
|
No | 10
|
No | No |
user-zoom descriptor |
29 — 84 | 12
|
No | 10
|
16 | No |
viewport-fit descriptor |
No | No | No | No | No | No |
width descriptor |
29 — 84 | 12
|
No | 10
|
16
|
No |
zoom descriptor |
29 — 84 | 12
|
No | 10
|
16 | No |
Mobile | ||||||
---|---|---|---|---|---|---|
@viewport |
4.4 — 37 | 29 — 84
|
No
|
16
|
No
|
2.0 |
height descriptor |
4.4 — 37 | 29 — 84 | No | 16
|
No | 2.0 |
max-height descriptor |
4.4 — 37 | 29 — 84 | No | 16
|
No | 2.0 |
max-width descriptor |
4.4 — 37 | 29 — 84 | No | 16
|
No | 2.0 |
max-zoom descriptor |
No | 29 — 84 | No | 16 | No | 2.0 |
min-height descriptor |
4.4 — 37 | 29 — 84 | No | 16
|
No | 2.0 |
min-width descriptor |
4.4 — 37 | 29 — 84 | No | 16
|
No | 2.0 |
min-zoom descriptor |
No | 29 — 84 | No | 16 | No | 2.0 |
orientation descriptor |
No | No | No | 11.1 — 14
|
No | No |
user-zoom descriptor |
No | 29 — 84 | No | 16 | No | 2.0 |
viewport-fit descriptor |
No | No | No | No | No | No |
width descriptor |
4.4 — 37 | 29 — 84 | No | 16
|
No | 2.0 |
zoom descriptor |
4.4 — 37 | 61 — 84 | No | 16 | No | 8.0 |
<meta>
, specifically <meta name="viewport">
© 2005–2020 Mozilla and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/@viewport