Lesson 20 / الدرس 20
Dark mode / الوضع الداكن
One prefix in Tailwind, one attribute in Bootstrap, and a set of design decisions that neither of them makes for you — because a dark theme is not a light one inverted.
بادئة واحدة في Tailwind وسمة واحدة في Bootstrap، ومجموعة قرارات تصميم لا يتخذها أي منهما عنك — لأن السمة الداكنة ليست الفاتحة مقلوبة.
TAILWIND — a prefix, like a breakpoint
<div class="bg-white text-slate-900 dark:bg-slate-900 dark:text-slate-100">
BOOTSTRAP — an attribute on the html element
<html data-bs-theme="dark">
Every component follows automatically.
Four things that do not simply invert
-
Shadows stop working. A shadow is the absence of light, and there is little left to remove on a dark surface. Lift a panel with a lighter background and a visible border instead. الظلال تكفّ عن العمل. فالظل غياب الضوء، ولا يبقى الكثير لإزالته على سطح داكن. ارفع اللوحة بخلفية أفتح وحد مرئي بدلًا من ذلك.
-
Pure black and pure white are both wrong. White text on pure black vibrates and is tiring to read; near-black and near-white are what every good dark theme uses. الأسود الخالص والأبيض الخالص كلاهما خطأ. فالنص الأبيض على أسود خالص يهتز ويرهق القراءة؛ وشبه الأسود وشبه الأبيض هما ما تستخدمه كل سمة داكنة جيدة.
-
Saturated colours get brighter. A blue that reads calm on white glares on near-black. Dark themes generally want the same hue, lighter and less saturated. الألوان المشبعة تزداد سطوعًا. فالأزرق الهادئ على الأبيض يبهر على شبه الأسود. والسمات الداكنة تريد عمومًا الدرجة نفسها أفتح وأقل تشبعًا.
-
Images need attention. A logo that is black on transparent disappears. So does a screenshot of a white interface, which glows like a torch. الصور تحتاج انتباهًا. فالشعار الأسود على شفاف يختفي. وكذلك لقطة شاشة لواجهة بيضاء، فهي تتوهج كمصباح.
Following the reader, and letting them choose
The operating system already knows which the reader prefers, and CSS can ask: prefers-color-scheme, from the CSS course. Both frameworks use it by default, so a page can respect the reader's choice with no toggle and no JavaScript at all. Adding a toggle is a real feature — it needs somewhere to remember the choice — and it is worth doing only after the automatic version works.
prefers-color-scheme من دورة CSS. ويستخدمه الإطاران افتراضيًا، فتستطيع صفحة احترام اختيار القارئ بلا مبدّل وبلا JavaScript إطلاقًا. وإضافة مبدّل ميزة حقيقية — تحتاج موضعًا تتذكر فيه الاختيار — وتستحق الفعل بعد أن تعمل الصيغة التلقائية فقط.text-slate-400 مريحة على bg-slate-900 وترسب بشدة على الأبيض؛ والرمادي الخافت الذي ينفع في الوضع الفاتح يختفي غالبًا في الداكن. وهذا الموقع يختبر كل زوج ألوان في السمتين لهذا السبب بالضبط، ووجد إخفاقات حقيقية بذلك.
A practical way to keep this manageable in Tailwind, where you would otherwise write dark: on hundreds of elements: define your colours as semantic names in the theme — surface, text, muted, border — and let those switch. Then a card is bg-surface text-text in both modes and the theme decides what those mean. That is how this site is built, and it is why its dark mode is one block of tokens rather than a thousand prefixes.
dark: على مئات العناصر: عرّف ألوانك بأسماء دلالية في السمة — سطح ونص وخافت وحد — ودع تلك تتبدل. فتصير البطاقة bg-surface text-text في الوضعين وتقرر السمة ما تعنيه. وهكذا بُني هذا الموقع، ولهذا كان وضعه الداكن كتلة رموز واحدة لا ألف بادئة.prefers-color-scheme استعلام وسائط كأي آخر. ولأدوات المتصفح أيضًا تحكم لمحاكاة كل واحد، وهو أسرع من تغيير إعداد النظام كل مرة.Try it live / جرّب بنفسك
Check yourself / اختبر نفسك
1. Why do shadows stop working in dark mode?
Lift a panel with a lighter background and a visible border instead — which is what the demonstration in this lesson does.
2. Why is white text on pure black a poor choice?
Too much contrast is its own problem. Near-black and near-white is what every good dark theme uses.
3. Does checking contrast in light mode tell you anything about dark mode?
Every pair has to be checked in both. This site tests exactly that, and the test found real failures.
Score / النتيجة: 0 / 3
Your task / مهمتك
Give one page a dark mode in both frameworks, following the reader's system preference with no toggle. Then audit it: list every text-on-background pair and measure its contrast in both themes, and find at least one thing that needed more than inverting — a shadow, an image, or a saturated colour. Say what you did about it.
أعطِ صفحة واحدة وضعًا داكنًا في الإطارين، متبعًا تفضيل نظام القارئ بلا مبدّل. ثم دقّقها: عدّد كل زوج نص-على-خلفية وقِس تباينه في السمتين، واعثر على شيء واحد على الأقل احتاج أكثر من القلب — ظل أو صورة أو لون مشبع. وقل ما فعلته بشأنه.
- Dark mode following the system preference, in both وضع داكن يتبع تفضيل النظام، في الاثنين
- Every pair measured in BOTH themes كل زوج مقيس في السمتين
- At least one thing that needed more than inverting شيء واحد على الأقل احتاج أكثر من القلب
- No pure black and no pure white لا أسود خالص ولا أبيض خالص