Anatomy of Gradient Background
How a single absolute layer, a BACKGROUND_KEYS ownership probe, and z-base stacking keep full-bleed gradients from fighting your content styles.
GradientBackground is intentionally boring infrastructure: one div,
baked CSS, no animation loop. The craft is not the paint — it is how the
component owns the background without colliding with caller overrides,
and how it sits under content without stealing focus or stacking context.
The baked default
Out of the box you get PatternCraft's dark-radial-glow: a near-black base
with a soft grey radial parked near the top of the frame.
const baseStyle = {
backgroundImage:
"radial-gradient(circle 500px at 50% 200px, #3e3e3e, transparent)",
backgroundColor: "#020617",
} as React.CSSProperties;- Base
- backgroundColor #020617
- Glow
- radial-gradient circle at 50% 200px
That bake lives in the component source between @default-props markers so
the registry / docs can surface the same strings. Presets are just other
style objects — the component itself stays one file.
Who owns the paint
CSS shorthand and longhand do not merge cleanly. If a caller passes
backgroundImage: "…" while the bake still sets backgroundColor, you can
end up with a broken cascade. So the component probes a fixed key list:
const BACKGROUND_KEYS = [
"background",
"backgroundColor",
"backgroundImage",
"backgroundSize",
"backgroundPosition",
"backgroundRepeat",
"backgroundBlendMode",
] as const;
const ownsBackground =
style != null && BACKGROUND_KEYS.some((key) => key in style);
style={ownsBackground ? style : { ...baseStyle, ...style }}- Owns — drop the bake entirely; caller style is the whole paint.
- Doesn't — spread bake first, then caller style (safe for non-background
keys like
opacityorfilter).
- Probe
- BACKGROUND_KEYS.some(k => k in style)
- Merge
- ownsBackground ? style : { ...base, ...style }
Pass a preset from gradientBackgroundPresets the same way — any object that
includes a background key triggers ownership.
Stack under content
The shell is always the same across the CSS preset family:
<div
aria-hidden="true"
className={`absolute inset-0 z-base ${className ?? ""}`}
style={…}
/>Drop it as the first child of a relative (usually overflow-hidden)
container. Raise your copy with z-raised or higher from the GodUI z-scale —
never arbitrary z-[1]. aria-hidden keeps the decorative plane out of the
accessibility tree.
- Background
- absolute inset-0 z-base aria-hidden
- Content
- relative z-raised (or higher)
The result
One layer, one ownership rule, zero motion — a reliable stage for everything you put on top.