Skip to main content

  • Foundations
    • Border radius
    • Breakpoints
    • Colours
    • Colour scheme
    • Elevation
    • Focus and outline
    • Sizing and spacing
    • Layout
    • Motion
    • Typography
    • Z-index
  • Elements
    • Buttons
    • Code
    • Icons
    • Figure and caption
    • Forms
    • Links
    • Lists
    • Media
    • Tables
  • Components
    • Accordion
    • Alerts
    • Avatar
    • Blockquote
    • Breadcrumbs
    • Card
    • Chiplets
    • Details and summary
    • Dialog
    • Empty state
    • Stats
    • Global footer
    • Horizontal rule
    • Kanban
    • Key-value list
    • Meter
    • Objects
    • Pagination
    • Polka background
    • Post-it note
    • Progress
    • Speech bubbles
    • Status dot
    • Skeleton
    • Skip link
    • Spinner
    • Toggles
    • Tooltip
    • Webmentions
  • Patterns
    • Article header
    • Author card
    • App list and app sheet
    • Error page
    • Related posts
    • Search results
    • Utilities

John Peart

  • Search
  • Menu
John Peart

Colour scheme

How light and dark modes are handled via light-dark() and prefers-color-scheme.

The site declares color-scheme: light dark and uses the light-dark() function to pick values based on the user's OS preference. There is no in-page toggle — the scheme follows the system.

Authoring rule: never hard-code a colour in a component. Either use a semantic token (--color, --background, --secondary-background) or, if you need a one-off, define it with light-dark().

:root {
  color-scheme: light dark;
  --background: light-dark(var(--white), var(--black));
  --color:      light-dark(var(--black), var(--white));
}

.my-component {
  background: light-dark(hsl(198, 100%, 92%), hsl(198, 100%, 15%));
}

See the colours page for the full palette with both light and dark values.

A line drawing of John Peart

John Peart

www.johnpe.art

Mastodon logo

Mastodon

BlueSky logo

Bluesky

LinkedIn logo

LinkedIn

Github logo

GitHub