This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
IGNORE prefers-color-scheme
article for web.dev
#929
Closed
Closed
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 027e37b
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 216e815
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija b62e008
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 8a769a9
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija add3f06
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 11c21c2
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 5358c15
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 22a93c6
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija bfabad9
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 78ad3cb
Format the options in the table
mihajlija 39207e6
Fix missing link
mihajlija 741b545
Add a link to explain 14KB threshold
mihajlija 0aaa1a0
Migrate prefers-color-scheme article from WebFu
tomayac 6d88724
Add gulp task so we can deploy styles. (#933)
robdodson 77121ce
Adds guidance about error boundaries to React.lazy docs (#924)
jeffposnick cc25619
Make Houssein codeowner for React docs. (#934)
robdodson 33790a3
I/O 2019: Speed at Scale blog post recap (#931)
addyosmani f275c97
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija d4749aa
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 8e1fc2d
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 7d2f384
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 968add4
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 9b07b04
Update src/site/content/en/fast/codelab-extract-and-inline-critical-cβ¦
mihajlija 5ae507f
Update index.md
mihajlija c41d06b
Delete inline-critical-css.png
mihajlija 0e9486b
Update screenshot
mihajlija be02efb
Delete eliminate-render-blocking-resources.png
mihajlija df9d4b2
Update screenshot
mihajlija 59eb5f6
Better align with web.dev template
tomayac 82ee9af
Added missing proxx github repo link (#937)
lego-sharat 32c8c71
Updates to React docs (#935)
housseindjirdeh 7ab8969
Fixes #576 (imagemagick commmand broken on windows) (#932)
khempenius 1dca010
Add glitch and network loading diagrams
tomayac b89fa9e
Write up how to use section
tomayac 50770fb
Bump tar from 2.2.1 to 2.2.2 (#940)
dependabot[bot] 67fe154
Rev eleventy to 0.8.3 and rev syntax highlighter. (#942)
robdodson 47d43a1
Merge pull request #918 from GoogleChrome/critical-css-codelab
addyosmani 7b39fa2
Blog: Add a guide about critical CSS tools (#898)
mihajlija a46279b
Retitle critical css post.
robdodson 0fada55
Rename extract css post.
robdodson b9b2c10
Works offline edits.
robdodson fd820fa
Add note to readme. (#945)
robdodson 3e5c9a1
enables customizing previewSize from front matter (#920)
argyleink 64cb7fe
Update to include my authorship information.
egsweeny 8458de1
[blog] Add long tasks article (#943)
addyosmani ac0af0b
Fix long task images.
robdodson 7551267
Bump fstream from 1.0.11 to 1.0.12 (#955)
dependabot[bot] 34446b8
Publish what should you measure post. (#957)
robdodson ed37130
Use correct apache license.
robdodson a35ff14
update illustrations for lighthosue
robdodson 1edea49
Add image optimization feature policies article. (#928)
jpmedley 073e397
Address Phil Walton's feedback (fixes #954)
addyosmani 9265bea
Merge pull request #960 from GoogleChrome/long-task-edits
addyosmani a78ca01
Update CODEOWNERS
robdodson ea87993
Fix for typo (#962)
fahad19 fc41de7
Blog: Service Worker Mindset (#946)
geddski 74ae8fe
Rev service workies post date.
robdodson bcf8672
Fixes #959. Fix RSS links.
robdodson 2acf39e
Fixes #899. Remove trailing slash in share url.
robdodson 3075331
Update CODEOWNERS
robdodson 6f85190
Blog: JS and Search (I/O 19) (#947)
AVGP 7fa33a8
Rev js search publish date.
robdodson 64b9b09
Editorial fixes to Service Workies post (#978)
mfriesenhahn 8bb85e8
Add Netlify preview builds. (#979)
robdodson fc0f871
Add netlify rewrites.
robdodson 41ac643
Bump js-yaml from 3.13.0 to 3.13.1 (#980)
dependabot[bot] 35cb962
Add feature request template.
robdodson 3c17679
Add bug template.
robdodson 7fedd67
Update pull_request_template.md
robdodson e808c2c
Add content request template.
robdodson 6c49e9b
Fix weird spacing in content request template.
robdodson c219dc2
Try to fix weird spacing in issue template.
robdodson 35737c1
Fix weird spacing. lol. final final.
robdodson 8e47bab
Fix the usage of react-window-infinite-loader (#966)
27289a2
Remove leading slash so paths are not absolute.
robdodson fffa0a2
Fix link of extract-critical-css (#981)
akccakcctw 84d0a41
Add columns component. (#952)
robdodson f710949
Fix title on perf measurement post.
robdodson d8d08a7
Fix links and Glitch instructions (#987)
mihajlija 94eac55
Remove glitches directory. (#983)
robdodson 56b5e3f
Link "Defer unused CSS" guide to "Extract critical CSS" guide. (#992)
demianrenzulli 1c59a9a
Publish How Can Performance Improve Conversions
robdodson 3f1f438
Add initial Layout Instability API draft (#996)
philipwalton aa855fd
Add YouTube & Media Capabilities user study post (#967)
beaufortfrancois 208b3a3
Fix double sentence in youtube-media-capabilities (#1002)
darthmaim 4895ea2
Add Web Payments update. Fixes #994. Fixes #995
robdodson af26637
Quote article title in Web Payments post.
robdodson fac8e16
Add Instruction component. (#990)
robdodson 27489ee
Add Value of Speed post. Fixes #916.
robdodson b5295de
Update content_request.md
robdodson 201ecec
Add YouTube shortcode. (#1006)
robdodson a0ae543
Remove extra lineitem div.
robdodson f7964dd
Add LightWallet article (#999)
khempenius 8cf3fc0
Migrate prefers-color-scheme article from WebFu
tomayac c11f57e
Better align with web.dev template
tomayac dcfb2db
Add glitch and network loading diagrams
tomayac 318cb72
Write up how to use section
tomayac 3b64756
Add iOS screenshot
tomayac 3a28771
More stuff in the intro
tomayac 27e1b8a
Merge branch 'prefers-color-scheme' of github.com:GoogleChrome/web.deβ¦
tomayac 28e8b5a
Remove new line
tomayac 3ad3a01
Add more best practice
tomayac c23ccf7
Add opt-out <dark-mode-toggle> section
tomayac 346155f
First complete-ish draft
tomayac 56f478e
Some typo fixes
tomayac 8ad2cf5
Complete front matter
tomayac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||||||||
authors: | ||||||||
- thomassteiner | ||||||||
date: 2019-05-23 | ||||||||
hero: macosx.png | ||||||||
alt: macOS X Dark Mode preferences. | ||||||||
description: | | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need a description so it'll appear in search. |
||||||||
|
||||||||
tags: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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 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 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 7 supported color, the default user interface was still black-and-white. | ||||||||
You can actually | ||||||||
experience System 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 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 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 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 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.