Backgrounds¶
Slide backgrounds map to reveal.js data-background-* attributes. You do not need background classes for typical use; pass plain values to bg().
Plain values (preferred)¶
from pyreveal import BackgroundSize, BackgroundType, Presentation, Slide
# Color string
slide = Slide()
slide.title = "Colored"
slide.bg("#2d3436")
# Image path
slide.bg("photos/bg.jpg")
# Image with options
slide.bg(image="bg.jpg", size=BackgroundSize.COVER, opacity=0.6)
# Explicit type via enum
slide.bg(type=BackgroundType.GRADIENT, gradient="linear-gradient(to bottom, #283b95, #17b2c3)")
# Video
slide.bg(type=BackgroundType.VIDEO, video="assets/loop.mp4")
# Iframe
slide.bg(
type=BackgroundType.IFRAME,
iframe="https://example.com",
interactive=True,
)
Deck default background¶
Apply a background to every slide that does not set its own:
Shared options¶
All background types accept optional opacity, position, repeat, transition, and parallax.
slide.bg(image="bg.jpg", size=BackgroundSize.COVER, opacity=0.6, position="center")
slide.bg(image="bg.jpg", parallax="2") # per-slide parallax multiplier
Deck-wide parallax background¶
For a single large background that scrolls as you move through the deck, use Presentation.parallax_background():
deck = Presentation("Talk")
deck.parallax_background(
"assets/parallax.jpg",
size="2100px 900px",
horizontal=200,
vertical=50,
)
This maps to reveal.js parallaxBackground* config options. See reveal.js parallax backgrounds.
Video with multiple formats¶
Advanced: background classes¶
For fine-grained control, background classes remain available:
from pyreveal import ColorBackground, GradientBackground, ImageBackground
slide.bg(ColorBackground("#2d3436"))
slide.bg(ImageBackground("bg.jpg", size="cover"))