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
npm install @ax-design/acrylicand import it:
import { register } from '@ax-design/acrylic';
register();If you don't use a bundler, load the script instead:
<script src="https://unpkg.com/@ax-design/acrylic/build/main.js"></script>
<script>AxAcrylic.register();</script>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
<ax-acrylic class="glass">
Acrylic
</ax-acrylic>.glass {
--acrylic-tint-color: rgb(0, 0, 0);
--acrylic-tint-opacity: 0.6;
--acrylic-blur: 20px;
}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
.glass {
--acrylic-saturate: 200%;
--acrylic-brightness: 95%;
}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
.glass {
--acrylic-noise-opacity: 0.03;
--acrylic-fallback-color: rgb(30, 30, 30);
}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
ax-acrylic {
--ax-radius: 30%;
--ax-corner-shape: round;
}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
import { register } from '@ax-design/surface';
import { registerAcrylicLayer } from '@ax-design/acrylic';
import { registerRevealLayer } from '@ax-design/reveal-highlight';
registerAcrylicLayer();
registerRevealLayer();
register();<ax-surface class="glass" layers="acrylic reveal">Press me</ax-surface>.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.