1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
---
title: '@viewport'
slug: Web/CSS/@viewport
tags:
- Adaptation
- At-rule
- CSS
- Device
- NeedsContent
- NeedsTranslation
- Reference
- TopicStub
translation_of: Web/CSS/@viewport
---
<div>{{SeeCompatTable}}{{CSSRef}}</div>
<p>The<strong> <code>@viewport</code></strong> <a href="/en/CSS" title="CSS">CSS</a> <a href="/en/CSS/At-rule" title="en/CSS/At-rule">at-rule</a> lets you configure the {{glossary("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).</p>
<p>Lengths specified as percentages are calculated relative to the <strong>initial viewport</strong>, 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.</p>
<p>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).</p>
<pre class="brush: css no-line-numbers">@viewport {
width: device-width;
}</pre>
<h2 id="Syntax">Syntax</h2>
<p>The at-rule contains a set of nested {{glossary("descriptor (CSS)", "descriptor")}}s in a CSS block that is delimited by curly braces.</p>
<p>A <em>zoom factor</em> of <code>1.0</code> or <code>100%</code> corresponds to no zooming. Larger values zoom in. Smaller values zoom out.</p>
<h3 id="Descriptors">Descriptors</h3>
<p>Browser support for <code>@viewport</code> 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 <code>@viewport</code> if they don't support it, and will ignore any descriptors that they don't recognize.</p>
<dl>
<dt><a href="/en-US/docs/Web/CSS/@viewport/min-width"><code>min-width</code></a></dt>
<dd>Used in the determination of the width of the viewport when the document is first displayed.</dd>
<dt><a href="/en-US/docs/Web/CSS/@viewport/max-width"><code>max-width</code></a></dt>
<dd>Used in the determination of the width of the viewport when the document is first displayed.</dd>
<dt><a href="/en-US/docs/Web/CSS/@viewport/width"><code>width</code></a></dt>
<dd>A shorthand descriptor for setting both <code>min-width</code> and <code>max-width</code>.</dd>
<dt><a href="/en-US/docs/Web/CSS/@viewport/min-height"><code>min-height</code></a></dt>
<dd>Used in the determination of the height of the viewport when the document is first displayed.</dd>
<dt><a href="/en-US/docs/Web/CSS/@viewport/max-height"><code>max-height</code></a></dt>
<dd>Used in the determination of the height of the viewport when the document is first displayed.</dd>
<dt><a href="/en-US/docs/Web/CSS/@viewport/height"><code>height</code></a></dt>
<dd>A shorthand descriptor for setting both <code>min-height</code> and <code>max-height</code>.</dd>
<dt><a href="/en-US/docs/Web/CSS/@viewport/zoom"><code>zoom</code></a></dt>
<dd>Sets the initial zoom factor.</dd>
<dt><a href="/en-US/docs/Web/CSS/@viewport/min-zoom"><code>min-zoom</code></a></dt>
<dd>Sets the minimum zoom factor.</dd>
<dt><a href="/en-US/docs/Web/CSS/@viewport/max-zoom"><code>max-zoom</code></a></dt>
<dd>Sets the maximum zoom factor.</dd>
<dt><a href="/en-US/docs/Web/CSS/@viewport/user-zoom"><code>user-zoom</code></a></dt>
<dd>Controls whether or not the user should be able to change the zoom factor.</dd>
<dt><a href="/en-US/docs/Web/CSS/@viewport/orientation"><code>orientation</code></a></dt>
<dd>Controls the document's orientation.</dd>
<dt>{{cssxref("@viewport/viewport-fit", "viewport-fit")}}</dt>
<dd>Controls the display of the document on non-rectangular displays.</dd>
</dl>
<h3 id="Formal_syntax">Formal syntax</h3>
{{csssyntax}}
<h2 id="Examples">Examples</h2>
<pre class="brush: css">@viewport {
min-width: 640px;
max-width: 800px;
}
@viewport {
zoom: 0.75;
min-zoom: 0.5;
max-zoom: 0.9;
}
@viewport {
orientation: landscape;
}</pre>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName("CSS Round Display", "#extending-viewport-rule", "@viewport")}}</td>
<td>{{Spec2("CSS Round Display")}}</td>
<td>Defined the {{cssxref("@viewport/viewport-fit", "viewport-fit")}} descriptor.</td>
</tr>
<tr>
<td>{{SpecName('CSS3 Device', '#the-atviewport-rule', '@viewport')}}</td>
<td>{{Spec2('CSS3 Device')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("css.at-rules.viewport")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li>{{HTMLElement("meta")}}, specifically <code><meta name="viewport"></code></li>
<li><a href="/en-US/docs/Mobile/Viewport_meta_tag">Using the viewport meta tag to control layout on mobile browsers</a></li>
</ul>
|