r/javascript • • Aug 21 '18

Effectively supported in all browsers, JavaScript has its own form of media queries just like CSS.

https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
465 Upvotes

114 comments sorted by

View all comments

-34

u/StoneCypher Aug 21 '18

um, this actually is css, not javascript

8

u/ejfrodo Aug 22 '18

um, this is actually javascript, not css. unleses this example from the article somehow works in a .css file

if (window.matchMedia("(min-width: 400px)").matches) {
  console.log('Larger than 399px');
} else {
  console.log('Less than 400px');
}