CSS: Media Query (Responsive Design)

By Xah Lee. Date: . Last updated: .

You can use CSS “Media Query” to set what CSS to use depending on user's window size.


/* current viewport width is ≥ 1024 px */
@media screen and (min-width: 1024px) {
    body {margin-right:220px;}
    aside#id1 {display:initial;width:201px;}

/* current viewport width is ≤ 1023 px */
@media screen and (max-width: 1023px) {
    body {margin-right:10px;}
    aside#id1 {display:none;width:10px;}


/* current viewport width w is 1000 ≤ w ≤ 1500 px */
@media screen and (min-width: 1000px) and (max-width: 1500px) {
 body {background-color:cyan}


Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.