Code line highlighting in Quarto revealjs presentations

Three methods make your code lines stand out

Shannon Pileggi true
`.qmd` source code shows three different methods for code highlighting; on right hand side, image of slide 1 shows line 1 highlighted, image of slide 2 shows line 2 highlighted, and image of slide 3 shows line 3 highlighted.

Figure 1: Left hand side shows .qmd source code; right hand side shows rendered slides with line highlighting.


I started playing with Quarto revealjs presentations, it is fun! Here are three methods I learned to highlight code lines.


Some terminology introduced in the Quarto documentation includes:

For more information on displaying code, see:

Quarto -> Guide -> Tools -> Visual Editor -> Technical Writing -> Displaying code

For a complete overview of all code block options supported in Quarto, see

Quarto -> Reference -> Code Cells -> Knitr.


To highlight code lines in Quarto revealjs presentations, use the option code-line-numbers. This is a Quarto specific cell option for Quarto presentation formats of revealjs. This means that code-line-numbers will not render code highlighting when used in Quarto documents (.qmd) of format html, nor within an R markdown document (.Rmd). Note that Quarto cell options have a dash their name.

I first found this option in presentation revealjs documentation:

Quarto -> Guide -> Formats -> Presentations -> Revealjs -> Code Blocks.

Method 1:

#| echo: TRUE
#| eval: FALSE
#| code-line-numbers: "1"
x <- 1:10

Here, we are executing code cell options via special comments indicated by #|. Comment-based syntax is recommended for Quarto to make documents more portable and consistent across execution engines. See

Quarto -> Guide -> Computations -> Using R -> Chunk Options.

Method 2:

```{r, echo=TRUE, eval=FALSE, `code-line-numbers`="2"}
x <- 1:10

Quarto code cell options have dash in their name; R only supports dashes in variable names when wrapped in the back tick.

Method 3:

```{.r code-line-numbers="3"}
x <- 1:10

.r signals a non-compute code block (which is what we used above with eval=FALSE). These are verbatim code blocks with a class set on them for language highlighting. In this case, the language is R.


There is a lot of wonderful Quarto documentation, but navigating it all takes practice and time. I am new to Quarto, so suggestions and corrections to this post are most welcome.

For a quick starter on this topic, you can download the full Quarto revealjs presentation demonstration quarto-code-hl.qmd.

And here are the rendered presentation slides, which you can click through.


Thank you very much to Chris Dervieux for kindly explaining all of this to me on RStudio Community.


Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".


For attribution, please cite this work as

Pileggi (2022, May 12). PIPING HOT DATA: Code line highlighting in Quarto revealjs presentations. Retrieved from

BibTeX citation

  author = {Pileggi, Shannon},
  title = {PIPING HOT DATA: Code line highlighting in Quarto revealjs presentations},
  url = {},
  year = {2022}