LeaVerou

style-observer: Detect Changes to CSS Properties

Style Observer is a JavaScript library that detects changes to CSS properties on connected elements, including custom properties and elements in Shadow DOM. Use it when application logic needs to respond to style changes without polling.

JavaScriptMITCSSLibraryFrontend
View on GitHub Compare
Stars
542
Forks
11
Stars, last 30 days
+1

Our take

Health score

30/100

How it is scored
Activity
31
Community
46
Issues
21
Pull requests
20

+1 stars in the last 30 days

Project history

Daily GitHub snapshots since Oct 7, 2026. History covers stars and forks; health signals are not tracked historically.

Selected snapshot

Stars

543

Forks

10

Change since Nov 16, 2026: +1 stars·0 forks

Overview

Style Observer lets JavaScript respond when a CSS property changes on an element. It addresses a gap in browser APIs by detecting changes to both custom and standard properties without polling, using browser mechanisms with workarounds for known bugs.

It is suited to frontend developers who need style changes to trigger application behavior. It is not a general-purpose observer for every CSS change: several properties and animation-driven changes are outside its scope.

Key Features

  • Observe custom properties and most standard CSS properties.
  • Track multiple properties across multiple elements with one observer.
  • Observe elements in Shadow DOM.
  • Receive records containing the target, property, new value, and old value.
  • Configure throttling so closely spaced changes are delivered together.
  • Avoid overwriting existing transitions.
  • Provides ESM-only code with no dependencies, according to the README.

Use Cases

  • Frontend developers can update JavaScript-driven behavior when a CSS custom property changes.
  • Component authors can observe style changes across multiple elements, including components using Shadow DOM.
  • Teams that coordinate CSS state and JavaScript behavior can react to property updates without periodic polling.
  • Developers can monitor discrete or animatable standard properties when browser support and the documented exclusions fit their needs.

Getting Started

Install from npm:

npm install style-observer

See the README for import options, usage, and compatibility details.

Considerations

  • Observation requires elements to be connected to a document. Changes made while disconnected are picked up once the elements are connected again.
  • The library cannot observe transition or animation properties, their constituent properties, or changes caused by CSS animations.
  • Moving a slotted element to a different slot is not detected.
  • If transition properties change after observation starts, call observer.updateTransition(targets) to regenerate the transition used for detection.
  • The README documents browser-version requirements that vary by property type. Check its compatibility table before relying on support across target browsers.
  • The project reports 542 stars and 11 forks, but those figures alone do not establish suitability for a particular production environment. Review its tests and compatibility guidance for your use case.

Found this useful?

Share it with someone who would like style-observer.