CSS Device Adaptation (original) (raw)
Abstract
This specification provides a way for an author to specify, in CSS, the size, zoom factor, and orientation of the viewport that is used as the base for the initial containing block.
Status of this document
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
The (archived) public mailing list www-style@w3.org (seeinstructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css-device-adapt” in the subject, preferably like this: “[css-device-adapt] _…summary of comment…_”
This document was produced by the CSS Working Group (part of the Style Activity).
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This is the first public Working Draft of the CSS Device Adaptation Module.
Table of Contents
- 1. Introduction
- 2. Values
- 3. The viewport
- 4. The @viewport rule
- 5. Viewport properties
- 5.1. The ‘min-width’ and ‘max-width’ properties
- 5.2. The ‘width’ shorthand property
- 5.3. The ‘min-height’ and ‘max-height’ properties
- 5.4. The ‘height’ shorthand property
- 5.5.The ‘zoom’ property
- 5.6.The ‘min-zoom’ property
- 5.7.The ‘max-zoom’ property
- 5.8.The ‘user-zoom’ property
- 5.9.The ‘orientation’ property
- 5.10.The ‘resolution’ property
- 6.Constraining viewport property values
- 7. Media Queries
- 8. CSSOM
- 9. Conformance
- 10. ViewportMETA element
- 11. Handling ‘auto’ for ‘zoom’
- Acknowledgments
- References
- Property index
- Index
1. Introduction
This section is not normative.
CSS 2.1 [CSS21] specifies an initial containing block for continuous media that has the dimensions of the viewport. Mobile/handheld device browsers have a viewport that is generally a lot narrower than a desktop browser window at a zoom level that gives a CSS pixel size recommended by CSS 2.1.
The narrow viewport is a problem for documents designed to look good in desktop browsers. The result is that mobile browser vendors use a fixed initial containing block size that is different from the viewport size, and close to that of a typical desktop browser window. In addition to scrolling or panning, zooming is often used to change between an overview of the document and zoom in on particular areas of the document to read and interact with.
Certain DOCTYPEs (for instance XHTML Mobile Profile) are used to recognize mobile documents which are assumed to be designed for handheld devices, hence using the viewport size as the initial containing block size.
Additionally, an HTML META
tag has been introduced for allowing an author to specify the size of the initial containing block, and the initial zoom factor directly. It was first implemented by Apple for the Safari/iPhone browser, but has since been implemented for the Opera, Android, and Fennec browsers. These implementations are not fully interoperable and this specification is an attempt at standardizing the functionality provided by the viewport META
tag in CSS.
2. Values
This specification follows the CSS property definition conventions from [CSS3SYN].
Value types are defined in [CSS3VAL].
3. The viewport
This specification introduces a way of overriding the size of the viewport provided by the user agent (UA). Because of this, we need to introduce the difference between the initial viewport and the actual viewport.
initial viewport
This refers to the viewport before any UA or author styles have overridden the viewport given by the window or viewing area of the UA. Note that the initial viewport size will change with the size of the window or viewing area.
actual viewport
This is the viewport you get after the cascaded viewport properties, and the following constraining procedure have been applied.
When the actual viewport cannot fit inside the window or viewing area, either because the actual viewport is larger than the initial viewport or the zoom factor causes only parts of the actual viewport to be visible, the UA should offer a scrolling or panning mechanism.
It is recommended that initially the upper-left corners of the actual viewport and the window or viewing area are aligned if the base direction of the document is ltr. Similarly, that the upper-right corners are aligned when the base direction is rtl. The base direction for a document is defined as the computed value of thedirection
property for the first BODY
element of an HTML or XHTML document. For other document types, it is the computed direction
for the root element.
"dbaron: The question is, what does this do on the desktop browser? (And what's a desktop browser)". Need to say that a "desktop" browser typically have no UA styles, as opposed to the UA stylesheet outlined for current mobile behaviour, and that no UA styles for @viewport will give "desktop" behaviour per default (actual viewport is initial viewport).
4. The @viewport
rule
The @viewport
at-rule consists of the @-keyword followed by a block of property declarations describing the viewport.
The property declarations inside an @viewport
rule are per document properties and there is no inheritance involved. Hence declarations using the ‘inherit
’ keyword will be dropped. They work similar to @page
properties and follow the cascading order of CSS. Hence, properties in@viewport
rules will override properties from preceding rules. The declarations allow !important which will affect cascading of properties accordingly.
Should the @viewport rule apply to top-level documents only? If not, we need to say something about different zoom factors in frames.
Bert: What's interactions of @viewport and @page
This example sets the viewport to fit the width of the device. Note that it is enough to set the width as the height will be resolved from the width.
@viewport { width: device-width; }
4.1. Syntax
The syntax for the @viewport
rule is as follows (using the notation from the Grammar appendix of CSS 2.1 [CSS21]):
viewport : VIEWPORT_SYM S* '{' S* declaration? [ ';' S* declaration? ]* '}' S*;
with the new token:
@{V}{I}{E}{W}{P}{O}{R}{T} {return VIEWPORT_SYM;}
where:
V v|\0{0,4}(56|76)(\r\n|[ \t\r\n\f])?|\v W w|\0{0,4}(57|77)(\r\n|[ \t\r\n\f])?|\w
The viewport
non-terminal is added to thestylesheet
production along with the ruleset
,media
, and page
non-terminals:
stylesheet : [ CHARSET_SYM STRING ';' ]? [S|CDO|CDC]* [ import [ CDO S* | CDC S* ]* ]* [ [ ruleset | media | page | viewport ] [ CDO S* | CDC S* ]* ]* ;
It is also added to media production to allow @viewport
rules nested inside @media
rules This is extending the CSS 2.1 syntax. A draft of CSS3 Paged Media also allows page inside @media.:
media : MEDIA_SYM S* media_list LBRACE S* [ ruleset | viewport ]* '}' S* ;
5. Viewport properties
This section presents the properties that are allowed inside an @viewport
rule. Other properties than those listed here will be dropped.
Relative length values are resolved against initial values. For instance ‘em
’s are resolved against the initial value of the font-size property.
5.1.The ‘min-width’ and ‘max-width’ properties
Name: | min-width |
---|---|
Value: | |
Initial: | auto |
Applies to: | N/A |
Inherited: | N/A |
Percentages: | Refer to the width of the initial viewport |
Media: | visual, continuous |
Computed value: | ‘auto’, ‘device-width’, ‘device-height’, an absolute length, or a percentage as specified |
Name: | max-width |
---|---|
Value: | |
Initial: | auto |
Applies to: | N/A |
Inherited: | N/A |
Percentages: | Refer to the width of the initial viewport |
Media: | visual, continuous |
Computed value: | ‘auto’, ‘device-width’, ‘device-height’, an absolute length, or a percentage as specified |
Specifies the minimum and maximum width of the viewport that is used to set the size of the initial containing block where
= auto | device-width | device-height | |
and the values have the following meanings:
‘auto
’
The used value is calculated from the other property values according to the constraining procedure.
‘device-width
’
The width of the screen in CSS pixels at zoom factor 1.0.
‘device-height
’
The height of the screen in CSS pixels at zoom factor 1.0.
A positive absolute or relative length.
A percentage value relative to the width or height of the initial viewport at zoom factor 1.0, for horizontal and vertical lengths respectively. Must be positive.
The min-width and max-width properties are inputs to the constraining procedure. The width will initially be set as close as possible to the initial viewport width within the min/max constraints.
5.2.The ‘width’ shorthand property
Name: | width |
---|---|
Value: | {1,2} |
Initial: | See individual properties |
Applies to: | N/A |
Inherited: | N/A |
Percentages: | See individual properties |
Media: | visual, continuous |
Computed value: | See individual properties |
This is a shorthand property for setting both min-width and max-width. One value will set both min-width and max-width to that value. Two values will set min-width to the first and max-width to the second.
5.3.The ‘min-height’ and ‘max-height’ properties
Name: | min-height |
---|---|
Value: | |
Initial: | auto |
Applies to: | N/A |
Inherited: | N/A |
Percentages: | Refer to the height of the initial viewport |
Media: | visual, continuous |
Computed value: | ‘auto’, ‘device-width’, ‘device-height’, an absolute length, or a percentage as specified |
Name: | max-height |
---|---|
Value: | |
Initial: | auto |
Applies to: | N/A |
Inherited: | N/A |
Percentages: | Refer to the height of the initial viewport |
Media: | visual, continuous |
Computed value: | ‘auto’, ‘device-width’, ‘device-height’, an absolute length, or a percentage as specified |
Specifies the minimum and maximum height of the viewport that is used to set the size of the initial containing block.
The min-height and max-height properties are inputs to the constraining procedure. The height will initially be set as close as possible to the initial viewport height within the min/max constraints.
5.4.The ‘height’ shorthand property
Name: | height |
---|---|
Value: | {1,2} |
Initial: | See individual properties |
Applies to: | N/A |
Inherited: | N/A |
Percentages: | See individual properties |
Media: | visual, continuous |
Computed value: | See individual properties |
This is a shorthand property for setting both min-height and max-height. One value will set both min-height and max-height to that value. Two values will set min-height to the first and max-height to the second.
5.5. The ‘zoom’ property
Name: | zoom | |
---|---|---|
Value: | auto | | |
Initial: | auto | |
Applies to: | N/A | |
Inherited: | N/A | |
Percentages: | The zoom factor itself | |
Media: | visual, continuous | |
Computed value: | ‘auto’, or a positive number or percentage as specified. |
Specifies the initial zoom factor for the window or viewing area. This is a magnifying glass type of zoom. Interactively changing the zoom factor from the initial zoom factor does not affect the size of the initial or the actual viewport.
Values have the following meanings: Should both numbers and percentages be allowed?
‘auto
’
The zoom factor is UA-dependent. The UA may use the size of the area of the canvas on which the document is rendered to find that initial zoom factor. See this section for a proposed way of handling ‘auto’ values for ‘zoom’.
A positive number used as a zoom factor. A factor of 1.0 means that no zooming is done. Values larger than 1.0 gives a zoomed-in effect and values smaller than 1.0 a zoomed-out effect.
A positive percentage value used as a zoom factor. A factor of 100% means that no zooming is done. Values larger than 100% gives a zoomed-in effect and values smaller than 100% a zoomed-out effect.
5.6. The ‘min-zoom’ property
Name: | min-zoom | |
---|---|---|
Value: | auto | | |
Initial: | auto | |
Applies to: | N/A | |
Inherited: | N/A | |
Percentages: | The zoom factor itself | |
Media: | visual, continuous | |
Computed value: | ‘auto’, or a positive number or percentage as specified. |
Specifies the smallest allowed zoom factor. It is used as input to theconstraining procedure to constrain non-‘auto’ ‘zoom’ values, but also to limit the allowed zoom factor that can be set through user interaction. The UA should also use this value as a constraint when choosing an actual zoom factor when the used value of ‘zoom’ is ‘auto’.
Values have the following meanings:
‘auto
’
The lower limit on zoom factor is UA dependant. There will be no minimum value constraint on the ‘zoom’ property used in the constraining procedure
A positive number limiting the minimum value of the zoom factor.
A positive percentage limiting the minimum value of the zoom factor.
5.7. The ‘max-zoom’ property
Name: | max-zoom | |
---|---|---|
Value: | auto | | |
Initial: | auto | |
Applies to: | N/A | |
Inherited: | N/A | |
Percentages: | The zoom factor itself | |
Media: | visual, continuous | |
Computed value: | ‘auto’, or a positive number or percentage as specified. |
Specifies the largest allowed zoom factor. It is used as input to the constraining procedure to constrain non-‘auto’ ‘zoom’ values, but also to limit the allowed zoom factor that can be set through user interaction. The UA should also use this value as a constraint when choosing an actual zoom factor when the used value of ‘zoom’ is ‘auto’.
Values have the following meanings:
‘auto
’
The upper limit on zoom factor is UA dependant. There will be no maximum value constraint on the ‘zoom
’ property used in the constraining procedure
A positive number limiting the maximum value of the zoom factor.
A positive percentage limiting the maximum value of the zoom factor.
5.8. The ‘user-zoom’ property
Name: | user-zoom |
---|---|
Value: | zoom | fixed |
Initial: | zoom |
Applies to: | N/A |
Inherited: | N/A |
Percentages: | N/A |
Media: | visual, continuous |
Computed value: | ‘zoom’ or ‘fixed’ as specified. |
Specifies if the zoom factor can be changed by user interaction or not.
Values have the following meanings:
‘zoom
’
The user can interactively change the zoom factor.
‘fixed
’
The user cannot interactively change the zoom factor.
5.9. The ‘orientation’ property
Name: | orientation | |
---|---|---|
Value: | auto | portrait | landscape |
Initial: | auto | |
Applies to: | N/A | |
Inherited: | N/A | |
Percentages: | N/A | |
Media: | visual, continuous | |
Computed value: | ‘auto’, ‘portrait’, or ‘landscape’ as specified. |
This property is used to request that a document is displayed in portrait or landscape mode. For a UA/device where the orientation is changed upon tilting the device, an author can use this property to inhibit the orientation change.
Values have the following meanings:
‘auto
’
The UA automatically chooses the orientation based on the device's normal mode of operation. The UA may choose to change the orientation of the presentation when the device is tilted.
‘portrait
’
The document should be locked to portrait presentation.
‘landscape
’
The document should be locked to landscape presentation.
5.10. The ‘resolution’ property
This property is at risk.
Name: | resolution | |
---|---|---|
Value: | auto | device | |
Initial: | auto | |
Applies to: | N/A | |
Inherited: | N/A | |
Percentages: | N/A | |
Media: | visual, continuous | |
Computed value: | ‘auto’, ‘device’, or a resolution value as specified. |
The UA relates the CSS pixel to the reference pixel or the physical length units as described in CSS 2.1 [CSS21]. The resolution property can be used to override the CSS pixel size chosen by the UA by setting a CSS pixel resolution. In CSS, absolute length units are fixed in relation to each other, hence, changing the CSS pixel resolution will for instance change the physical length of a CSS cm.
The relationship between a device pixel and a CSS pixel will depend on the device resolution. Setting resolution: 120dpi
on a 240dpi device will give a 2:1 ratio between device and CSS pixels, while on a 120dpi device, the ratio will be 1:1. Likewise, the ‘device’ value will always keep a 1:1 ratio, but will give different CSS pixel resolution depending on device resolution.
Note that setting this property will affect the used lengths for ‘device-width’, ‘device-height’, and the size of the initial viewport.
The value is a positive immediately followed by a unit identifier (‘dpi
’ or ‘dpcm
’).
Values have the following meanings:
‘auto
’
Use the UAs CSS pixel resolution.
‘device
’
Use device resolution as the CSS pixel resolution. That is, have a 1-1 relationship between a CSS and a device pixel.
Set the CSS pixel resolution to a fixed dpi or dpcm value.
6.Constraining viewport property values
6.1. Definitions
For the procedure below:
Properties refer to the values resolved/constrained to at that point in the procedure. They are initially resolved to their computed values.
width
andheight
refer to the resolved viewport size and not the shorthand properties. They are both initially ‘auto’.
MIN/MAX
computations where one of the arguments is ‘auto
’ resolve to the other argument. For instance, MIN(0.25, 'auto') = 0.25
, and MAX(5, 'auto') = 5
.
initial-width
is the width of the initial viewport in pixels at zoom factor 1.0.
initial-height
is the height of the initial viewport in pixels at zoom factor 1.0.
6.2. The procedure
The used values are resolved from the computed values going through the steps below.
User agents are expected, but not required, to re-run this procedure and re-layout the document, if necessary, in response to changes in the user environment, for example if the device is tilted from landscape to portrait mode or the window that forms the initial viewport is resized.
Resolve non-‘auto’ lengths to pixel lengths
- Resolve relative and absolute lengths, percentages, and keywords (‘device-width’, ‘device-height’) to pixel values for the ‘min-width’, ‘max-width’, ‘min-height’ and ‘max-height’ properties
Resolve initial width
and height
from min/max properties
- If
min-width
ormax-width
is not ‘auto’, setwidth = MAX(min-width, MIN(max-width, initial-width))
- If
min-height
ormax-height
is not ‘auto’, setheight = MAX(min-height, MIN(max-height, initial-height))
Resolvemin-zoom
and max-zoom
values
Constrain zoom
value to the [min-zoom, max-zoom]
range
- If
zoom
is not ‘auto’, setzoom = MAX(min-zoom, MIN(max-zoom, zoom))
Resolve width
value
- If
width
andzoom
are both ‘auto
’, setwidth = initial-width
- If
width
is ‘auto
’, andheight
is ‘auto
’, setwidth = (initial-width / zoom)
- If
width
is ‘auto
’, setwidth = height * (initial-width / initial-height)
Resolve height
value
- If
height
is ‘auto
’, setheight = width * (initial-height / initial-width)
Extend width
and height
to fill the window/viewing area for the specified zoom
- If
zoom
ormax-zoom
is not ‘auto’, setwidth = MAX(width, (initial-width / MIN(zoom, max-zoom)))
- If
zoom
ormax-zoom
is not ‘auto’, setheight = MAX(height, (initial-height / MIN(zoom, max-zoom)))
This example shows the case where the used value for width is increased to fit the window/viewing area for a specified zoom value. The used value for width will be two times device-width in this case, assuming device-width is the same as the initial viewport width.
@viewport { width: device-width; zoom: 0.5; }
For several media features, the size of the initial containing block and the orientation of the device affects the result of a media query evaluation, which means that the effect of @viewport
rules on media queries needs extra attention.
Bert: If you put @viewport, can you put @viewport in @media? Say what it means?
From the Media Queries specification [MEDIAQ]:
“To avoid circular dependencies, it is never necessary to apply the style sheet in order to evaluate expressions. For example, the aspect ratio of a printed document may be influenced by a style sheet, but expressions involving ‘device-aspect-ratio’ will be based on the default aspect ratio of the user agent.”
For @viewport
rules, though, it is recommended that they are applied before media queries for other rules are evaluated.
Recommended procedure for applying CSS rules:
- Apply
@viewport
rules. If@viewport
rules rely on media queries, use the viewport properties of the initial viewport. - Apply style rules. If style rules rely on media queries, use the viewport properties obtained from step 1 when evaluating the media queries.
The rationale for using the viewport properties obtained from applying the @viewport
rules for evaluating media queries for style rules, is that media queries should match the actual viewport that the document will be layed out in and not the initial or the one specified in the UA stylesheet. Consider the example below given that the UA stylesheet has a viewport width of 980px, but a device-width and initial viewport width of 320px. The author has made separate styles to make the document look good for initial containing block widths above or below 400px. The actual viewport used will be 320px wide, and in order to match the styles with the actual viewport width, the viewport resulting from applying the @viewport
rules should be used to evaluate the media queries.
Given a device-width of 320px and a UA stylesheet viewport width of 980px, the first media query will not match, but the second will.
@viewport { width: device-width; }
@media screen and (min-width: 400px) { div { color: red; } }
@media screen and (max-width: 400px) { div { color: green; } }
Another example:
The media query below should match because the @viewport
rule is applied before the media query is evaluated.
@media screen and (width: 397px) { div { color: green; } }
@viewport { width: 397px; }
Below is an example where an @viewport
rule relies on a media query affected by the viewport properties.
The green color should be applied to a div because the initial viewport width is used to evaluate the media query for the second @viewport
rule, but the actual viewport is used for evaluating the media query when applying style rules.
@viewport { width: 397px; }
@media screen and (width: 397px) { @viewport { width: 500px; } }
@media screen and (width: 397px) { div { color: green; } }
It is recommended that authors do not write @viewport
rules that rely on media queries whose evaluation is affected by viewport properties. Is is also recommended that the @viewport
rule(s) is placed as early in the document as possible to avoid unnecessary re-evaluation of media queries or reflows.
The next example illustrates possible circular dependencies between media queries and @viewport
rules. Assuming a UA stylesheet viewport width larger than 200px, the first viewport rule would apply causing an actual viewport width of 100px. If the media queries were based on the actual viewport, a re-evaluation would apply the second @viewport
rule which would in turn cause the first media query to be true, which means we're back to start.
@media screen and (min-width: 200px) { @viewport { width: 100px; } }
@media screen and (max-width: 200px) { @viewport { width: 300px; } }
There are prefixed implementations of a media feature for the device:css pixel ratio (-webkit-device-pixel-ratio / -o-device-pixel-ratio). Should be standardized here or in a new level of Media Queries?
8. CSSOM
Properties in the CSSOM and CSSOM View specifications refer to the viewport and the initial containing block. If any of those properties should refer to the initial viewport and not the actual viewport, those exceptions need to be adressed.
Standardize window.devicePixelRatio? Should be done in the CSSOM View spec perhaps?
9. Conformance
Requirements for a conforming UA:
- The ‘min-width’, ‘max-width’, ‘width’, ‘min-height’, ‘max-height’, and ‘height’ properties must be supported.
- The ‘min-zoom’, ‘max-zoom’, and ‘zoom’ properties must be supported as input to the constraining procedure. However, the UA may choose to use a different zoom factor when presenting the document to the user, and use different minimum and maximum zoom limits for the user interaction.
This will for instance allow UAs without zooming capabilities to conform and still have interoperable implementations when it comes to viewport dimensions. It will also allow the UA to choose a different zoom factor when content overflows the actual viewport. - Support for the ‘user-zoom’ and ‘orientation’ properties is optional.
Need to say something about the resolution property if it is kept.
This section is not normative.
This section describes a mapping from the content attribute of the viewport META
element, first implemented by Apple in the iPhone Safari browser, to the properties of the @viewport
rule described in this specification.
10.1. UA stylesheet
In order to match the Safari implementation, the following parsing algorithm and translation rules rely on the UA stylesheet below.
@viewport { width: 980px; min-zoom: 0.25; max-zoom: 5; }
Note that these values might not fit well with all UAs. For instance, with a min-zoom of 0.25 you will be able to fit the whole width of the document inside the window for widths up to 1280px on a 320px wide device like the iPhone, but only 960px if you have 240px display.
10.2. Properties
The recognized properties in the viewport META
element are:
width
height
initial-scale
minimum-scale
maximum-scale
user-scalable
target-densityDpi
At risk since ‘resolution’ is at risk.
10.3. Parsing algorithm
Below is an algorithm for parsing the content
attribute of the META
tag produced from testing Safari on the iPhone. The testing was done on an iPod touch running iPhone OS 4. The UA string of the browser:"Mozilla/5.0 (iPod; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"
. The pseudo code notation used is based on the notation used in [Algorithms]. The white-space class contains the following characters (ascii):
- Horizontal tab (0x09)
- Line feed (0x0a)
- Carriage return (0x0d)
- Space (0x20)
Parse-Content(S) i ← 1 while i ≤ length[S] do while i ≤ length[S] and S[i] in [white-space, ',', '='] do i ← i + 1 if i ≤ length[S] then i ← Parse-Property(S, i)
Parse-Property(S, i) start ← i while i ≤ length[S] and S[i] not in [white-space, ',', '='] do i ← i + 1 if i > length[S] or S[i] = ',' then return i property-name ← S[start .. (i - 1)] while i ≤ length[S] and S[i] not in [',', '='] do i ← i + 1 if i > length[S] or S[i] = ',' then return i while i ≤ length[S] and S[i] in [white-space, '='] do i ← i + 1 if i > length[S] or S[i] = ',' then return i start ← i while i ≤ length[S] and S[i] not in [white-space, ',', '='] do i ← i + 1 property-value ← S[start .. (i - 1)] Set-Property(property-name, property-value) return i
Set-Property matches the listed property names case-insensitively. Theproperty-value
strings are interpreted as follows:
- If a prefix of
property-value
can be converted to a number usingstrtod
, the value will be that number. The remainder of the string is ignored. - If the value can not be converted to a number as described above, the whole
property-value
string will be matched with the following strings case-insensitively:yes
,no
,device-width
,device-height
- If the string did not match any of the known strings, the value is unknown.
10.4.Translation into @viewport
properties
The Viewport META
element is placed in the cascade as if it was a STYLE
element, in the exact same place in the dom, that only contains a single @viewport
rule.
Each of the property/value pair from the parsing in the previous section are translated, and added to that single at-rule as follows:
Unknown properties
Unknown properties are dropped.
The width
and height
properties
The width
and height
viewport META
properties are translated into ‘width’ and ‘height’ shorthand properties, effectively setting the min and max properties to the same value.
- Non-negative number values are translated to pixel lengths, clamped to the range:
[1px, 10000px]
- Negative number values are dropped
device-width
anddevice-height
are used as keywords- Other keywords and unknown values translate to 1px
For a viewport META
element that translates into an @viewport
rule with a non-‘auto
’ ‘zoom’ declaration and no ‘width’ declaration, add:
width: auto;
to the @viewport
rule.
This META
element:
translates into:
@viewport { zoom: 1.0; width: auto; }
Theinitial-scale
, minimum-scale
, and maximum-scale
properties
The properties are translated into ‘zoom’, ‘min-zoom’, and ‘max-zoom’ respectively with the following translations of values.
- Non-negative number values are translated to values, clamped to the range
[0.1, 10]
- Negative number values are dropped
yes
is translated to 1device-width
anddevice-height
are translated to 10no
and unknown values are translated to 0.1
For a viewport META
element that translates into an @viewport
rule with no ‘max-zoom’ declaration and a non-‘auto
’ ‘min-zoom’ value that is larger than the ‘max-zoom’ value of the UA stylesheet, the ‘min-zoom’ declaration value is clamped to the UA stylesheet ‘max-zoom’ value.
The user-scalable
property
The user-scalable
property is translated into ‘user-zoom’ with the following value translations.
yes
andno
are translated into ‘zoom’ and ‘fixed’ respectively.- Numbers ≥ 1, numbers ≤ -1,
device-width
anddevice-height
are mapped to ‘zoom’ - Numbers in the range
<-1, 1>
, and unknown values, are mapped to ‘fixed’
This META
element:
will translate into this @viewport
block:
@viewport { width: 480px; zoom: 2.0; user-zoom: zoom; }
The target-densityDpi
property
At risk since ‘resolution’ is at risk.
This property differ from the others since it is from the WebKit implementation used in the Android browser and not supported in Safari
The target-densityDpi
property is translated into ‘resolution’ with the following value translations.
- Number values in the range
[70, 400]
are translated to ‘dpi
’ values. device-dpi
translates to ‘device’low-dpi
translates to 120dpimedium-dpi
translates to 160dpihigh-dpi
translates to 240dpi- Other values are dropped
11. Handling ‘auto’ for ‘zoom’
This section is not normative.
This section presents one way of picking an actual value for the ‘zoom’ property when the used value is ‘auto’.
Given an initial viewport with size(initial-width, initial-height)
, and a finite region within the canvas where the formatting structure is rendered (rendered-width, rendered-height)
. That region is at least as large as the actual viewport.
Then, if the used value of ‘zoom’ is ‘auto’, let the actual zoom factor be:
zoom = MAX(initial-width / rendered-width, initial-height / rendered-height)
The actual zoom factor should also be further limited by the [min-zoom, max-zoom] range.
Acknowledgments
References
Normative references
[CSS21]
Bert Bos; et al. Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification. 7 June 2011. W3C Recommendation. URL: http://www.w3.org/TR/2011/REC-CSS2-20110607
[CSS3SYN]
L. David Baron. CSS3 module: Syntax. 13 August 2003. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2003/WD-css3-syntax-20030813
[CSS3VAL]
Håkon Wium Lie; Chris Lilley. CSS3 Values and Units. 19 September 2006. W3C Working Draft. (Work in progress.) URL: http://www.w3.org/TR/2006/WD-css3-values-20060919
[MEDIAQ]
Håkon Wium Lie; et al. Media Queries. 27 July 2010. W3C Candidate Recommendation. (Work in progress.) URL: http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/
Other references
[Algorithms]
Thomas H. Cormen; et al. Introduction to Algorithms, Second Edition, MIT Press.
Property index
Property | Values | Initial | Applies to | Inh. | Percentages | Media | |
---|---|---|---|---|---|---|---|
height | {1,2} | See individual properties | N/A | N/A | See individual properties | visual, continuous | |
max-height | auto | N/A | N/A | Refer to the height of the initial viewport | visual, continuous | ||
max-width | auto | N/A | N/A | Refer to the width of the initial viewport | visual, continuous | ||
max-zoom | auto | | auto | N/A | N/A | The zoom factor itself | visual, continuous | |
min-height | auto | N/A | N/A | Refer to the height of the initial viewport | visual, continuous | ||
min-width | auto | N/A | N/A | Refer to the width of the initial viewport | visual, continuous | ||
min-zoom | auto | | auto | N/A | N/A | The zoom factor itself | visual, continuous | |
orientation | auto | portrait | landscape | auto | N/A | N/A | N/A | visual, continuous |
resolution | auto | device | auto | N/A | N/A | N/A | visual, continuous | |
user-zoom | zoom | fixed | zoom | N/A | N/A | N/A | visual, continuous | |
width | {1,2} | See individual properties | N/A | N/A | See individual properties | visual, continuous | |
zoom | auto | | auto | N/A | N/A | The zoom factor itself | visual, continuous |
Index
- actual viewport, 3.
- auto
- device, 5.10.
- device-dpi, #
- device-height, 5.1.
- device-width, 5.1.
- fixed, 5.8.
- height, 5.4.
- high-dpi, #
- initial-scale, 10.2.,#
- initial viewport, 3.
- landscape, 5.9.
- low-dpi, #
- max-height, 5.3.
- maximum-scale, 10.2.,#
- max-width, 5.1.
- max-zoom, 5.7.
- medium-dpi, #
- min-height, 5.3.
- minimum-scale, 10.2.,#
- min-width, 5.1.
- min-zoom, 5.6.
- no, 10.3., #,#
- orientation, 5.9.
- portrait, 5.9.
- resolution, 5.10.
- , 5.10.
- target-densityDpi, 10.2., #, #
- user-scalable, 10.2.,#, #
- user-zoom, 5.8.
- , 5.1.
- width, 5.2.
- yes, 10.3., #, #
- zoom