@function

An experimental at-rule that lets you define your own custom CSS functions with logic and return values, very similar to functions in programming languages like JavaScript.

This is an experimental technology. The syntax and behavior are still subject to change.

/* Usage Example */
@function --get-vibrant-bg(--color-base) {
  /* Experimental: logic to generate a color variant */
  result: color-mix(in srgb, var(--color-base), #fff 20%);
}
.card{
  background: --get-vibrant-bg(#3b82f6);
}

This comparison shows how @function works in a real project. View snippet →

Limited availability Since 2020 67% global usage

This feature is not Baseline because it does not work in some of the most widely-used browsers.

139+
139+
Kinsta

Your first month is free

Managed WordPress hosting for faster sites.

Learn more

New CSS drops.

Join 600+ readers who've survived clearfix hacks.

ESC