Media Queries topic

Media Queries are a way to target browsers by certain characteristics, features, and user preferences, then apply styles, or run other code based on those things. They are a key part of responsive web design, as they allow you to create different layouts depending on the size of the viewport, but they can also be used to detect other things about the environment your site is running on, for example whether the user is using a touchscreen rather than a mouse. Media queries are used for the following:

  • conditionally apply styles with the CSS @media and @import at-rules
  • target specific media for the <style>, <link>, <source>, and other HTML elements with the media= attribute
  • test and monitor media states using the Window.matchMedia() and EventTarget.addEventListener() methods

A media query is composed of an optional media type and any number of media feature expressions, which may optionally be combined in various ways using logical operators.

  • Media types define the broad category of device for which the media query applies. The type is optional except when using the not or only logical operators.
    • all: Suitable for all devices.
    • print: Intended for paged material and documents viewed on a screen in print preview mode.
    • screen: Intended primarily for screens.
  • Media features describe a specific characteristic of the user agent, output device, or environment. Media Queries Level 4 groups 18 media features into 5 categories.
    • Viewport/Page Characteristics
    • Display Quality
    • Color
    • Interaction
    • Video-prefixed: The spec references user agents, including TVs, that render video and graphics in two separate planes that each have their own characteristics. (upcoming Media Queries Level 5)
  • Logical operators can be used to compose a complex media query: not, and, and only. You can also combine multiple media queries into a single rule by separating them with commas.

List Media Queries repositories

breakpoint

35
Stars
4
Forks
Watchers

A tiny API wrapper around window.matchMedia

Fluid-Size

42
Stars
1
Forks
Watchers

:triangular_ruler::iphone::computer::desktop_computer: A method of fluidly resizing in various devices based on visual angle. (with SASS) :revolving_hearts: :eyes:

Hipster-Startup-Website

39
Stars
54
Forks
Watchers

A single page static website template for a startup company.

pulsar-core

27
Stars
1
Forks
Watchers

🚀 Handy dynamic styles utilities for React Native and React Native Web.

actual

51
Stars
6
Forks
Watchers

Determine actual CSS media query breakpoints via JavaScript

Slidy

294
Stars
13
Forks
Watchers

📸 Sliding action script

mq-scss

124
Stars
8
Forks
Watchers

Extremely powerful Sass media query mixin. Allows you to create almost any media query you can imagine.

styled-breakpoints

545
Stars
24
Forks
Watchers

Simple and powerful breakpoints for styled components and emotion.