Course contentsShow
← Web Development
Lesson 1235 of 2,98222. Responsive Images and MediaFree lesson

Art Direction for Print and Dark Mode

Use media queries beyond viewport width like prefers-color-scheme or print in picture sources.

What You'll Learn

You'll learn how to use <picture> with media queries that respond to print mode and dark mode preferences, not just screen size.


Beyond Viewport Width

Until now, we've mostly used the media attribute in <source> elements to check viewport width. But CSS media queries can test many other conditions — and <picture> can use them too!

Two powerful examples:

1. Print Stylesheets

You can serve a completely different image when the page is printed:

<picture>
  <source srcset="chart-highres-bw.png" media="print">
  <img src="chart-color.png" alt="Sales chart">
</picture>

When someone prints the page, they'll get a high-contrast black-and-white version optimized for paper. On screen, they see the colorful version.

2. Dark Mode (prefers-color-scheme)

Serve images that match the user's system theme:

<picture>
  <source srcset="logo-dark.svg" media="(prefers-color-scheme: dark)">
  <img src="logo-light.svg" alt="Company logo">
</picture>

If the user has dark mode enabled, they see logo-dark.svg. Otherwise, they get the default light version.


Why This Matters

Analogy: Just like a chameleon changes color to match its environment, your images can adapt to printing or theme preferences automatically. The browser picks the best source based on the current context, not just screen size.

You can even combine conditions:

<source srcset="wide-dark.jpg" media="(min-width: 800px) and (prefers-color-scheme: dark)">

Key Takeaway: The media attribute in <picture> sources accepts any CSS media query, including print, (prefers-color-scheme: dark), and combined conditions, giving you full art direction control beyond just viewport dimensions.