Try this: https://bookdown.org/yihui/rmarkdown-cookbook/html-scroll.html or this: https://community.rstudio.com/t/bookdown-reveal-solution-to-exercise/16496