# Tilt
Package: @mantine/core
Import: import { Tilt } from '@mantine/core';
Description: 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](https://alpha.mantine.dev/llms/hooks-use-tilt.md) hook, use the hook directly for full control over the transforms.
Wrap any element with a defined size:

```tsx
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>
  );
}
```


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

function Demo() {
  return (
    <Tilt radius="lg" maxRotate={15} perspective={1000} withGlare={true} resetOnLeave={true} trackWindow={false}>
      <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:

```tsx
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:

```tsx
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`:

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

function Demo() {
  return (
    <Tilt withGlare classNames={{ glare: classes.glare }}>
      {/* content */}
    </Tilt>
  );
}
```

```css
.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:

```tsx
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](https://alpha.mantine.dev/llms/hooks-use-tilt.md#device-orientation-permission) for details.


#### Props

**Tilt props**

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| children | React.ReactNode | - | Content of the component, usually `Tilt.Layer` components for a layered depth effect |
| maxRotate | number | 15 | Maximum rotation in degrees applied to the content at the edges |
| perspective | string \| number | 1000 | Perspective distance of the 3D container, numbers are converted to rem |
| radius | MantineRadius \| number | - | Key of `theme.radius` or any valid CSS value to set `border-radius` of the content and glare, numbers are converted to rem |
| resetOnLeave | boolean | true | If set, the content returns to its neutral position when the pointer leaves the element. Ignored when `trackWindow` is set |
| resetTransitionDuration | number | - | Transition duration in ms when the element returns to its neutral position, `transitionDuration * 2` by default |
| trackWindow | boolean | false | If set, the component reacts to the pointer position anywhere on the page |
| transitionDuration | number | 150 | Transition duration in ms while the pointer moves over the element |
| withGlare | boolean | false | If set, a light glare that follows the pointer is displayed over the content |

**Tilt.Layer props**

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| children | React.ReactNode | - | Content of the layer |
| depth | number | - | Controls how far the layer shifts relative to the tilt, `0` – static, `1` – full shift |
| shift | number | - | Distance in px the layer shifts at the edges when `depth={1}` |


#### Styles API

Tilt component supports Styles API. With Styles API, you can customize styles of any inner element. Follow the documentation to learn how to use CSS modules, CSS variables and inline styles to get full control over component styles.

**Tilt selectors**

| Selector | Static selector | Description |
|----------|----------------|-------------|
| root | .mantine-Tilt-root | Root element, the perspective container |
| content | .mantine-Tilt-content | Element that receives the tilt rotation, wraps children and glare |
| layer | .mantine-Tilt-layer | Tilt.Layer root element |

**Tilt CSS variables**

| Selector | Variable | Description |
|----------|----------|-------------|
| root | --tilt-perspective | Controls perspective distance of the 3D container |
| root | --tilt-radius | Controls `border-radius` of the content and glare |

**Tilt data attributes**

| Selector | Attribute | Condition | Value |
|----------|-----------|-----------|-------|
| root | data-track-window | trackWindow prop is set | - |
| root | data-glare | withGlare prop is set | - |
