Style Observer: Run JavaScript When CSS Properties Change

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Style Observer: Run JavaScript When CSS Properties Change

Summary

Style Observer is a robust, production-ready JavaScript library designed to detect and respond to changes in any CSS property. It allows developers to run custom JavaScript code when a CSS property changes, offering a powerful way to create dynamic and reactive web interfaces. The library handles browser inconsistencies and provides a lightweight, dependency-free solution for observing styles.

Repository Information

Analyzed by OSRepos on January 10, 2026

Topics

Click on any tag to explore related repositories

Use at your own risk

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.

Introduction

Style Observer is a robust, production-ready JavaScript library by Lea Verou and Dmitry Sharabin, designed to detect and respond to changes in any CSS property. It provides a powerful mechanism to run JavaScript code whenever a CSS property on an element changes, offering a solution for dynamic web interfaces. The library is lightweight, dependency-free, and meticulously tested to ensure compatibility across various browsers, even detecting and working around known browser bugs.

Key features include:

  • Observe changes to custom properties
  • Observe changes to standard properties (except transition and animation)
  • Observe changes on any element (including those in Shadow DOM)
  • Lightweight, ESM-only code, with no dependencies
  • 200+ unit tests you can run in your browser of choice
  • Throttling per element
  • Does not overwrite existing transitions

Installation

The quickest way to get started is by including Style Observer directly from a CDN:

import StyleObserver from "https://observe.style/index.js";

For more controlled environments, you can install it via npm:

npm install style-observer

Then, if you use a bundler like Rollup or Webpack:

import StyleObserver from "style-observer";

And if you don’t use a bundler:

import StyleObserver from "node_modules/style-observer/dist/index.js";

Examples

Style Observer's API is similar to other browser observers. You can create an observer instance and then observe elements and properties.

Observing a single property on a single element:

const observer = new StyleObserver(records => console.log(records));
observer.observe(document.querySelector("#my-element"), "--my-custom-property");

You can also observe multiple properties on multiple elements:

const observer = new StyleObserver(records => console.log(records));
const properties = ["color", "--my-custom-property"];
const targets = document.querySelectorAll(".my-element");
observer.observe(targets, properties);

Alternatively, you can provide targets and properties directly when creating the observer:

import StyleObserver from "style-observer";

const observer = new StyleObserver(callback, {
	targets: document.querySelectorAll(".my-element"),
	properties: ["color", "--my-custom-property"]
});

Each record passed to the callback contains target, property, value, and oldValue, providing detailed information about the change.

Why Use Style Observer?

Style Observer stands out as a sophisticated solution for monitoring CSS changes, addressing a long-standing challenge in web development. Unlike earlier attempts that relied on polling, this library leverages modern browser capabilities and innovative techniques to provide a highly efficient and accurate observation mechanism. It is built from scratch to extend browser support and robustness, ensuring reliable performance across different environments.

Key advantages include its ability to observe both custom and standard CSS properties, comprehensive browser compatibility (as detailed in its documentation), and a lightweight footprint with no external dependencies. The project boasts over 200 unit tests, highlighting its commitment to stability and bug detection. For developers needing precise control over UI reactions to style changes, Style Observer offers a production-ready and thoroughly vetted tool.

Links

Related repositories

Similar repositories that may be relevant next.

theme.park: Custom Themes for Your Self-Hosted Applications

theme.park: Custom Themes for Your Self-Hosted Applications

April 2, 2026

theme.park offers a vast collection of custom themes and skins for over 50 self-hosted applications. Easily personalize the look and feel of your favorite services, including popular media servers and download clients, with a unified and visually appealing interface. Enhance your user experience and bring dark mode or other styles to your entire self-hosted ecosystem.

csscustom-cssdark-mode
Beer CSS: Build Material Design Interfaces with Ease

Beer CSS: Build Material Design Interfaces with Ease

March 29, 2026

Beer CSS is a lightweight CSS framework designed to help developers build Material Design 3 interfaces quickly and efficiently. It emphasizes semantic HTML and offers a streamlined approach, making it easy to integrate into any project without complex build steps or dependencies.

cssmaterial-designdesign-system
Galaxy: The Largest Open-Source UI Library for Web Development

Galaxy: The Largest Open-Source UI Library for Web Development

March 9, 2026

Galaxy is an extensive open-source UI library, offering over 3000 unique, community-made UI elements. Curated from Uiverse.io, these components are freely available under the MIT License and can be implemented using CSS or Tailwind. It's a valuable resource for web developers seeking diverse and ready-to-use UI components.

communitycsstailwind
Nerd Fonts: Enhance Your Terminal with Iconic Glyphs and Patched Fonts

Nerd Fonts: Enhance Your Terminal with Iconic Glyphs and Patched Fonts

March 3, 2026

Nerd Fonts is an ambitious project that patches popular developer-oriented fonts with a vast collection of iconic glyphs, including sets like Font Awesome, Material Design Icons, and Octicons. This allows developers to enjoy a richer visual experience in their terminals and code editors, making it easier to display various symbols and icons. With over 67 pre-patched font families and a powerful font patcher, it offers extensive customization for any coding environment.

fontsicon-fontsdeveloper-tools

Source repository

Open the original repository on GitHub.

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️