Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

IGNORE prefers-color-scheme article for web.dev #929

Closed
wants to merge 107 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
b1628f5
Add critical CSS codelab
mihajlija May 15, 2019
027e37b
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 22, 2019
216e815
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 22, 2019
b62e008
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 22, 2019
8a769a9
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 22, 2019
add3f06
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 22, 2019
11c21c2
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 22, 2019
5358c15
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 22, 2019
22a93c6
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 22, 2019
bfabad9
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 22, 2019
78ad3cb
Format the options in the table
mihajlija May 22, 2019
39207e6
Fix missing link
mihajlija May 22, 2019
741b545
Add a link to explain 14KB threshold
mihajlija May 22, 2019
0aaa1a0
Migrate prefers-color-scheme article from WebFu
tomayac May 23, 2019
6d88724
Add gulp task so we can deploy styles. (#933)
robdodson May 23, 2019
77121ce
Adds guidance about error boundaries to React.lazy docs (#924)
jeffposnick May 23, 2019
cc25619
Make Houssein codeowner for React docs. (#934)
robdodson May 23, 2019
33790a3
I/O 2019: Speed at Scale blog post recap (#931)
addyosmani May 23, 2019
f275c97
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 23, 2019
d4749aa
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 23, 2019
8e1fc2d
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 23, 2019
7d2f384
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 23, 2019
968add4
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 23, 2019
9b07b04
Update src/site/content/en/fast/codelab-extract-and-inline-critical-c…
mihajlija May 23, 2019
5ae507f
Update index.md
mihajlija May 23, 2019
c41d06b
Delete inline-critical-css.png
mihajlija May 23, 2019
0e9486b
Update screenshot
mihajlija May 23, 2019
be02efb
Delete eliminate-render-blocking-resources.png
mihajlija May 23, 2019
df9d4b2
Update screenshot
mihajlija May 23, 2019
59eb5f6
Better align with web.dev template
tomayac May 24, 2019
82ee9af
Added missing proxx github repo link (#937)
lego-sharat May 24, 2019
32c8c71
Updates to React docs (#935)
housseindjirdeh May 24, 2019
7ab8969
Fixes #576 (imagemagick commmand broken on windows) (#932)
khempenius May 24, 2019
1dca010
Add glitch and network loading diagrams
tomayac May 27, 2019
b89fa9e
Write up how to use section
tomayac May 28, 2019
50770fb
Bump tar from 2.2.1 to 2.2.2 (#940)
dependabot[bot] May 28, 2019
67fe154
Rev eleventy to 0.8.3 and rev syntax highlighter. (#942)
robdodson May 28, 2019
47d43a1
Merge pull request #918 from GoogleChrome/critical-css-codelab
addyosmani May 29, 2019
7b39fa2
Blog: Add a guide about critical CSS tools (#898)
mihajlija May 29, 2019
a46279b
Retitle critical css post.
robdodson May 29, 2019
0fada55
Rename extract css post.
robdodson May 29, 2019
b9b2c10
Works offline edits.
robdodson May 29, 2019
fd820fa
Add note to readme. (#945)
robdodson May 29, 2019
3e5c9a1
enables customizing previewSize from front matter (#920)
argyleink May 30, 2019
64cb7fe
Update to include my authorship information.
egsweeny May 23, 2019
8458de1
[blog] Add long tasks article (#943)
addyosmani May 30, 2019
ac0af0b
Fix long task images.
robdodson May 30, 2019
7551267
Bump fstream from 1.0.11 to 1.0.12 (#955)
dependabot[bot] May 31, 2019
34446b8
Publish what should you measure post. (#957)
robdodson May 31, 2019
ed37130
Use correct apache license.
robdodson May 31, 2019
a35ff14
update illustrations for lighthosue
robdodson May 29, 2019
1edea49
Add image optimization feature policies article. (#928)
jpmedley May 31, 2019
073e397
Address Phil Walton's feedback (fixes #954)
addyosmani Jun 1, 2019
9265bea
Merge pull request #960 from GoogleChrome/long-task-edits
addyosmani Jun 1, 2019
a78ca01
Update CODEOWNERS
robdodson Jun 4, 2019
ea87993
Fix for typo (#962)
fahad19 Jun 4, 2019
fc41de7
Blog: Service Worker Mindset (#946)
geddski Jun 4, 2019
74ae8fe
Rev service workies post date.
robdodson Jun 4, 2019
bcf8672
Fixes #959. Fix RSS links.
robdodson Jun 4, 2019
2acf39e
Fixes #899. Remove trailing slash in share url.
robdodson Jun 4, 2019
3075331
Update CODEOWNERS
robdodson Jun 5, 2019
6f85190
Blog: JS and Search (I/O 19) (#947)
AVGP Jun 5, 2019
7fa33a8
Rev js search publish date.
robdodson Jun 5, 2019
64b9b09
Editorial fixes to Service Workies post (#978)
mfriesenhahn Jun 5, 2019
8bb85e8
Add Netlify preview builds. (#979)
robdodson Jun 5, 2019
fc0f871
Add netlify rewrites.
robdodson Jun 5, 2019
41ac643
Bump js-yaml from 3.13.0 to 3.13.1 (#980)
dependabot[bot] Jun 5, 2019
35cb962
Add feature request template.
robdodson Jun 5, 2019
3c17679
Add bug template.
robdodson Jun 5, 2019
7fedd67
Update pull_request_template.md
robdodson Jun 5, 2019
e808c2c
Add content request template.
robdodson Jun 5, 2019
6c49e9b
Fix weird spacing in content request template.
robdodson Jun 5, 2019
c219dc2
Try to fix weird spacing in issue template.
robdodson Jun 5, 2019
35737c1
Fix weird spacing. lol. final final.
robdodson Jun 5, 2019
8e47bab
Fix the usage of react-window-infinite-loader (#966)
Jun 6, 2019
27289a2
Remove leading slash so paths are not absolute.
robdodson Jun 6, 2019
fffa0a2
Fix link of extract-critical-css (#981)
akccakcctw Jun 6, 2019
84d0a41
Add columns component. (#952)
robdodson Jun 6, 2019
f710949
Fix title on perf measurement post.
robdodson Jun 7, 2019
d8d08a7
Fix links and Glitch instructions (#987)
mihajlija Jun 7, 2019
94eac55
Remove glitches directory. (#983)
robdodson Jun 11, 2019
56b5e3f
Link "Defer unused CSS" guide to "Extract critical CSS" guide. (#992)
demianrenzulli Jun 11, 2019
1c59a9a
Publish How Can Performance Improve Conversions
robdodson Jun 11, 2019
3f1f438
Add initial Layout Instability API draft (#996)
philipwalton Jun 11, 2019
aa855fd
Add YouTube & Media Capabilities user study post (#967)
beaufortfrancois Jun 12, 2019
208b3a3
Fix double sentence in youtube-media-capabilities (#1002)
darthmaim Jun 13, 2019
4895ea2
Add Web Payments update. Fixes #994. Fixes #995
robdodson Jun 13, 2019
af26637
Quote article title in Web Payments post.
robdodson Jun 13, 2019
fac8e16
Add Instruction component. (#990)
robdodson Jun 13, 2019
27489ee
Add Value of Speed post. Fixes #916.
robdodson Jun 13, 2019
b5295de
Update content_request.md
robdodson Jun 13, 2019
201ecec
Add YouTube shortcode. (#1006)
robdodson Jun 14, 2019
a0ae543
Remove extra lineitem div.
robdodson Jun 14, 2019
f7964dd
Add LightWallet article (#999)
khempenius Jun 14, 2019
8cf3fc0
Migrate prefers-color-scheme article from WebFu
tomayac May 23, 2019
c11f57e
Better align with web.dev template
tomayac May 24, 2019
dcfb2db
Add glitch and network loading diagrams
tomayac May 27, 2019
318cb72
Write up how to use section
tomayac May 28, 2019
3b64756
Add iOS screenshot
tomayac Jun 17, 2019
3a28771
More stuff in the intro
tomayac Jun 18, 2019
27e1b8a
Merge branch 'prefers-color-scheme' of github.com:GoogleChrome/web.de…
tomayac Jun 18, 2019
28e8b5a
Remove new line
tomayac Jun 18, 2019
3ad3a01
Add more best practice
tomayac Jun 18, 2019
c23ccf7
Add opt-out <dark-mode-toggle> section
tomayac Jun 18, 2019
346155f
First complete-ish draft
tomayac Jun 19, 2019
56f478e
Some typo fixes
tomayac Jun 19, 2019
8ad2cf5
Complete front matter
tomayac Jun 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
174 changes: 174 additions & 0 deletions src/site/content/en/blog/prefers-color-scheme/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
---
title: Hello Darkness, My Old Friendβ€”Dark Theme is Here
subhead:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a catchy subhead. This will appear on the post's card on the blog landing page and under the title on the article itself.

authors:
- thomassteiner
date: 2019-05-23
hero: macosx.png
alt: macOS X Dark Mode preferences.
description: |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a description so it'll appear in search.


tags:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tags:
tags:
- post

post tag is required to show up on the blog landing page. I need to figure out a better way to make sure all blog posts get it automatically :\

- dark-mode
---

# Hello Darkness, My Old Friend: Dark Theme is Here

## Background

<figure class="attempt-right">
<img style="height:175px; width:auto;" src="green-screen.jpg" alt="Green screen computer monitor" intrinsicsize="640x480">
<figcaption><b>Fig. 1</b> Green screen (<a href="https://commons.wikimedia.org/wiki/File:Compaq_Portable_and_Wordperfect.JPG">Source</a>)</figcaption>
</figure>

We have gone full circle with dark mode.
In the dawn of personal computing, dark mode wasn't a deliberate choice,
but purely a matter of fact:
Monochrome Cathod-Ray Tube (CRT) computer monitors work by firing electron beams
on a phosphorescent screen, and as the phospor that these early CRTs used was green,
they were oftentimes referred to as
[green screens](https://commons.wikimedia.org/wiki/File:Schneider_CPC6128_with_green_monitor_GT65,_start_screen.jpg).
Information like text was displayed in green, and the rest of the screen was black.

The subsequently introduced Color CRTs display multiple colors
through the use of red, green, and blue phosphors.
They create white by activating all three phosphors simultaneously.
With the advent of more sophisticated *What You See Is What You Get* (WYSIWYG)
[desktop publishing](https://en.wikipedia.org/wiki/Desktop_publishing),
the idea of making the document resemble a physical sheet of paper became popular.
This is where *dark-on-white* as a design trend started,
and this trend was carried over to the document-based web.
To the present day, web pages and apps are typically designed with dark text on a light background,
a baseline assumption that is also hard-coded in User-Agent (UA) stylesheets like
[Chrome's](https://chromium.googlesource.com/chromium/blink/+/master/Source/core/css/html.css).

<figure class="attempt-right">
<img style="height:175px; width:auto;" src="word-processing.jpg" alt="Dark-on-white word processing" intrinsicsize="698x551">
<figcaption><b>Fig. 2</b> Dark-on-white (<a href="https://www.youtube.com/watch?v=qKkABzt0Zqg">Source</a>)</figcaption>
</figure>

Today, a lot of content consumption and creation has shifted to mobile devices
that use LED backlit LCD or energy-saving AMOLED screens, and on the desktop as well
(which can be a full PC or a laptop), the days of CRTs are long over.
With such smaller and more transportable computers, tablets, and smartphones,
new usage patterns have evolved, like people using their devices in their beds at night-time,
and tasks like coding or high-end gaming frequently happen after-hours in dim environments.
The more people use their devices in the dark, and even more since Apple has introduced
[Dark Mode in macOS Mojave](https://support.apple.com/en-us/HT208976) on the desktop,
the idea of going back to the roots of *light-on-dark* is becoming increasingly popular again.

## Why Dark Mode

When people get asked
[why they like or want dark mode](https://medium.com/dev-channel/let-there-be-darkness-maybe-9facd9c3023d),
the most popular response is that *"it's easier on the eyes,"*
followed by *"it's elegant and beautiful."*
Apple in their
[Dark Mode developer documentation](https://developer.apple.com/documentation/appkit/supporting_dark_mode_in_your_interface)
explicitly write: *"The choice of whether to enable a light or dark appearance
is an aesthetic one for most users, and might not relate to ambient lighting conditions."*

<figure class="attempt-right">
<img style="height:225px; width:auto;" src="closeview.png" alt="CloseView in Mac OS System 7 with \"White on Black\" mode" intrinsicsize="531x618">
<figcaption><b>Fig. 3</b> System&nbsp;7 CloseView (<a href="https://archive.org/details/mac_Macintosh_System_7_at_your_Fingertips_1992">Source</a>)</figcaption>
</figure>

However, there're also people who actually need dark mode or other accessibility tools,
for example, users with low vision.
The earliest occurrence of such a tool I could find is
[System&nbsp;7](https://en.wikipedia.org/wiki/System_7)'s *CloseView* feature that had a toggle for
*"Black on White"* and *"White on Black,"* which arguably can be called dark mode.
While System&nbsp;7 supported color, the default user interface was still black-and-white.
You can actually
experience System&nbsp;7 live thanks to the
[Internet Archive](https://archive.org/details/mac_MacOS_7.0.1_compilation)
(unfortunately the *CloseView* feature was on a separate floppy disk not part of the emulation).
These simple inversion-based implementations started to suffer the moment color was introduced.
User research by Szpiro *et al.* on
[how people with low vision access computing devices](https://dl.acm.org/citation.cfm?id=2982168)
showed that all interviewed users disliked inverted images, however,
that some preferred light text on a dark background.
On its mobile devices, Apple accommodates for this shortcoming with a feature called
[Smart Invert](https://www.apple.com//accessibility/iphone/vision/)
that reverses the colors on the display, except for images, media,
and some apps that use dark color styles.

Computer Vision Syndrome, also known as Digital Eye Strain, is
[defined](https://onlinelibrary.wiley.com/doi/full/10.1111/j.1475-1313.2011.00834.x)
as *"the combination of eye and vision problems associated with the use of computers
(including desktop, laptop and tablets) and other electronic displays (e.g.
smartphones and electronic reading devices)."*
It has been [proposed](https://bmjopen.bmj.com/content/5/1/e006748)
that the use of electronic devices by adolescents, particularly at night time,
leads to an increased risk of shorter sleep duration,
longer sleep-onset latency, and increased sleep deficiency.
Additionally, exposure to blue light has been widely
[reported](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4254760/)
to be involved in the regulation of circadian rhythm and the sleep cycle,
and irregular light environments may lead to sleep deprivation,
possibly affecting mood and task performance, according to
[Rosenfield](https://www.college-optometrists.org/oip-resource/computer-vision-syndrome--a-k-a--digital-eye-strain.html).
To limit these negative effects, limiting blue light by adjusting the display color temperature
through features like iOS' [Night Shift](https://support.apple.com/en-us/HT207570) or Android's
[Night Light](https://support.google.com/pixelphone/answer/7169926?) can help,
as well as avoiding bright lights or irregular lights in general through dark themes or dark modes.

## Supporting Dark Mode

[Media Queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries)
allow authors to test and query values or features of the user agent or display device,
independent of the document being rendered.
They are used in the CSS `@media` rule to conditionally apply styles to a document,
and in various other contexts and languages, such as HTML and JavaScript.
[Media Queries Level&nbsp;5](https://drafts.csswg.org/mediaqueries-5/)
introduces so-called user preference media features, that is,
a way for sites to detect the user's preferred way to display content.

Note: An established user preference media feature is `prefers-reduced-motion`
that lets you detect the desire for less motion on a page.
If you're interested, I have written about
[`prefers-reduced-motion`](https://developers.google.com/web/updates/2019/03/prefers-reduced-motion)
before.

The `prefers-color-scheme` media feature is used to detect
if the user has requested the page to use a light or dark color theme.
It takes the following values:

- `no-preference`:
Indicates that the user has made no preference known to the system.
This keyword value evaluates as false in the
[boolean context](https://drafts.csswg.org/mediaqueries-5/#boolean-context).
- `light`:
Indicates that the user has notified the system that they prefer a page that has a light theme
(dark text on light background).
- `dark`:
Indicates that the user has notified the system that they prefer a page that has a dark theme
(light text on dark background).

Before we dive into this, let's first clarify how people can activate dark mode in the first place.

<figure class="attempt-left">
<img style="height:225px; width:auto;" src="windows10.png" alt="Windows 10 dark theme settings" intrinsicsize="1812x1513">
<figcaption><b>Fig. 4</b> Windows&nbsp;10 dark theme settings</figcaption>
</figure>

<figure class="attempt-left">
<img style="height:225px; width:auto;" src="macosx.png" alt="macOS X dark mode settings" intrinsicsize="668x678">
<figcaption><b>Fig. 5</b> macOS&nbsp;X dark mode settings</figcaption>
</figure>

## Dark Mode Best Practices

## Related Links

- Resources for the `prefers-color-scheme` media query:
- [Chrome Platform Status page](https://chromestatus.com/feature/5109758977638400)
- [Chromium bug](https://crbug.com/889087)
- [Media Queries Level&nbsp;5 spec](https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme)
- Resources for the `supported-color-schemes` meta tag and CSS property:
- [Chrome Platform Status page](https://chromestatus.com/feature/5330651267989504)
- [Chromium bug](http://crbug.com/925935)
- [CSS WG GitHub Issue for the meta tag and the CSS property](https://github.com/w3c/csswg-drafts/issues/3299)
- [HTML WHATWG GitHub Issue for the meta tag](https://github.com/whatwg/html/issues/4504)

## Acknowledgements
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.