concept

registered-custom-property — CSS reference

Registration gives a custom property defined grammar and computed-value behavior. A registered length computes relative units before inheritance, unlike unregistered tokens. It also enables length interpolation. Registration via CSS or JavaScript does not create component-local scope.

Formal Syntax & Structure

css syntaxcss
@property --offset {syntax: "<length>"; inherits: false; initial-value: 0px;}

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS substitution lab</title><style>body {margin:0} .sample {height:12px;background:#006050}#parent {width:300px} .sample {width:40px;height:30px;margin-bottom:4px;color:white}@property --typed{syntax:"<length>";inherits:true;initial-value:10px} #parent{font-size:20px;--typed:2em;--raw:2em} .sample{font-size:10px} #a{width:var(--typed)} #b{width:var(--raw)}</style><body><div id="parent"><div id="a" class="sample">A</div><div id="b" class="sample">B</div></div></body></html>
CSS Reference