Server rendering without a flash
A server-rendered page shows its HTML before the scripts run. If a script hides the content, the content shows, then hides, then animates. The React, Vue and Astro packages hide the waiting content in the server HTML, so it does not flash.
Hidden in the server HTML
Section titled “Hidden in the server HTML”Each waiting element has the data-awesome-reveal attribute in the server HTML:
Revealand the other reveal APIs setdata-awesome-reveal="hidden"on the element.Cascadeand the other cascade APIs setdata-awesome-reveal="cascade"on the container.
The reveal.css stylesheet of the package gives opacity: 0 to each hidden element and to the direct children of each cascade container. The element keeps its size and its place, so the layout does not move at the reveal. At the reveal, the package removes the attribute, and the entrance starts.
The modules of each package import the stylesheet, so your bundler or Astro adds it to the page. Three setups need a step:
The 5 second hold
Section titled “The 5 second hold”The stylesheet does not hide a waiting element with a static rule. It plays the awesome-reveal-hold CSS animation, which holds opacity: 0 for 5 seconds. When the script of the package attaches the element, it adds the data-awesome-reveal-attached attribute. A static opacity: 0 rule then hides the element until the reveal.
If no script attaches the element in 5 seconds, the hold ends, and the content shows. Thus the content does not stay hidden when a script fails to load or throws.
While focus is in the element or in the cascade container, the content shows. Thus a keyboard user does not focus invisible content before the script attaches it. After a blur, the hold continues until its 5 seconds end.
If the script attaches the element after 5 seconds, the content shows, then hides again until it reveals. Lazy hydration often attaches the element that late. Hydrate the reveal content eagerly.
When the stylesheet does not hide content
Section titled “When the stylesheet does not hide content”The stylesheet hides content only for the screen media type, and only with prefers-reduced-motion: no-preference. Thus the content shows immediately in these cases:
- The user asks for reduced motion.
- The user prints the page.
- JavaScript is off. A
scripting: nonerule stops the hold. In browsers without thescriptingmedia feature, such as Safari 16, the content shows after 5 seconds.
Things to know
Section titled “Things to know”- The hold replaces your own
animationuntil the reveal. Put your own animation on an inner element. The hold also firesanimationstartandanimationendevents, and shows ingetAnimations(). !importantstyles can show the element too early. An inlineopacityor your ownanimationwith!importantcan show the element before the reveal.- The packages reserve two attributes. Do not set
data-awesome-revealordata-awesome-reveal-attachedyourself. - The stylesheet does not reach a shadow root. It cannot hide an element in a shadow root.
The JavaScript API
Section titled “The JavaScript API”@awesome-reveal/core has no stylesheet, and it does not hide content before your script calls reveal() or cascade(). Server-rendered content can show, then animate. For server-rendered pages, use the React, Vue or Astro package.
You can import core on the server. Call reveal() and cascade() only in the browser.
Search engines
Section titled “Search engines”The content is in the server HTML. The stylesheet changes only the opacity of the content, not the text or the layout. Thus a search engine or a tool that reads the HTML gets all the content.