# @microsoft/load-themed-styles

> Loads themed styles.

Latest version **2.2.27** (published 2026-09-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @microsoft/load-themed-styles
pnpm add @microsoft/load-themed-styles
yarn add @microsoft/load-themed-styles
bun add @microsoft/load-themed-styles
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 2.2.27 |
| Published | 2026-09-14 |
| First published | 2016-08-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6497 |
| Maintainers | microsoft1es, microsoft-oss-releases, odspnpm |

## Links

- npm: https://www.npmjs.com/package/@microsoft/load-themed-styles
- Repository: https://github.com/microsoft/rushstack
- Homepage: https://github.com/microsoft/rushstack#readme
- Issues: https://github.com/microsoft/rushstack/issues
- npm.io page: https://npm.io/package/@microsoft/load-themed-styles

## Recent versions

- 2.2.27 (latest) — 2026-09-14
- 2.1.25 (pr5496) — 2026-01-12
- 2.2.26 — 2026-09-09
- 2.2.25 — 2026-08-21
- 2.2.24 — 2026-08-20
- 2.2.23 — 2026-08-14
- 2.2.22 — 2026-07-21
- 2.2.21 — 2026-07-17
- 2.2.20 — 2026-07-16
- 2.2.19 — 2026-06-13
- 2.2.18 — 2026-06-08
- 2.2.17 — 2026-04-20
- 2.2.16 — 2026-04-20
- 2.2.15 — 2026-04-18
- 2.2.14 — 2026-04-18
- … 710 more at https://npm.io/package/@microsoft/load-themed-styles/versions

## README

# @microsoft/load-themed-styles
[![npm version](https://badge.fury.io/js/%40microsoft%2Fload-themed-styles.svg)](https://badge.fury.io/js/%40microsoft%2Fload-themed-styles)

> Loads a string of style rules, but supports detokenizing theme constants built within it.

## Install

Install with [npm](https://www.npmjs.com/)

```
$ npm install --save @microsoft/load-themed-styles
```

## Usage

To load a given string of styles, you can do this in TypeScript or ES6:

```TypeScript
import { loadStyles } from '@microsoft/load-themed-styles';

loadStyles('body { background: red; }');
```

This will register any set of styles given. However, in the above example the color is hardcoded to red. To make this theme-able, replace it with the string token in this format:

```
"[theme:{variableName}, default:{defaultValue}]"
```

For example:

```js
loadStyles('body { background: "[theme:primaryBackgroundColor, default: blue]"');
```

When loading, the background will use the default value, blue. Providing your own theme values using the `loadTheme` function:

```js
import { loadStyles, loadTheme } from '@microsoft/load-themed-styles';

loadTheme({
  primaryBackgroundColor: "#EAEAEA"
});

loadStyles('body { background: "[theme:primaryBackgroundColor, default: #FFAAFA]"');
```

This will register #EAEAEA as the body's background color. If you call `loadTheme` again after styles have already been registered, it will replace the style elements with retokenized values.

## Security considerations

In order for `style` elements to be added to the DOM, a `nonce` attribute may need to be attached to the elements to adhere to a CSP requirements. To provide the value, you can specify the `nonce` value by defining a `CSPSettings` object on the page in global scope:

```js
window.CSPSettings = {
  nonce: 'nonce'
};
```

## Links

- [CHANGELOG.md](
  https://github.com/microsoft/rushstack/blob/main/libraries/load-themed-styles/CHANGELOG.md) - Find
  out what's new in the latest version

`@microsoft/load-themed-styles` is part of the [Rush Stack](https://rushstack.io/) family of projects.

---
_Source: https://npm.io/package/@microsoft/load-themed-styles · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
