⚠️ Your browser doesn't currently support CSS custom functions.

Responsive narrow-wide function

This example features a custom CSS function called --narrow-wide(), which takes two parameters — a value to apply to a narrow layout and a value to apply to a wide layout.

Usage

The custom function is very useful — you can use it as the value of just about any property where you want to provide a choice of values — one for a narrow layout and one for a wide layout.

Defining the function

The --narrow-wide() function is built using two CSS custom properties and a media query to detect whether the viewport is narrower or wider than the provided breakpoint, and return one value or the other as appropriate.