GodUIGodUI
85

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.

tsx
 
const baseStyle = {
  backgroundImage:
    "radial-gradient(circle 500px at 50% 200px, #3e3e3e, transparent)",
  backgroundColor: "#020617",
} as React.CSSProperties;
Anatomybase fill · radial glow
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:

tsx
 
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 opacity or filter).
OwnershipBACKGROUND_KEYS drop the bake
baked default
caller style wins
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:

tsx
 
<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.

Stackingabsolute inset-0 z-base
Background
absolute inset-0 z-base aria-hidden
Content
relative z-raised (or higher)

The result

Resultthe real component — content above z-base

One layer, one ownership rule, zero motion — a reliable stage for everything you put on top.

On this page

Built with GodUI

Beautifully crafted motion components for modern interfaces.

Star on GitHub