Μετάβαση στο κύριο περιεχόμενο
← 🎨 CSS as a design system·Ενότητα B5 · Μάθημα 10
ΕργασίαAdd color-scheme: light dark to :root. Body has background #fff, color #111 in light; dark overrides via prefers-color-scheme. Form has an input and a select — they pick up native dark/light styling automatically.

χρωματικός συνδυασμός + χρώματα γραμμής κύλισης

60 XP5 min
Θεωρία

What color-scheme actually does

:root { color-scheme: light dark; }

Tells the browser "this page supports both modes." Browser then themes:

  • Scrollbars — light or dark variant matching the page.
  • Form controls — <input>, <select>, <button> get dark or light native styling.
  • `<dialog>` backdrop — different default backdrop color.
  • Spell-check underlines — different colors for visibility.

Without color-scheme: light dark, you'd ship a dark page with bright white scrollbars and bright form controls — looks broken.

Per-element

.modal { color-scheme: dark; }

Force a region into one scheme regardless of the page setting. Useful for a modal that ignores OS preference.

Browser limitations

  • Custom-styled scrollbars override color-scheme.
  • Some Linux distros (older Firefox) don't honor it for native widgets.

In 2026: treat color-scheme: light dark on :root as a free win. Add it to every project.

🔒

Εγγράψου για να αρχίσεις να προγραμματίζεις

Η θεωρία είναι ανοιχτή για όλους. Ο επεξεργαστής, η ζωντανή προεπισκόπηση και ο έλεγχος ξεκλειδώνουν με 7-ήμερη δωρεάν δοκιμή — απαιτείται κάρτα.

Εγγραφή — δωρεάν δοκιμή →

Τα πρώτα 10 μαθήματα κάθε διαδρομής είναι δωρεάν. Δεν χρειάζεται κάρτα.

← ΠροηγούμενοΕπόμενο μάθημα →

Μια συμβουλή Python ή web την ημέρα — με email

Σύντομο, γραμμένο στο χέρι, χωρίς spam. Διαγραφή με ένα κλικ.