Elevation

A shadow that tells how high an element floats above the page, and follows its shape.

Wrap the content that should float above the page in ax-elevation and set --elevation-depth. The shadow has two layers that grow with the depth: a large, soft one and a small, darker one under the element.

Elevation runs on Surface, so the shadow follows the shape of the element, not only rectangles. It is also a layer of ax-surface. The shadows need room around the element and a light background to show.

Installation

shell
npm install @ax-design/elevation

and import it:

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

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

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

Depth

The depth is a number: the higher it is, the larger and softer the shadow. 0 draws no shadow.

The property is inherited, so you can set it on a container and every ax-elevation inside takes it.

Try it

16
html
<ax-elevation class="card">
  Depth
</ax-elevation>
css
.card {
  --elevation-depth: 16;
}
Shape

Shape

The shadow follows the Surface shape properties. A rounded card gets a rounded shadow, and a bevel or scoop corner gets a shadow with the same corner.

The shadow is cut out under the shape, so a translucent card does not look darker. Add the clip attribute to cut the content to the shape too, background included.

Try it

25 %
8 px
html
<ax-elevation clip>
  <div class="card-body">Shape</div>
</ax-elevation>
css
ax-elevation {
  --elevation-depth: 16;
  --ax-radius: 25%;
  --ax-corner-shape: scoop;
  --ax-corner-shoulder-radius: 8px;
}
ABC

Inherited depth

Because the depth is inherited, one value on a container sets all cards inside. A card can still set its own depth.

Here the first two cards take the depth of the container, the last one sets its own.

Try it

12
html
<div class="row">
  <ax-elevation class="card">A</ax-elevation>
  <ax-elevation class="card">B</ax-elevation>
  <ax-elevation class="card own">C</ax-elevation>
</div>
css
.row {
  --elevation-depth: 12;
}

.own {
  --elevation-depth: 48;
}
Press me

With Surface

Elevation is also a layer of ax-surface. List it first, so the other layers paint on top of it.

This surface has a shadow, a fill and a reveal light on one shape, and sinks when you press it.

Try it

20
js
import { register } from '@ax-design/surface';
import { registerElevationLayer } from '@ax-design/elevation';
import { registerRevealLayer } from '@ax-design/reveal-highlight';

registerElevationLayer();
registerRevealLayer();
register();
html
<ax-surface class="card" layers="elevation fill reveal">...</ax-surface>
css
.card {
  --elevation-depth: 20;
  --ax-tilt-mode: absolute;
}

Reference

--elevation-depth property

<number>, default 0

How high the element floats. The shadow is a large, soft layer and a small, darker one that grow with the depth. 0 draws no shadow. Inherited.

--ax-* property

Surface properties

ax-elevation takes the shape properties of Surface, for example --ax-radius, --ax-corner-shape and --ax-corner-shoulder-radius.

registerElevationLayer() method

() => void

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