Media queries are used to set breakpoints for layout changes. While responsive design using flexbox and grid have reduced our need for media queries, they are still very important for complex and dynamic layouts.
- Media queries set breakpoints for how content is displayed
- you can make very percise layout changes for different screen sizes
- traditionally, css has been programmed for desktop design first and mobile layouts second
- modern css aims to write for a mobile layout first, and then make exceptions for the desktop
- hence mobile first
- Media queries give you the ability to serve specific changes for different aspect ratios. So everyone can enjoy your website.
- Determine the maximum screen size for a particular layout
- Create a media query that kicks in at this screen size
- Fill the media query with css declarations for the screen size range in question
- These layout changes could not be done in flex without media queries
- Use media queries for things that you cannot do with a responsive layout
- Always put media queries near the end of your css. -- They are overrides