Acrylic

A frosted glass texture that blurs, tints and adds noise to what is behind it.

Wrap your content with ax-acrylic and it gets a texture of frosted glass: the background behind it is blurred, tinted and covered with a little noise. It needs something behind it to blur, so place it over an image, a video or a colorful page.

Acrylic runs on Surface, so the texture follows the shape of the element. It is also a layer of ax-surface. In browsers without backdrop-filter, the texture falls back to a plain color.

Installation

shell
npm install @ax-design/acrylic

and import it:

js
import { register } from '@ax-design/acrylic';
register();

If you don't use a bundler, load the script instead:

html
<script src="https://unpkg.com/@ax-design/acrylic/build/main.js"></script>
<script>AxAcrylic.register();</script>
Acrylic

Glass

The tint is a color on top of the blurred background. A lower opacity shows more of the background; a higher one makes the text easier to read.

The blur radius sets how deep the blur is.

Try it

#000000
0.6
20 px
html
<ax-acrylic class="glass">
  Acrylic
</ax-acrylic>
css
.glass {
  --acrylic-tint-color: rgb(0, 0, 0);
  --acrylic-tint-opacity: 0.6;
  --acrylic-blur: 20px;
}
Colors

Saturation and brightness

The blurred background is made more saturated and a bit darker before the tint is applied. This is what keeps the colors of the background alive behind the glass.

Lower the saturation to get a gray glass, raise the brightness for a light one.

Try it

200 %
95 %
css
.glass {
  --acrylic-saturate: 200%;
  --acrylic-brightness: 95%;
}
Noise

Noise

A layer of fine noise sits on top of the tint, like the grain of real acrylic. It is very faint by default. Raise it to see it.

In a browser without backdrop-filter, the noise is removed and the glass becomes the plain fallback color, always fully opaque so text stays readable.

Try it

0.03
#1E1E1E
css
.glass {
  --acrylic-noise-opacity: 0.03;
  --acrylic-fallback-color: rgb(30, 30, 30);
}
Shape

Shape

The glass follows the Surface shape properties, like --ax-radius and --ax-corner-shape. The blur is cut to the shape, whatever it is.

Try it

30 %
css
ax-acrylic {
  --ax-radius: 30%;
  --ax-corner-shape: round;
}
Press me

With Surface

Acrylic is also a layer of ax-surface, so you can put it together with other layers on the same shape. Here acrylic and reveal highlight share a surface that tilts when you press it.

Move your pointer over the glass and press it.

Try it

3 px
16 px
js
import { register } from '@ax-design/surface';
import { registerAcrylicLayer } from '@ax-design/acrylic';
import { registerRevealLayer } from '@ax-design/reveal-highlight';

registerAcrylicLayer();
registerRevealLayer();
register();
html
<ax-surface class="glass" layers="acrylic reveal">Press me</ax-surface>
css
.glass {
  --ax-radius: 16px;
  --ax-tilt-mode: absolute;
  --ax-tilt-depth: 3px;
}

Reference

--acrylic-tint-color property

<color>, default black

The base color of the texture when backdrop-filter is available.

--acrylic-tint-opacity property

<number>, default 0.6

The opacity of the tint when backdrop-filter is available.

--acrylic-fallback-color property

<color>, default black

The color of the texture when backdrop-filter is not available. It is always opaque, for readability; there is no fallback opacity.

--acrylic-noise-opacity property

<number>, default 0.03

The opacity of the noise layer. The noise is removed in fallback mode.

--acrylic-blur property

<length>, default 20px

The radius of the blur. A greater radius blurs deeper.

--acrylic-saturate property

<percentage>, default 200%

The saturation of the blurred background.

--acrylic-brightness property

<percentage>, default 95%

The brightness of the blurred background.

--ax-* property

Surface properties

ax-acrylic takes the shape and tilt properties of Surface, for example --ax-radius and --ax-corner-shape.

registerAcrylicLayer() method

() => void

Registers the acrylic layer for ax-surface. register() calls it too.