Reference

Configuration options

Every @samline/reveal attribute, JavaScript option, CSS custom property and state, with defaults and which one wins.

Attributes

Attributes win over options, so one call can set defaults and each element can override them.

Attribute Value Description
data-reveal up (empty), down, left, right, fade, zoom, blur, rotate, wipe-up, wipe-down, wipe-left, wipe-right, or several separated by spaces Marks the element and picks the effects. An empty, unknown or partly unknown value uses the effect option.
data-reveal-duration milliseconds Transition length
data-reveal-delay milliseconds Delay before the transition
data-reveal-distance CSS length How far up, down, left and right travel
data-reveal-easing smooth, snappy, spring, bounce, or a CSS timing function Easing of the transition
data-reveal-repeat present, or false Hide again on leaving, reveal on every entry
data-reveal-stagger milliseconds, on a container Cascade the elements inside it that enter together
data-reveal-stagger-from start, end, center, edges, random, on the same container Where the cascade starts (default start: document order)
data-reveal-stagger-grid present, or false, on the container Cascade over rows and columns measured from the layout instead of a line
data-reveal-stagger-ease linear or out, on the container Spacing of the gaps: even, or shrinking as the cascade goes on; the total length does not change
data-reveal-stagger-max milliseconds, on the container Longest cascade; longer ones are scaled down to fit
data-reveal-split words or chars Animate the text piece by piece with the element’s effect; the element itself does not animate
data-reveal-split-stagger milliseconds Step between pieces (default 50 for words, 20 for chars)
data-reveal-split-max milliseconds Longest split cascade (default 800, 0 for no cap); the step shrinks to fit
data-reveal-threshold 0 to 1 Share of this element that must be visible
data-reveal-margin CSS margin, such as 0px 0px 64px 0px rootMargin for this element; an invalid value falls back to the option
data-reveal-media media query While it does not match, the element is shown as is, never hidden
data-reveal-reduced show or fade What reduced motion does: show at once (default) or still fade
data-reveal-scrub present Follow the scroll position with CSS only; the script skips it

Combine effects with spaces, as in data-reveal="up blur": one direction (up, down, left, right) and one wipe at most. A wipe alone does not fade; add fade (wipe-up fade) to do both.

Options

Option Default Description
effect 'up' Effect, space-separated effects or one of your own CSS, for elements whose data-reveal is empty
duration CSS (600) Transition length in milliseconds
delay CSS (0) Delay in milliseconds
distance CSS ('0.75rem') CSS length for the directional effects
stagger 0 Milliseconds added per element when several are revealed together, in document order
staggerFrom 'start' 'start', 'end', 'center', 'edges' or 'random'; the container attribute wins
staggerGrid false Cascade over rows and columns; the container attribute wins
staggerEase 'linear' 'linear' or 'out'; the container attribute wins
staggerMax none Longest cascade in milliseconds; the container attribute wins
split none 'words' or 'chars'; data-reveal-split wins
easing CSS ('smooth') Preset or CSS timing function; data-reveal-easing wins
media — Media query; while it does not match, elements are shown as is
reducedMotion 'show' 'fade' keeps a fade under reduced motion instead of showing everything at once
repeat false Hide again after leaving and reveal on every entry
root viewport Scroll container to observe against
rootMargin '0px 0px 64px 0px' Grows the root so reveals start just before entering; if the browser rejects it, the call returns a destroyed controller and content stays visible
threshold 0 Share of the element that must be visible, 0 to 1
onShow(element) — When an element is shown: its transition starts, or right away if it was in view on load
onEnd(element) — When an element becomes revealed: after its transition, or right away if it has none
onHide(element) — When an element is hidden again: a repeat element left, or hide() was called
presets none { name: options }: elements whose whole data-reveal value is name use those per-element options; their attributes win
selector, scope, observe '[data-reveal]', document, true autoReveal only

Elements cascade with the others of their closest data-reveal-stagger container; elements outside any container cascade with the others of the same call that share the stagger value. Only elements revealed in the same frame cascade, so content scrolled in one by one is never delayed. The pattern attributes (from, grid, ease, max) are read from the same container; the options apply to elements without one, and calls with different patterns never cascade together.

CSS custom properties

Set them on the element or on any ancestor. duration, delay and distance set the first three inline.

Property Default Used by
--reveal-duration 600ms Every effect
--reveal-delay 0ms Every effect; cascades add to it
--reveal-easing cubic-bezier(0.2, 0.7, 0.2, 1) Every effect
--reveal-distance 0.75rem up, down, left, right
--reveal-scale 0.94 zoom
--reveal-blur 8px blur
--reveal-rotate -3deg rotate
--reveal-range entry 0% entry 100% Scrub mode
--reveal-split-stagger 50ms (words), 20ms (chars) Step between split pieces; set it on the element or an ancestor, or use data-reveal-split-stagger
--reveal-split-max 800ms Longest split cascade; the step shrinks so the cascade fits
--reveal-index set by the script Position of a split piece, in document order

Easing presets, set with data-reveal-easing or the easing option: smooth (the default curve), snappy, spring (overshoots) and bounce. spring and bounce use linear() where supported and fall back to a cubic-bezier otherwise; give them 800 to 1000 ms. Opacity and wipes keep a curve without overshoot.

Events

Dispatched on the element, bubbling, with detail: { animated: boolean }. animated is false when the element is shown or hidden without a transition: in view on load, media query not matching, reduced motion, or a media query that stops matching while the element is revealing.

Event When
reveal:show An element is shown, exactly when onShow is called
reveal:end An element becomes revealed, together with onEnd
reveal:hide An element is hidden again, together with onHide

Nothing fires after destroy().

States

The script sets data-reveal-state on each element:

State Meaning
pending Hidden, waiting to enter
revealing The transition is running
revealed Shown; no transition is applied any more

The transition only exists in revealing, so your own transitions on the element keep working once it is revealed. Every rule in the stylesheet uses :where(), so any selector of yours wins.