Quick Start

Your first toggle button

The toggle button appears when you hover over a code block. It sits in the top-right corner, next to the copy button if you have one enabled.

Here’s what it looks like (click to try):

Try It

Hover over any code block on this page. You’ll see the button fade in on the upper right side of the code cell.

print("Hello! Hover over this code block.")
[1] "Hello! Hover over this code block."
x <- 1:5
cat("Sum:", sum(x), "\n")
Sum: 15 
cat("Mean:", mean(x), "\n")
Mean: 3 
```{r}
print("Hello! Hover over this code block.")
```

```{r}
x <- 1:5
cat("Sum:", sum(x), "\n")
cat("Mean:", mean(x), "\n")
```

Enabling Toggle

You have two approaches: enable for specific cells, or enable document-wide.

Per-Cell

summary(iris)
  Sepal.Length    Sepal.Width     Petal.Length    Petal.Width   
 Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100  
 1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300  
 Median :5.800   Median :3.000   Median :4.350   Median :1.300  
 Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199  
 3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800  
 Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500  
       Species  
 setosa    :50  
 versicolor:50  
 virginica :50  
                
                
                
```{r}
#| toggle: true
summary(iris)
```

Document-Wide

Enable for all cells in your YAML header:

extensions:
  toggle:
    output-toggle: true

This page uses document-wide configuration, so every code cell has a button.

Disabling for Specific Cells

When toggle is enabled document-wide, you can turn it off for individual cells:

print("This output is always visible. No button here.")
[1] "This output is always visible. No button here."
```{r}
#| toggle: false
print("This output is always visible. No button here.")
```

This is useful when you have results that should always be visible, like final conclusions or key findings.

Summary

Toggle buttons give readers control over output visibility. Enable them document-wide with output-toggle: true, or per-cell with #| toggle: true. Override either direction as needed.

Next: Hide outputs by default, sync multiple outputs, or add a global button.