docs.rodeo

MDN Web Docs mirror

initial-value

{{CSSRef}} 

The initial-value descriptor of the {{cssxref("@property")}}  at-rule specifies the initial value for the registered CSS custom property. It is a required descriptor unless the {{cssxref("@property/syntax", "syntax")}}  descriptor value is the universal syntax (*). If required but missing or invalid, the entire @property rule is invalid and ignored.

Syntax

/* Set initial color value */
initial-value: rebeccapurple;

/* Set initial length value */
initial-value: 2rem;

Values

A value that matches the type specified in the {{cssxref("@property/syntax", "syntax")}}  descriptor. For example, if syntax is <color>, then the initial-value must be a valid {{cssxref("color")}}  value.

Formal definition

{{cssinfo}} 

Formal syntax

{{csssyntax}} 

Examples

Setting an initial value for a custom property

This example shows how to define a custom property --my-color with an initial color value of #c0ffee. This initial value will be used when the property is not inherited (inherits: false) and no other value is set on the element.

@property --my-color {
  syntax: "<color>";
  inherits: false;
  initial-value: #c0ffee;
}

Using JavaScript {{domxref('CSS.registerProperty_static', 'CSS.registerProperty()')}} :

window.CSS.registerProperty({
  name: "--my-color",
  syntax: "<color>",
  inherits: false,
  initialValue: "#c0ffee",
});

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN