Skip to Content
Cristal

Layout

Animated background

Decorative animated background behind content (aurora, gradient, grid, dots, waves, particles), in the theme colours.

<cr-background>CrBackground

Example

CrBackground is a container: its content shows on top of a gently moving background, and stays ordinary page content, readable and clickable. variant picks the effect; that is all there is to set.

<CrBackground variant="aurora">
  <h1>Invoices, without the effort</h1>
</CrBackground>

Invoices, without the effort

Create, send and track your invoices in a few clicks, from a single screen.

Start for free
'use client';

import { useState } from 'react';
import { CrBackground, CrBox, CrButton, CrSegmented } from '@cristal-ui/react';

const variants = [
  ['aurora', 'Aurora'],
  ['gradient', 'Gradient'],
  ['grid', 'Grid'],
  ['dots', 'Dots'],
  ['waves', 'Waves'],
  ['particles', 'Particles'],
] as const;

export default function BackgroundGallery() {
  const [index, setIndex] = useState(0);

  return (
    <CrBox display="flex" direction="column" gap="lg" align="stretch">
      <CrSegmented label="Effect" value={String(index)} onCrChange={(event) => setIndex(Number(event.detail))}>
        {variants.map(([variant, label], value) => (
          <option key={variant} value={value}>
            {label}
          </option>
        ))}
      </CrSegmented>
      <CrBackground variant={variants[index][0]} style={{ padding: '64px 32px', borderRadius: 'var(--cr-radius-l)', textAlign: 'center' }}>
        <h3 style={{ margin: 0, fontSize: 30, lineHeight: 1.2 }}>Invoices, without the effort</h3>
        <p style={{ margin: '12px auto 24px', maxWidth: 420 }}>Create, send and track your invoices in a few clicks, from a single screen.</p>
        <CrButton>Start for free</CrButton>
      </CrBackground>
    </CrBox>
  );
}
variantEffect
auroralarge colour glows drifting slowly (default)
gradienta gradient sliding from end to end, crossed by a light sheen
grida grid floor moving toward the horizon
dotsa dot grid crossed by a wave of bigger, brighter dots
wavesthree layered waves rippling at the bottom
particlesdrifting points linked to their close neighbours (drawn in a canvas); they move away from the cursor and link to it, unless interactive={false}

The background takes the size of its content: set padding, min-height or border-radius as on a div. Leave some room at the bottom right for the pause button.

Colours

The colours come from the theme: the primary colour and two neighbouring hues, on the barely tinted surface. Changing --cr-color-primary is therefore enough to match everything. To pick other colours, set these CSS properties on the background or on a parent:

CSS propertyDefault
--cr-background-basethe surface, tinted with 4% of the primary colour
--cr-background-color-1the primary colour
--cr-background-color-2the primary colour, hue shifted by −70°
--cr-background-color-3the primary colour, hue shifted by +60°

Give strong colours: each effect lightens them itself so the text stays readable.

Pink theme

The colours follow the theme's primary colour.

Chosen colours

The three colours are set in CSS.

import type { CSSProperties } from 'react';
import { CrBackground, CrBox } from '@cristal-ui/react';

const block: CSSProperties = { padding: '32px 24px 56px', borderRadius: 'var(--cr-radius-l)' };

export default function BackgroundColors() {
  return (
    <CrBox display="grid" columns="260px" gap="lg">
      <div className="cr-theme" style={{ '--cr-color-primary': '#e11d48' } as CSSProperties}>
        <CrBackground variant="aurora" style={block}>
          <strong>Pink theme</strong>
          <p>The colours follow the theme's primary colour.</p>
        </CrBackground>
      </div>
      {/* A hand-picked light base: cr-theme keeps the light theme text, even when the page is dark. */}
      <CrBackground
        className="cr-theme"
        variant="waves"
        style={
          {
            ...block,
            '--cr-background-base': '#f0fdfa',
            '--cr-background-color-1': '#0284c7',
            '--cr-background-color-2': '#059669',
            '--cr-background-color-3': '#0d9488',
          } as CSSProperties
        }
      >
        <strong>Chosen colours</strong>
        <p>The three colours are set in CSS.</p>
      </CrBackground>
    </CrBox>
  );
}

Pause and reduced motion

An animation that starts by itself and lasts more than 5 seconds must be stoppable: a small pause button is therefore shown in the bottom right corner. The background also stops by itself when it leaves the screen or the tab is hidden, and starts again when it comes back, unless it is paused.

If your application already has its own control to stop animations, hide the button with controls={false} and drive the pause with paused:

<CrBackground variant="waves" controls={false} paused={!animations}>
  …
</CrBackground>

If the user asked their system to reduce motion, the background starts paused on a still frame; the button still lets them start it. Before the script loads, the page already shows this still frame.

Accessibility

  • The background is decorative: it is hidden from screen readers (aria-hidden) and holds nothing focusable. The content stays in the page, read and used normally.
  • The pause button is a real button, named "Pause the animation" ("Mettre en pause l'animation" in French), announced as pressed when the animation is stopped; its icon switches from pause to play. It has a solid background and a border above 3:1, a 30 × 30 pixel target and a visible focus outline.
  • Each effect stays subtle enough for text in --cr-color-text to keep a contrast of at least 4.5:1 over its darkest point, with the default colours. If you change the colours, check the contrast.
  • In high contrast mode, the background and its button disappear.
  • When paused, off screen or in a hidden tab, the background computes nothing: CSS animations are suspended and the canvas stops drawing.

API

Properties

PropertyTypeDefaultDescription
controlsbooleantrueAffiche le bouton pause dans le coin. À false seulement si l'application a sa propre commande pour arrêter les animations.
interactivebooleantrueAvec particles, les points s'écartent du pointeur et s'y relient par des traits ; sans effet sur les autres variants.
pausedbooleanfalseMet l'animation en pause ; le bouton pause l'inverse. Passe à true au chargement si l'utilisateur a demandé à réduire les animations.
variant"aurora" | "dots" | "gradient" | "grid" | "particles" | "waves"'aurora'Effet : aurora (halos de couleur qui dérivent, par défaut), gradient (dégradé qui glisse), grid (grille en perspective), dots (points traversés par une vague), waves (vagues) ou particles (points reliés, dessinés dans un canvas).

Slots

SlotDescription
defaultLe contenu affiché par-dessus le fond.

CSS parts

To style it from outside: cr-background::part(name) { … }

PartDescription
layerLa couche animée, décorative.
toggleLe bouton pause.

On this page