Skip to main content

Devbit

Consider the user's preference for dark or light system colors

The theme should take into account whether the user has selected dark or light colors in the OS settings.
/* Default theme */
:root {
  --Background-Color: #fff;
  --Text-Color: #000;
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
  :root {
    --Background-Color: #000;
    --Text-Color: #fff;
  }
}

Issue:

The theme should take into account whether the user has selected dark or light colors in the OS settings.

Solution:

Use the prefers-color-scheme CSS media feature. See also: documentation at developer.mozilla.org.

Ein Mann mit kurzem grauem Bart und rasiertem Kopf trägt ein schwarzes T-Shirt mit der Aufschrift „DRPL“ und eine schwarze Kapuzenjacke. Er blickt freundlich in die Kamera. Im Hintergrund sind mehrere Bildschirme und ein Schreibtisch mit Technik-Equipment zu sehen.

Holger Weischenberg

Frontend Developer

Ihre Drupal-Website zukunftssicher machen

Wir prüfen Ihr System und zeigen, was Sie für AI, Wartung und Upgrades brauchen.