Skip to content

Advanced Shadows

A tilting element should have a shadow to look more believable, so the <HoverTilt /> component automatically applies a dynamic shadow to the element when the shadow prop is enabled.

However, there are two cases where you might feel this is not the solution for you;

  1. You want a static shadow even while not interacting.
    See Shadows while not active for more details.
  2. You need a custom shadow effect for your use case.
    See Custom dynamic shadows for more details.

The built-in shadow prop produces a dynamic shadow driven by --hover-tilt-x and --hover-tilt-y. For cards that need depth even when idle there’s two approaches;

This is the simplest approach. Just add a static shadow to the slot contents.

When the content shadow is subtle, it may be fine (or even desirable) to let the built-in dynamic shadow stack on top of it.

ShadowCard.svelte
<HoverTilt class="shadow-card" shadow shadowBlur={30}>
<div class="card">
Content always has a subtle shadow
</div>
</HoverTilt>
<style>
.card {
box-shadow: 0px 10px 15px -3px rgba(0 0 0 / 0.2);
}
</style>

The demo keeps a soft shadow under the card while idle, then suppresses it when the built-in dynamic shadow activates.

I’ve made the static shadow red, so it is easier to see how the toggle is working.
ShadowCard.svelte
<HoverTilt class="shadow-card" shadow shadowBlur={30}>
<div class="card">
Custom shadow when inactive
</div>
</HoverTilt>
<style>
.shadow-card .card:not(:hover) {
/* transition to a static shadow when not hovering */
box-shadow: 0px 10px 15px -3px rgb(250 45 45 / 0.2) ;
transition: box-shadow 300ms ease 300ms;
}
.shadow-card:hover .card {
/* apply shadow immediately when hovering */
transition-delay: 0ms
}
</style>

If you need a specific shadow effect, it’s posible to utilise the --shadow-x and --shadow-y variables, and override the built-in dynamic shadow by setting the --hover-tilt-custom-shadow CSS variable.

See the Custom Shadow page for more details.