at-rule

@function — CSS reference

Defines a reusable CSS value function with a dashed name, optional typed parameters and a result declaration. It returns a CSS value rather than injecting style rules. The invocation uses the current argument; the first width provides a fallback in engines rejecting the function syntax.

Formal Syntax & Structure

css syntaxcss
@function --double(--x <length>) returns <length> { result: calc(var(--x) * 2); }

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>@function</title><style>body{margin:8px;font:16px/20px sans-serif;color:black;background:white}@function --double(--x <length>) returns <length> { result:calc(var(--x)*2); } #a{width:20px;width:--double(30px);height:20px;background:blue}</style><body><p id="a">Example text</p></body></html>
CSS Reference