Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Backgrounds

Pro

Eclipse Background for React

A total eclipse as a frame: a moon wider than the box, so only its rim shows, ringed by a thin line of light, a soft corona with swaying streamers and a diamond of sunlight gliding along it. For React with Base UI, when a hero, a launch or an event page needs drama around a centred headline.

Framework

A total eclipse as a frame: the moon is wider than the box's shorter side, so only its rim shows, ringed by a thin line of light and a soft corona whose streamers fan out along the longer sides and sway, while a diamond of sunlight glides along the rim and sparkles. The moon is your page's own background, so a headline sits inside the ring and reads as it does anywhere else, in either colour scheme: white gold on black in the dark, warm gold on paper in the light. The corona is CSS gradients painted once; two layers of seeded streamers sway with transforms and blend onto the sky, and the diamond rides a rotating wrapper, so the browser repaints nothing.

Centre a short headline inside the ring. For a giant sun rising from the top edge instead, use Corona; for the glowing remnant of an exploded star, Supernova; for stage lights sweeping down from above, Spotlight.

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Usage

import { Eclipse } from "@/components/ui/eclipse";
<Eclipse className="flex min-h-[460px] items-center justify-center">
  <h1 className="text-5xl font-semibold">Totality</h1>
</Eclipse>

Eclipse is a container: whatever you put inside sits on top of the scene, in normal flow, and a centred headline lands inside the ring. The moon's radius is 66% of the container's shorter side, capped at 42% of the longer one, so the rim and its corona show along the longer sides; on a tall box the whole frame turns a quarter, so the streamers fan up and down and the diamond rides the top. The component paints your background colour behind the corona. For the whole page, render it empty with className="fixed inset-0 -z-10".

Demos

Size

size is the moon's radius as a share of the container's shorter side (0.66 by default). At size={0.5} the whole ring fits in the card, with intensity="strong" for a brighter corona.

Preview width

Blood sun

colors takes three colours: the rim and the diamond, the streamers, and the outer glow. moonColor paints the disc in any colour. The container's dark class and bg-background keep this scene dark in both colour schemes.

Preview width

Accessibility

The eclipse is decorative: it's hidden from screen readers and never takes the pointer, and your content stays on top in normal flow. With reduced motion the streamers stop swaying and the diamond stops where it is, so a still eclipse stays. Nothing flashes; the diamond's sparkle swells and settles over three seconds.

Text inside the ring keeps the contrast your theme gives it, since the moon is your background colour: use your foreground colour (text-foreground). The rim, the diamond and the corona just outside it are the brightest parts of the scene, so keep text off them.

FAQ

Why is the moon so big?

So the eclipse frames your content instead of sitting in the middle of it: only the rim and the corona show, along the longer sides of the box, and the inside of the ring is calm space for a headline. Pass a smaller size, such as 0.5, to show the whole ring.

Can I put text on the moon?

Yes, that's where it goes. The moon is your page's own background colour by default, so text in your foreground colour reads exactly as it does elsewhere on the page, in light and dark mode. If you set moonColor, pick a text colour that contrasts with it.

How do I change the corona colours?

Pass colors with three CSS colours: the rim and the diamond, the streamers, and the outer glow; fewer repeat the last. You can also set --eclipse-color-1 to --eclipse-color-3 in your CSS.

What moves?

Two layers of streamers sway 7° each way, out of step, on 31 and 23 second swings, and the diamond glides along the rim and back every 26 seconds while its sparkle swells. It's all rotate, scale and opacity, which the browser animates without repainting. speed scales it all.

What happens in a tall box?

The frame turns a quarter: the corona's long streamers fan up and down, where the rim shows, and the diamond rides the top of the moon instead of its side.

How is it different from Corona?

Eclipse is the dark moon framed by its corona, with the headline inside the ring. Corona is the bright sun itself, rising from the top edge and pouring rays down into a sky.

Does it respect reduced motion?

Yes: the streamers and the diamond hold still, so the eclipse stays on screen as a still picture.

API Reference

Eclipse

<div> data-slot="eclipse"

PropType
colors?string[]

Three CSS colours for the corona: the rim and the diamond, the streamers, and the outer glow. By default white gold on a dark page and warm golds on a light one.

intensity?"subtle" | "medium" | "strong"

How strongly the corona and streamers glow.

Type
"subtle" | "medium" | "strong"
Default
"medium"
moonColor?string

The moon's colour, any CSS colour. By default it's your page's own background, so text inside the ring reads as it does anywhere else.

size?number

The moon's radius as a share of the container's shorter side, capped so the rim always shows along the longer sides.

Default
0.66
speed?number

How fast the streamers sway and the diamond glides: 2 is twice as fast.

Default
1
stars?number

How many stars show around the corona on a dark page, from 0 to 200. @default 70.

Default
70
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

CSS variableType
--eclipse-color-1string

The rim and the diamond (white gold; gold in light mode).

--eclipse-color-2string

The streamers (pale gold).

--eclipse-color-3string

The outer glow (gold; amber in light mode).

--eclipse-moonstring

The moon's colour (your page's background).

--eclipse-rstring
--eclipse-sizestring

The moon's radius as a share of the shorter side (0.66).

--eclipse-skystring
--eclipse-speedstring

How fast it all moves (1).

All 100 backgrounds