- min-
- max-
- >=
- > NEW
- <
- <=
- =
@media (min-width: 600px) @media (max-width: 600px) @media (width: 600px) @media (width >= 600px) @media (width > 600px) @media (width < 600px) @media (width = 600px)
<link media="screen" ...
<style media="screen">
@import "myCSS.css"; ...
@import url(myCSS.css) screen;
@media screen {}
<?xml-stylesheet media="screen" ...
@media screen and (max-width: 600px) {
#presentation {
background: red;
}
}
@media screen and (orientation: portrait) {
#presentation {
background: yellow;
}
@media screen and (orientation: landscape) {
a[href^="mailto:"]:before {
content: url(icons/email.gif);
}
}
<link rel='stylesheet' media='screen and (min-width: 320px) and (max-width: 480px)'
href='css/smartphone.css' />
@media screen and (max-width: 480px) {
selector { /* small screen */
property: value;
}
}
@media screen and (orientation: landscape) {
selector { /* landscape properties */
property: value;
}
}
@media
@media print and (orientation: landscape) { ... }
media=""
<link src="style.css" rel="stylesheet" media="screen and (min-width: 400)"/>
"only" leaves out older browsers
media="only print and (color)"
"not" - if untrue
media="not screen and (color)"
"and" - both parts must be true
media="only screen and (orientation: portrait)"
Comma separates selectors - any part can be true
media="print, screen and (min-width: 480px)"
In parenthesis
media="screen and (max-width: 600px)"
media="print and (orientation: landscape)"
@media screen and (prefers-reduced-motion: reduce) {...}
@media tty and (grid) {...}
In parenthesis
media="screen and (max-width: 600px)"
media="print and (orientation: landscape)"
@media screen and (prefers-reduced-motion: reduce) {...}
@media tty and (grid) {...}
Viewport / Page Dimensions
Display quality
Interactions
Colors
Others
Notes:
widthheightaspect-ratioorientationresolution@media (min-width: 600px) @media (max-width: 600px) @media (width: 600px) @media (width >= 600px) @media (width > 600px) @media (width < 600px) @media (width = 600px)
Note: 0 is invalid.
There are some cool developer tools media query features:
pointernone | coarse | fine hovernone | hoverany-pointernone | coarse | fineany-hovernone | hovergrid0 | 1 or (grid)color@media (min-color: 1) means it's a color devicecolor-gamutsrgb | p3 | rec2020 (Ch,Op,Sf)display-modedisplay member (Defined in the Manifest Spec) full-screen | standalone | minimal-ui | browser (Ch,Op,FF)monochromeoverflow-blocknone | scroll | optional-paged | paged (FF)overflow-inlinescaninterlace | progressiveupdatenone | slow | fastcolor-index(color-index) | (min|max-color-index: n) inverted-colorsnone | invertedlight-leveldim | normal | washedscriptingnone | initial-only | enableddevice-widthdevice-heightdevice-aspect-rationo-preference | reduce (Ch,FF,SF)no-preference | reduceno-preference | high | low no-preference | light | dark (Ch,FF,SF)none | active opaque | additive | subtractive <meta name="viewport" content="width=device-width,
initial-scale=1, maximum-scale=1"/>
device-width (width of screen)device-height (height of screen)@viewport {
width: device-width; zoom: 0.5;
}
Notes:
<meta> is set to disable zoom, there is no delay on onClick events.<meta> is set to disable zoom, you're a jerk!Tap Highlight Color
-webkit-tap-highlight-color: #bada55;
Prevent Select & Hold dialogue
user-select: none; /* (auto | text | none | contain | all) */
Prevent Images Dialog
-webkit-touch-callout: none;
Prevent accidental OS popups (panning)
touch-action: none;
sets how an element's region can be manipulated by a touchscreen user
touch-action: auto; touch-action: none; /* disables gestures */ touch-action: pan-x; touch-action: pan-left; touch-action: pan-right; touch-action: pan-y; touch-action: pan-up; touch-action: pan-down; touch-action: pinch-zoom; touch-action: manipulation; /* removes click event delay */
touch-action propertyauto | none | [ [ pan-x | pan-left | pan-right ] || [ pan-y | pan-up | pan-down ] || pinch-zoom ] | manipulation
Specified as the keywords auto, none, manipulation, OR
one of the keywords pan-x, pan-left, pan-right, and/or one of the keywords pan-y, pan-up, pan-down, plus optionally the keyword pinch-zoom.
pan-left pan-right is not valid (use pan-x).pan-up pan-down is not valid (use pan-y).touch-action propertypan-y, pan-up, pan-down and/or pinch-zoom.pan-x, pan-left, pan-right and/or pinch-zoom.pan- values. user-select propertyControls whether the user can select text.
auto | text | none | contain | all
nonecontainall or none, it's the sametext
Not fully supported
- Generate Text -
@supports
@supports (display: flex) {
/* rules for browsers supporting flex box (with no prefix) */
}
@supports (will-change) {
/* rules for browsers supporting improved performance */
}
@supports or and ()
@supports ((transition-property: color) or (animation-name: foo)) and
(transform: rotate(10deg)) {
...
}
not
@supports not ( display: flex ) {
main { width: 100%; }
main > nav { width: 25%; }
main > article { width: 75%; }
}
Don't use this legacy support detection:
@media screen and (transform-3d) {
.transforms {}
}
Just including it, in case you come across it