Tilt

Tilts its content in 3D in response to the pointer and device orientation

Usage

Tilt rotates its content in 3D following the pointer. It is built on top of the use-tilt hook, use the hook directly for full control over the transforms. Wrap any element with a defined size:

Hover to tilt

The card reacts to your cursor and returns to its resting position on leave.

import { Box, Stack, Text, Tilt, Title } from '@mantine/core';

function Demo() {
  return (
    <Tilt radius="lg">
      <Box
        w={320}
        h={220}
        p="xl"
        c="white"
        style={{
          borderRadius: 'var(--mantine-radius-lg)',
          backgroundImage:
            'linear-gradient(135deg, var(--mantine-color-indigo-6), var(--mantine-color-grape-6))',
        }}
      >
        <Stack justify="center" h="100%" gap={4}>
          <Title order={3}>Hover to tilt</Title>
          <Text>The card reacts to your cursor and returns to its resting position on leave.</Text>
        </Stack>
      </Box>
    </Tilt>
  );
}

Tilt me

Tweak the props to see how the effect changes.

Max rotate
Perspective
import { Box, Stack, Text, Tilt, Title } from '@mantine/core';

function Demo() {
  return (
    <Tilt radius="lg" withGlare>
      <Box
        w={320}
        h={220}
        p="xl"
        c="white"
        style={{
          borderRadius: 'var(--mantine-radius-lg)',
          backgroundImage:
            'linear-gradient(135deg, var(--mantine-color-blue-6), var(--mantine-color-cyan-6))',
        }}
      >
        <Stack justify="center" h="100%" gap={4}>
          <Title order={3}>Tilt me</Title>
          <Text>Tweak the props to see how the effect changes.</Text>
        </Stack>
      </Box>
    </Tilt>
  );
}

Layers

Use Tilt.Layer to build a depth effect. Each layer shifts towards the pointer, depth prop controls how far it shifts: layers with a higher depth appear closer to the viewer:

PARALLAX

depth in motion

import { Box, Text, Tilt, Title } from '@mantine/core';

function Demo() {
  return (
    <Tilt maxRotate={14} radius="lg">
      <Box
        style={{
          position: 'relative',
          overflow: 'hidden',
          width: 320,
          height: 220,
          borderRadius: 'var(--mantine-radius-lg)',
          backgroundImage: 'linear-gradient(160deg, #1b1f3b 0%, #3b2f63 60%, #7b3fa0 100%)',
        }}
      >
        {/* Background layer moves the least */}
        <Tilt.Layer depth={0.25} shift={16} style={{ position: 'absolute', inset: 0 }}>
          <Box
            style={{
              position: 'absolute',
              top: 120,
              left: '50%',
              width: 220,
              height: 220,
              transform: 'translateX(-50%)',
              borderRadius: '50%',
              backgroundImage: 'radial-gradient(circle at 40% 35%, #ffd43b, #f76707)',
            }}
          />
        </Tilt.Layer>

        {/* Foreground text pops out the most */}
        <Tilt.Layer
          depth={1.4}
          style={{
            position: 'absolute',
            inset: 0,
            display: 'flex',
            flexDirection: 'column',
            alignItems: 'center',
            justifyContent: 'center',
          }}
        >
          <Title order={2} c="white">
            PARALLAX
          </Title>
          <Text c="rgba(255, 255, 255, 0.7)">depth in motion</Text>
        </Tilt.Layer>
      </Box>
    </Tilt>
  );
}

Glare

Set withGlare to display a light reflection that follows the pointer:

Glare

A light reflection follows the pointer across the surface.

import { Box, Stack, Text, Tilt, Title } from '@mantine/core';

function Demo() {
  return (
    <Tilt withGlare radius="lg">
      <Box
        w={320}
        h={220}
        p="xl"
        c="white"
        style={{
          borderRadius: 'var(--mantine-radius-lg)',
          backgroundImage:
            'linear-gradient(135deg, var(--mantine-color-indigo-6), var(--mantine-color-grape-6))',
        }}
      >
        <Stack justify="center" h="100%" gap={4}>
          <Title order={3}>Glare</Title>
          <Text>A light reflection follows the pointer across the surface.</Text>
        </Stack>
      </Box>
    </Tilt>
  );
}

The reflection is the ::before pseudo-element of the glare selector, change it with classNames:

import { Tilt } from '@mantine/core';
import classes from './Demo.module.css';

function Demo() {
  return (
    <Tilt withGlare classNames={{ glare: classes.glare }}>
      {/* content */}
    </Tilt>
  );
}
.glare::before {
  background: radial-gradient(circle at 50% 50%, rgba(255, 220, 150, 0.6), transparent 60%);
}

React to the whole page

By default, Tilt reacts only while the element is hovered. Set trackWindow to make it follow the pointer anywhere on the page:

Move your cursor anywhere on the page

import { Box, Text, Tilt } from '@mantine/core';

function Demo() {
  // trackWindow makes the element follow the cursor anywhere on the page,
  // not only while it is hovered
  return (
    <Tilt trackWindow maxRotate={12} radius="lg">
      <Box
        w={220}
        h={220}
        c="white"
        style={{
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'center',
          textAlign: 'center',
          padding: 'var(--mantine-spacing-md)',
          fontWeight: 600,
          borderRadius: 'var(--mantine-radius-lg)',
          backgroundImage: 'radial-gradient(circle at 30% 30%, #4dabf7, #1971c2)',
        }}
      >
        <Text inherit>Move your cursor anywhere on the page</Text>
      </Box>
    </Tilt>
  );
}

Reduced motion

Tilt does not tilt the content when the user has requested reduced motion.

Device orientation

On supported mobile devices, Tilt reacts to the device orientation instead of the pointer. iOS requires a permission, see use-tilt for details.