@viewport

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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: device-width;
}

Syntax

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.

Descriptors

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 (en-US)

Used in the determination of the width of the viewport when the document is first displayed.

max-width (en-US)

Used in the determination of the width of the viewport when the document is first displayed.

width (en-US)

A shorthand descriptor for setting both min-width and max-width.

min-height (en-US)

Used in the determination of the height of the viewport when the document is first displayed.

max-height (en-US)

Used in the determination of the height of the viewport when the document is first displayed.

height (en-US)

A shorthand descriptor for setting both min-height and max-height.

zoom (en-US)

Sets the initial zoom factor.

min-zoom (en-US)

Sets the minimum zoom factor.

max-zoom (en-US)

Sets the maximum zoom factor.

user-zoom (en-US)

Controls whether or not the user should be able to change the zoom factor.

orientation (en-US)

Controls the document's orientation.

viewport-fit (en-US)

Controls the display of the document on non-rectangular displays.

Formal syntax

Error: could not find syntax for this item

Examples

@viewport {
  min-width: 640px;
  max-width: 800px;
}

@viewport {
  zoom: 0.75;
  min-zoom: 0.5;
  max-zoom: 0.9;
}

@viewport {
  orientation: landscape;
}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also