GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

CSS properties and values API

The CSS properties and values API module defines a method for registering new CSS properties, defining the property's data type, inheritance behavior, and, optionally, an initial value. This API expands on CSS custom properties for cascading variables module, which allows authors to define custom properties in CSS using two dash syntax (--).

The **CSS properties and values API** module defines a method for registering new CSS properties, defining the property's data type, inheritance behavior, and, optionally, an initial value.
This API expands on [CSS custom properties for cascading variables](/docs/Web/CSS/Guides/Cascading_variables) module, which allows authors to define custom properties in CSS using [two dash syntax (`--`)](/docs/Web/CSS/Reference/Properties/--*).
The CSS properties and values API is part of the [CSS Houdini](/docs/Web/API/Houdini_APIs) umbrella of APIs.

Custom properties let you reuse values across a project to simplify complex or repetitive stylesheets.
Basic custom properties are defined in the [CSS custom properties for cascading variables](/docs/Web/CSS/Guides/Cascading_variables) module.
The CSS properties and values API expands on that module, enabling adding metadata to custom properties using CSS with the @property at-rule or, alternatively, using JavaScript's CSS.registerProperty method.

Whether registered with CSS or JavaScript, setting metadata on custom properties provides for an expected data type that the browser can use depending on the context, defines an initial value, and lets you control inheritance.

CSS properties and values API custom property registration is more robust than the more basic CSS cascading variable custom property declaration, especially when it comes to transitioning and animating values as browsers can interpolate between custom values of this type, whereas properties that use [two dash syntax (`--`)](/docs/Web/CSS/Reference/Properties/--*) behave more like a string substitution.

## Properties and values API in action

To see how custom properties and values can be used via API, hover over the box below.

```js hidden
CSS.registerProperty({
name: "--stop-color",
syntax: "<color>",
inherits: false,
initialValue: "cornflowerblue",
});
```

```css hidden
.box {
padding: 1rem;
width: 90%;
height: 4rem;
font-family: sans-serif;
font-size: large;
color: white;
border-radius: 0.5rem;
}

.box {
background: linear-gradient(to right, var(--stop-color), lavenderblush);
transition: --stop-color 2s;
}

.box:hover {
--stop-color: aquamarine;
}
```

```html hidden
<div class="box"><p>Linear gradient with transition</p></div>
```

600

The box has a [background](/docs/Web/CSS/Reference/Properties/background) consisting of a [linear gradient](/docs/Web/CSS/Reference/Values/gradient/linear-gradient) from `--stop-color` (the custom property) to [`lavenderblush`](/docs/Web/CSS/Reference/Values/named-color).
The value of `--stop-color` is set to `cornflowerblue` at first, but when you hover over the box, `--stop-color` [transitions](/docs/Web/CSS/Reference/Properties/transition) to `aquamarine` over two seconds (`linear-gradient(to right, aquamarine, lavenderblush)`).

## Reference

### At-rules and descriptors

- @property
- [syntax](/docs/Web/CSS/Reference/At-rules/@property#descriptors) descriptor
- [`+` and `#`](/docs/Web/CSS/Reference/At-rules/@property#descriptors) multipliers
- [`|`](/docs/Web/CSS/Reference/At-rules/@property#descriptors) combinator
- [inherits](/docs/Web/CSS/Reference/At-rules/@property#descriptors) descriptor
- [initial-value](/docs/Web/CSS/Reference/At-rules/@property#descriptors) descriptor

### Interfaces and APIs

- CSSPropertyRule
- CSS.registerProperty()

## Guides

- [Registering CSS custom properties](/docs/Web/CSS/Guides/Properties_and_values_API/Registering_properties)
- : Covers how to register CSS custom properties with the `@property` at-rule and explains the benefits of doing so.
- [Using the CSS properties and values API](/docs/Web/API/CSS_Properties_and_Values_API/guide)
- : Explains how to register custom properties in CSS and JavaScript, with hints on handling undefined and invalid values, fallbacks, and inheritance.
- [CSS Houdini](/docs/Web/CSS/Guides/Properties_and_values_API/Houdini)
- : Reference guide to Houdini resources including the CSS modules, API guides, and external resources.
- [Houdini APIs](/docs/Web/API/Houdini_APIs)
- : Explains what CSS Houdini is and its advantages, along with a list of available APIs and their statuses.

## Related concepts

- var
- [CSSRule](/docs/Web/API/CSSRule)
- [CSSStyleValue](/docs/Web/API/CSSStyleValue)
- [CSS scoping](/docs/Web/CSS/Guides/Scoping)
- [Using shadow DOM](/docs/Web/API/Web_components/Using_shadow_DOM)
- [CSS Typed Object Model API](/docs/Web/API/CSS_Typed_OM_API)
- [CSS Painting API](/docs/Web/API/CSS_Painting_API)
- [Worklet](/docs/Web/API/Worklet)

## Specifications

## See also

- [CSS cascading and inheritance](/docs/Web/CSS/Guides/Cascade)
- [CSS scoping](/docs/Web/CSS/Guides/Scoping) module
- [Using shadow DOM](/docs/Web/API/Web_components/Using_shadow_DOM)
- [CSS Painting API](/docs/Web/API/CSS_Painting_API) module
- [Worklet](/docs/Web/API/Worklet) interface
- [CSS `env()`](/docs/Web/CSS/Reference/Values/env)
- [CSS Typed Object Model](/docs/Web/API/CSS_Typed_OM_API)

source: MDN Web Docs mirror · page

Cite this

"CSS properties and values API". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Properties_and_values_API

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·