Primitives
Background
An absolutely-positioned background layer for images, video, or color, with an optional overlay and slotted content on top.
Image background
Image Background
---
import Background from '@alfadormx/blocks/primitives/Background.astro';
---
<div class="relative h-64 overflow-hidden rounded-lg">
<Background image="https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=1200&h=600&fit=crop">
<div class="relative flex h-full items-center justify-center">
<h4 class="text-emphasis text-2xl font-bold drop-shadow-lg">Image Background</h4>
</div>
</Background>
</div>Color background
Plain Color Background
---
import Background from '@alfadormx/blocks/primitives/Background.astro';
---
<div class="relative h-64 overflow-hidden rounded-lg">
<Background class="bg-primary">
<div class="relative flex h-full items-center justify-center">
<h4 class="text-background text-2xl font-bold">Plain Color Background</h4>
</div>
</Background>
</div>Image background with overlay
Darkened for Legibility
---
import Background from '@alfadormx/blocks/primitives/Background.astro';
---
<div class="relative h-64 overflow-hidden rounded-lg">
<Background
image="https://images.unsplash.com/photo-1469474968028-56623f02e42e?w=1200&h=600&fit=crop"
overlayClass="bg-background/60"
>
<div class="relative flex h-full items-center justify-center">
<h4 class="text-emphasis text-2xl font-bold">Darkened for Legibility</h4>
</div>
</Background>
</div>Video background
A video starts muted and looping once the page loads, with a pause/play button in the bottom-end corner. It stays paused when the visitor prefers reduced motion, and pauses itself while off-screen. poster sets the still shown before playback and while paused.
video also takes a list of { src, type } sources in order of preference, such as a WebM file before an mp4 fallback; a missing type is inferred from the file extension.
Pause Any Time
---
import Background from '@alfadormx/blocks/primitives/Background.astro';
---
<div class="relative h-64 overflow-hidden rounded-lg">
<Background
video="/videos/demos/jewellery/hero.mp4"
poster="~/assets/images/demos/jewellery/craft.jpg"
overlayClass="bg-background/60"
>
<div class="relative flex h-full items-center justify-center">
<h4 class="text-emphasis text-2xl font-bold">Pause Any Time</h4>
</div>
</Background>
</div>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| image | string | — | Background image path or URL (supports `~/assets/`, public, and external URLs). |
| video | string | VideoFileSource[] | — | Background video: a URL, or sources in order of preference (`[{ src, type }]`, smallest format first). A missing `type` is inferred from the file extension. |
| attachment | BackgroundAttachment | 'scroll' | Scroll behavior for the background image; defaults to `'scroll'`. |
| class | string | '' | Additional classes applied to the background layer (color, sizing, etc.). |
| overlayClass | string | — | Classes applied to the optional overlay div rendered on top of the background. |
| poster | string | — | Still image shown before playback and while a background video is paused; same sources as `image`. Applies only with `video`. |
| pauseButton | ButtonProps | — | Pause button shown over a playing background video. Restyle through this field; it cannot be removed. |
| playButton | ButtonProps | — | Play button shown over a paused background video. Inherits `pauseButton`'s defaults. |