r/javascript • u/[deleted] • 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
r/javascript • u/[deleted] • Aug 21 '18
1
u/GeneralYouri Aug 23 '18
For the longest time you've been able to edit CSS styles from within JS. So when CSS introduces media queries, JS needs a way to work with those to continue being able to edit CSS styles properly. As far as I know, that's about all this is.
Also, as with other CSS styling, you'll want to prefer defining those directly via CSS. Handling them via the JS DOM is for those use cases where CSS itself isn't enough - such as when you need variables depending on runtime state.