--- title: '初始值' slug: Web/CSS/@property/initial-value tags: - CSS - Reference - Web - Property - Houdini ---
{{CSSRef}}{{SeeCompatTable}}

initial-value CSS描述符在使用{{cssxref("@property")}} {{cssxref("at-rule")}}的时候是必需的,除非syntax属性接受了任何有效的token流。 它为属性设置初始值。

被选定为initial-value的参数,依照syntax描述符定义,必须可以正确地解析。 因此,如果syntax描述符为<color>,那么初始值必须是一个有效的{{cssxref("color")}}值。

语法

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

@property --property-name {
  syntax: '<color>';
  inherits: true;
  initial-value: #c0ffee;
}

取值

对于设定的syntax,具有正确值的字符串。

标准定义

{{cssinfo}}

标准语法

{{csssyntax}}

实例

--my-color {{cssxref('--*', '自定义属性')}}添加颜色值类型检测、设置默认值并且设置属性值不允许被继承。

使用 CSS {{cssxref('@property')}} 规则:

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

使用 JavaScript中的 {{domxref('CSS.registerProperty')}}函数:

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

标准语法

{{csssyntax}}

规范

规范 状态 提案
{{SpecName('CSS Properties and Values API', '#at-property-rule')}} {{Spec2('CSS Properties and Values API')}} 初始定义.

浏览器兼容性

{{Compat("css.at-rules.property")}}

另见