reveal.js HTML Presentation Framework
repository·master·Indexed 13 days ago
https://github.com/hakimel/reveal.jsAn open-source HTML presentation framework for creating interactive presentations using HTML, CSS, and JavaScript. Features include nested vertical slides, Markdown support, Auto-Animate transitions, PDF export, speaker notes, LaTeX math typesetting, and syntax-highlighted code blocks. Includes a React wrapper (@revealjs/react) and plugins for Markdown and Highlight.js.
What's inside reveal.js
- reveal.js is an open source HTML presentation framework that allows you to create presentations using web technologies. It is designed to be viewed in any web browser and includes advanced features like nested (vertical) slides, Markdown support, Auto-Animate transitions, PDF export, speaker notes, LaTeX math typesetting, and syntax-highlighted code blocks.
How @revealjs/react works
masterUnderstanding the lifecycle and synchronization of the wrapper:
- Initialization:
Deckcreates one Reveal instance on mount and destroys it on unmount. Initialization is asynchronous;onReadyfires oncereveal.initialize()resolves. The instance becomes available viauseReveal()anddeckRefonly after this point. - Synchronization:
Deckcallsreveal.sync()when the React slide structure changes (adding, removing, or reordering slides). - Slide Updates:
Slidecomponents handle localdata-*attribute updates usingreveal.syncSlide(). This allows React content updates inside a slide to occur without triggering a full deck sync. - Markdown: The
Markdowncomponent usesmarkedand supports standard Reveal markdown comment syntax (e.g.,<!-- .slide: ... -->and<!-- .element: ... -->). - Configuration: The
configprop is shallow-compared;reveal.configure()is only called when a value actually changes. - Plugins: The
pluginsprop is captured once on the first mount and ignored on subsequent renders, matching Reveal's initialization lifecycle.
- Initialization:
Set up a basic Reveal deck in React
masterTo create a presentation, render a
Deckcomponent containing one or moreSlidecomponents. You must import the core Reveal CSS and a theme (e.g.,black.css) for the deck to render correctly.import { Deck, Slide } from '@revealjs/react'; import 'reveal.js/reveal.css'; import 'reveal.js/theme/black.css'; export function Presentation() { return ( <Deck> <Slide> <h1>Hello</h1> <p>My first Reveal deck in React.</p> </Slide> <Slide background="#111827"> <h2>Second slide</h2> </Slide> </Deck> ); }How to create a custom reveal.js theme
masterTo create a new theme, duplicate an existing
.scssfile located incss/theme. The theme will be automatically compiled from Sass to CSS when you execute the build command.Each theme follows a specific four-step structure based on template files:
- Include
mixins.scss: Provides shared utility functions. - Include
settings.scss: Defines the custom CSS variables used by the template. You should override these variables to customize your theme's appearance. - Include
theme.scss: The core template file that generates the final CSS output based on the variables defined in the previous step. - Customization: Optionally add custom fonts or additional specific styles at the end of the file.
# To compile your new theme after creating the .scss file npm run build:styles- Include
Prerequisites for creating a reveal.js theme
masterThemes are written using Sass to maintain modularity and minimize selector repetition. Before attempting to create or modify themes, ensure you have the full reveal.js development environment installed as described in the official installation guide.Install @revealjs/react and dependencies
masterTo use the React wrapper, install
@revealjs/reactalong with its peer dependencies:reveal.js,react, andreact-dom.Note: The package only provides React bindings. You are responsible for importing Reveal CSS, themes, and any plugins you intend to use.
npm i @revealjs/react reveal.js react react-dom # or yarn add @revealjs/react reveal.js react react-domUse enqueued API calls for pre-initialization setup
masterThe
Revealentrypoint allows you to call certain configuration and event methods beforeinitialize()is actually executed. These calls are queued and automatically applied to theRevealApiinstance once initialization completes.Supported methods for queuing include:
configureonoffaddEventListenerremoveEventListenerregisterPlugin
This ensures that event listeners and configurations are applied correctly even if they are defined before the DOM is fully ready or
initialize()is called.import Reveal from './js/index.ts'; // These calls are queued and executed after initialize() Reveal.on('ready', () => { console.log('Presentation is ready!'); }); Reveal.configure({ hash: true }); // Finally, trigger the initialization Reveal.initialize();Configure Reveal via the Deck component
masterPass a
configobject to theDeckcomponent to set Reveal options. This object maps directly to the Reveal configuration object.Plugins should be passed to the
pluginsprop onDeck. Plugins are registered once during initialization and are not re-applied on subsequent renders.import { Deck, Slide } from '@revealjs/react'; import 'reveal.js/reveal.css'; import 'reveal.js/theme/black.css'; import 'reveal.js/plugin/highlight/monokai.css'; import RevealHighlight from 'reveal.js/plugin/highlight'; export function Presentation() { return ( <Deck config={{ width: 1280, height: 720, hash: true, controls: true, progress: true, transition: 'slide', }} plugins={[RevealHighlight]} > <Slide>Configured deck</Slide> </Deck> ); }Include images in Markdown slides
masterYou can embed images in your Markdown-based slides using standard Markdown image syntax:
.Use Markdown for slide content
masterreveal.js supports Markdown for defining slide content. You can use standard Markdown syntax for headings, text, and special elements like images and mathematical equations.
To create speaker notes, use the
Note:prefix followed by your text. This content will only be visible in the speaker notes window during a presentation.## External 1.1 Content 1.1 Note: This will only appear in the speaker notes window. ## External 3.3 (Image)  ## External 3.4 (Math) $$ J(\theta_0,\theta_1) = \sum_{i=0} $$Include math equations in Markdown slides
masterMathematical equations can be included in Markdown slides using LaTeX-style syntax wrapped in double dollar signs (
$$ ... $$).$$ J(\theta_0,\theta_1) = \sum_{i=0} $$Use @revealjs/react components: Fragment, Code, Stack, and Markdown
masterThe package provides several specialized components for common slide patterns:
Fragment: Reveals content incrementally. Useanimation(e.g.,fade-up) andasorasChildto control the rendered element.Code: Renders syntax-highlighted blocks. Requires thereveal.js/plugin/highlightplugin.Stack: Groups multipleSlidecomponents into a vertical column.Markdown: Renders Reveal-compatible markdown. It accepts string children, amarkdownprop, or asrcprop for external files.
import { Deck, Slide, Stack, Markdown, Fragment, Code } from '@revealjs/react'; import RevealHighlight from 'reveal.js/plugin/highlight'; import 'reveal.js/plugin/highlight/monokai.css'; export function Presentation() { return ( <Deck plugins={[RevealHighlight]}> <Slide> <h2>Step by step</h2> <Fragment animation="fade-up" as="p">First point</Fragment> <Fragment animation="fade-up" asChild> <div>Second point</div> </Fragment> <Code language="javascript" lineNumbers> {`console.log('Hello, world!');`} </Code> </Slide> <Stack> <Slide>Vertical 1</Slide> <Slide>Vertical 2</Slide> </Stack> <Markdown separator="^\n---\n$" verticalSeparator="^\n--\n$" options={{ smartypants: true, animateLists: true }} > {` ## Markdown 1.1 - First item <!-- .element: class="fragment" --> - Second item <!-- .element: class="fragment" --> -- ## Markdown 1.2 Notes: These become speaker notes. --- <!-- .slide: data-background="#111827" --> ## Markdown 2 `} </Markdown> </Deck> ); }