Media queries allow you to apply CSS styles depending on a device's general type (such as print vs. screen) or other characteristics such as screen resolution or browser viewport width. Media queries are used for the following:
- To conditionally apply styles with the CSS
@mediaand@importat-rules. - To target specific media for the
<style>,<link>,<source>, and other HTML elements with themedia=attribute. - To test and monitor media states using the
Window.matchMedia()andEventTarget.addEventListener()methods.
Note: The examples on this page use CSS's @media for illustrative purposes, but the basic syntax remains the same for all types of media queries.