<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/passing-your-css-theme-to-canvas-aaron-gustafson-nwolh2xgl" -->

---
title: Passing Your CSS Theme to `canvas` :: Aaron Gustafson
description: A practical guide to syncing CSS custom property theme colors (light/dark mode) with HTML canvas rendering. The technique uses `window.getComputedStyle()` to...
canonical: https://daily.dev/posts/passing-your-css-theme-to-canvas-aaron-gustafson-nwolh2xgl
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Passing Your CSS Theme to `canvas` :: Aaron Gustafson | daily.dev
og:description: A practical guide to syncing CSS custom property theme colors (light/dark mode) with HTML canvas rendering. The technique uses `window.getComputedStyle()` to...
og:url: https://daily.dev/posts/passing-your-css-theme-to-canvas-aaron-gustafson-nwolh2xgl
og:image: https://api.daily.dev/og/posts/NwOlH2XGL.png
og:image:alt: Passing Your CSS Theme to `canvas` :: Aaron Gustafson
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Passing Your CSS Theme to `canvas` :: Aaron Gustafson

**[Aaron Gustafson](https://daily.dev/sources/aaron_gustafson)** · 3 min read · 0 upvotes · 0 comments

## Summary

A practical guide to syncing CSS custom property theme colors (light/dark mode) with HTML canvas rendering. The technique uses `window.getComputedStyle()` to read CSS custom properties into a JavaScript theme object, then attaches a `MediaQueryList` event listener to `prefers-color-scheme` so canvas colors automatically update whenever the user switches themes.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.aaron-gustafson.com/notebook/passing-your-css-theme-to-canvas>

## Similar posts on daily.dev

- [A few ways of specifying per-theme colours in only CSS — Chris Morgan](https://daily.dev/posts/a-few-ways-of-specifying-per-theme-colours-in-only-css-chris-morgan-yeihwzack) · Lobsters · 0 upvotes · 0 comments
- [Color Themes with Baseline CSS Features](https://daily.dev/posts/color-themes-with-baseline-css-features-hqncxlcye) · OddBird · 22 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#css](https://daily.dev/tags/css)

[View this post on daily.dev](https://daily.dev/posts/passing-your-css-theme-to-canvas-aaron-gustafson-nwolh2xgl)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Passing Your CSS Theme to `canvas` :: Aaron Gustafson","url":"https://daily.dev/posts/passing-your-css-theme-to-canvas-aaron-gustafson-nwolh2xgl","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/passing-your-css-theme-to-canvas-aaron-gustafson-nwolh2xgl"},"datePublished":"2026-07-05T07:21:34.143Z","dateModified":"2026-07-05T07:22:04.771Z","description":"A practical guide to syncing CSS custom property theme colors (light/dark mode) with HTML canvas rendering. The technique uses `window.getComputedStyle()` to...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a1d4e79542c098e276421498b172c75f?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a1d4e79542c098e276421498b172c75f?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Aaron Gustafson","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Aaron Gustafson","logo":"https://media.daily.dev/image/upload/s--EbaHv8mu--/f_auto,q_auto/v1783236087/logos/aaron_gustafson","url":"https://daily.dev/sources/aaron_gustafson"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/passing-your-css-theme-to-canvas-aaron-gustafson-nwolh2xgl","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,css","timeRequired":"PT3M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Aaron Gustafson","item":"https://daily.dev/sources/aaron_gustafson"},{"@type":"ListItem","position":3,"name":"Passing Your CSS Theme to `canvas` :: Aaron Gustafson"}]}
```

