aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/css/@media/prefers-color-scheme/index.html
blob: 7fc1c8778800c53b9957a505e6cdd3c7827d9c4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
title: prefers-color-scheme
slug: Web/CSS/@media/prefers-color-scheme
tags:
  - '@media'
  - CSS
  - Reference
  - Web
  - prefers-color-scheme
translation_of: Web/CSS/@media/prefers-color-scheme
---
<div class="blockIndicator note">
<p>Se você definiu <code>privacy.resistFingerprinting</code> como <strong>true</strong>, <code><a href="https://developer.mozilla.org/docs/Web/CSS/@media/prefers-color-scheme">prefers-color-scheme</a></code> será substituída pela <code>light</code>.</p>
</div>

<p>O <strong><code>prefers-color-scheme</code></strong> <a href="/en-US/docs/CSS">CSS</a> <a href="/en-US/docs/Web/CSS/Media_Queries/Using_media_queries#Media_features">media feature</a> é usado para detectar se o usuário solicitou que o sistema use um tema de cores claras ou escuras.</p>

<h2 id="Syntax">Syntax</h2>

<dl>
 <dt><code><dfn>no-preference</dfn></code></dt>
 <dd>Indica que o usuário não fez nenhuma preferência conhecida pelo sistema. Este valor da palavra-chave é avaliado como <code>false</code> no <a href="https://drafts.csswg.org/mediaqueries-5/#boolean-context" id="ref-for-boolean-context④">contexo booleano</a>.</dd>
 <dt><code><dfn>light</dfn></code></dt>
 <dd>Indica que o usuário notificou o sistema de que prefere uma interface com um tema claro.</dd>
 <dt><code><dfn>dark</dfn></code></dt>
 <dd>Indica que o usuário notificou o sistema de que prefere uma interface com um tema escuro.</dd>
</dl>

<h2 id="Exemplos">Exemplos</h2>

<p>Os elementos abaixo têm um tema de cores inicial. Eles podem ser mais temáticos de acordo com a preferência do esquema de cores do usuário.</p>

<h3 id="HTML">HTML</h3>

<pre class="brush: html">&lt;div class="day"&gt;Dia (inicial)&lt;/div&gt;
&lt;div class="day light-scheme"&gt;Dia (modificar e utilizar um tema claro)&lt;/div&gt;
&lt;div class="day dark-scheme"&gt;Dia (modificar e utilizar um tema escuro)&lt;/div&gt; &lt;br&gt;

&lt;div class="night"&gt;Noite (inicial)&lt;/div&gt;
&lt;div class="night light-scheme"&gt;Noite (modificar e utilizar um tema claro)&lt;/div&gt;
&lt;div class="night dark-scheme"&gt;Noite (modificar e utilizar um tema escuro)&lt;/div&gt;</pre>

<h3 id="CSS">CSS</h3>

<pre class="brush: css">.day   { background: #eee; color: black; }
.night { background: #333; color: white; }

@media (prefers-color-scheme: dark) {
  .day.dark-scheme   { background:  #333; color: white; }
  .night.dark-scheme { background: black; color:  #ddd; }
}

@media (prefers-color-scheme: light) {
  .day.light-scheme   { background: white; color:  #555; }
  .night.light-scheme { background:  #eee; color: black; }
}

.day, .night {
  display: inline-block;
  padding: 1em;
  width: 7em;
  height: 2em;
  vertical-align: middle;
}
</pre>

<h3 id="Resultado">Resultado</h3>

<p>{{EmbedLiveSample("Exemples")}}</p>

<h2 id="Especificações">Especificações</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Especificação</th>
   <th scope="col">Estado</th>
   <th scope="col">Comentários</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS5 Media Queries', '#descdef-media-prefers-color-scheme', 'prefers-color-scheme')}}</td>
   <td>{{Spec2('CSS5 Media Queries')}}</td>
   <td>Definição inicial.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Compatibilidade com navegadores</h2>

<p>{{Compat("css.at-rules.media.prefers-color-scheme")}}</p>

<h2 id="Veja_também">Veja também</h2>

<ul>
 <li><a href="https://www.youtube.com/watch?v=jmepqJ5UbuM">Video tutorial: Coding a Dark Mode for your Website</a></li>
 <li><a href="https://stuffandnonsense.co.uk/blog/redesigning-your-product-and-website-for-dark-mode">Redesigning your product and website for dark mode</a></li>
 <li>Changing color schemes in <a href="https://blogs.windows.com/windowsexperience/2019/04/01/windows-10-tip-dark-theme-in-file-explorer/">Windows</a>, <a href="https://developer.apple.com/design/human-interface-guidelines/macos/visual-design/dark-mode/">macOS</a> and <a href="https://www.theverge.com/2019/5/7/18530599/google-android-q-features-hands-on-dark-mode-gestures-accessibility-io-2019">Android</a>.</li>
</ul>

<div>{{QuickLinksWithSubpages("/en-US/docs/Web/CSS/@media/")}}</div>