Background
Background colors
Background colors for slides can be specified by two means: a classic one and one using AsciiDoc roles. See background-color.adoc for more examples.
Using AsciiDoc roles
Using roles respects the AsciiDoc philosophy of separation of content and presentation.
Colors are defined in CSS, and the :customcss: attribute is used to specify the CSS file to load.
To avoid clashing with existing reveal.js themes or CSS, a specific CSS class called background is expected to be present.
Here is an example:
= Title
:customcss: my-css.css
[.red.background]
== Slide One
Is very red
section.red.background {
background-color: red;
}
The canvas keyword can be used instead of background for the same effect.
|
The CSS rule styles the slide’s <section> element, so the color only covers the area taken by the slide’s content, not the whole screen.
To set a full-screen background from CSS, use a slide state instead:
[state=red]
== Slide One
Is very red, from edge to edge
.reveal-viewport.red {
background-color: red;
}
reveal.js adds the state as a class on the viewport element while the slide is shown.
See Role or state? for the difference between the two.
Unlike the background-color attribute below, the background changes instantly, without reveal.js' background transition.
Classic
[background-color="yellow"]
== Slide Three
Is very yellow
Slide Three applies the data-background-color attribute to the reveal.js <section> tag.
Anything accepted by CSS color formats works.
Background gradients
[background-gradient="linear-gradient(to right, blue 50%, grey 50%)"]
== Half and Half
Left half blue, right half grey
This applies the data-background-gradient attribute to the reveal.js <section> tag.
Anything accepted by the CSS background property works, such as linear-gradient(…) or radial-gradient(…).
To define the gradient in CSS instead, use a role or a state as described in Using AsciiDoc roles.
A gradient is an image in CSS, not a color, so set it with background-image (or the background shorthand); background-color ignores it:
[state=half-and-half]
== Half and Half
Left half blue, right half grey
.reveal-viewport.half-and-half {
background-image: linear-gradient(to right, blue 50%, grey 50%);
}
Background images
[%notitle]
== Grand Announcement
image::cover.jpg[background, size=cover]
This will put cover.jpg as the slide’s background image.
It sets reveal.js’ data-background-image attribute.
The size attribute is also supported.
See the relevant reveal.js documentation for details.
Background images file names are now relative to the :imagesdir: attribute if set.
|
The canvas keyword can be used instead of background for the same effect.
|
[%notitle]
== The Great Goat
image::https://upload.wikimedia.org/wikipedia/commons/b/b2/Hausziege_04.jpg[canvas,size=contain]
As you can see, you can use a URL to specify your image resource too.
Background videos
A background video for a slide can be specified using the background-video element attribute.
[background-video="https://my.video/file.mp4",background-video-loop=true,background-video-muted=true]
== Nice background!
For convenience background-video-loop and background-video-muted attributes are mapped to loop and muted options which can be specified with options="loop,muted".
For example:
[background-video="https://my.video/file.mp4",options="loop,muted"]
== Nice background!
See the relevant reveal.js documentation for details.
Note that the data- prefix is not required in AsciiDoc files.
Background iframes
The background can be replaced with anything a browser can render in an iframe using the background-iframe reveal.js feature.
[%notitle,background-iframe="https://www.youtube.com/embed/LaApqL4QjH8?rel=0&start=3&enablejsapi=1&autoplay=1&loop=1&controls=0&modestbranding=1"]
== a youtube video
See the relevant reveal.js documentation for details.