resolution
The resolution
CSS media feature can be used to test the pixel density of the output device.
Syntax
The resolution
feature is specified as a <resolution>
value representing the pixel density of the output device. It is a range feature, meaning that you can also use the prefixed min-resolution
and max-resolution
variants to query minimum and maximum values, respectively.
Examples
HTML
html
<p>This is a test of your device's pixel density.</p>
CSS
css
/* Exact resolution */
@media (resolution: 150dpi) {
p {
color: red;
}
}
/* Minimum resolution */
@media (min-resolution: 72dpi) {
p {
text-decoration: underline;
}
}
/* Maximum resolution */
@media (max-resolution: 300dpi) {
p {
background: yellow;
}
}
Result
Specifications
Specification |
---|
Media Queries Level 4 # resolution |
Browser compatibility
BCD tables only load in the browser
See also
window.devicePixelRatio
- The
image-resolution
property