How to use Media Query in CSS

author details
AdiPie
25th Feb 2021
2 mins read
Image
How to use Media Query in CSS

Media Query

On the off chance that you have ever made a print stylesheet for a site, at that point you will be acquainted with making a particular stylesheet to become an integral factor under specific conditions - on account of a print stylesheet when the page is printed. This usefulness was empowered in CSS2 by media types.

Media Types let you determine a sort of media to target, so you could target print, etc. Miserably these media types never acquired a great deal of help by devices and, other than the print media type, you will infrequently see them being used.

 

/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {..}

/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {..}

/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {..}

/* Large devices (laptops/desktops, 992px and up) */
@media only screen and (min-width: 992px) {..}

/* Extra large devices (large laptops and desktops, 1200px and up) */
@media only screen and (min-width: 1200px) {..}

/* Devices in landscape mode */
@media only screen and (orientation: landscape) {..}