Dark Mode
Introduction
This sample demonstrates how to use dark mode. It shows both prefers-color-scheme
as well as a manual toggle for people on non-supporting browsers.
You can read more about prefers-color-scheme
in the article
https://web.dev/prefers-color-scheme.
Everything adjacent to this checkbox can be styled, leave it here in the DOM tree.
Dark Mode Sample
- On browsers that support
prefers-color-scheme
and report the user prefersdark
, just obey and don't give the user an override option, since they clearly state they like dark. - On browsers that support
prefers-color-scheme
and report the user preferslight
orno-preference
, offer the option to toggle dark mode manually. - On browsers that don't support
prefers-color-scheme
, offer the option to toggle dark mode manually.
<input id="dark-mode-checkbox" type="checkbox">
<label id="dark-mode-label" for="dark-mode-checkbox">Turn on dark mode</label>
<div class="wrapper">
<h1>Dark Mode Sample</h1>
<ul>
<li>
On browsers that support <code>prefers-color-scheme</code> and report the user prefers <code>dark</code>,
just obey and don't give the user an override option, since they clearly state they like dark.
</li>
<li>
On browsers that support <code>prefers-color-scheme</code> and report the user prefers <code>light</code>
or <code>no-preference</code>, offer the option to toggle dark mode manually.
</li>
<li>
On browsers that don't support <code>prefers-color-scheme</code>,
offer the option to toggle dark mode manually.
</li>
</ul>
</div>
إذا لم تكن الإيضاحات الموجودة في هذه الصفحة تُجيب على جميع أسئلتك، فلا تتردد في التواصل مع مستخدمي AMP الآخرين لمناقشة حالة الاستخدام المحددة لديك بالضبط.
الذهاب إلى Stack Overflow هل هي ميزة غير موضحة؟يشجع مشروع AMP مشاركتك ومساهمتك بشدة! ونأمل أن تكون مشاركًا دائمًا في مجتمعنا مفتوح المصدر، ولكننا نشجع أيضًا المساهمات التي تحدث لمرة واحدة في الأمور التي تتحمس لها.
تعديل العينة على GitHub