Responsive web design (RWD) is a collection of techniques to create web pages that adapt to the browser's size
Elements are laid out on fluid, proportion-based grids that use relative units like percentages instead of absolute units like pixels
Images are sized with relative units to adapt to various screen sizes
CSS media queries apply different CSS styles depending on the browser's width
Media queries used in combination with media type and expression that evaluate to true
or false based on various media features. Ex: @media screen and (max-height:300px)
Media types
all - All devices
print - Printers and documents viewed on screen in print preview mode
screen - All devices that don't match "print" or "speech"
speech - Screenreaders
Common media features
device-height - Height of the output device (entire screen)
device-width - Width of the output device (entire screen)
height - Height of the output device's viewport
width - Width of the output device's viewport
orientation - portrait or landscape
Media features may be prefaced with min- or max- to express
≥ and ≤ constraints
Examples
Numbers used in media queries are often called breakpoints
Breakpoints often set for mobile, tablet, and/or desktops
Must use viewport meta tag for breakpoints to work!
Example using grid layout with 2 breakpoints to alter design
for tablet and desktop screens
<picture> element uses <source> elements to
specify media queries that are used to determine which image should be downloaded -
ideal for art direction
<!-- Browser 300px wide does not match any media query, so dog-narrow.jpg downloaded -->
<!-- Browser 400px wide downloads dog.jpg -->
<!-- Browser 1000px wide downloads dog-wide.jpg -->
<!-- If no media queries match or browser doesn't know picture tag, dog-narrow.jpg downloaded -->
<picture>
<source media="(min-width: 600px)"
srcset="dog-wide.jpg">
<source media="(min-width: 400px)"
srcset="dog.jpg">
<img src="dog-narrow.jpg" alt="dog">
</picture>