print("Always visible - no toggle button")Always visible - no toggle buttonThis page demonstrates how to globally enable toggle functionality for all code cells, rather than enabling it on a per cell configuration. This approach allows you to skip individual cell configurations unless you want to override the global behavior.
To enable toggle for all cells, add this to your document’s YAML header:
---
title: "Your Document Title"
format: html
toggle:
  output-toggle: true    # Automatically add toggle to all cells
  output-hidden: false   # Show outputs by default
filters: [toggle]
---With this set, every code cell that produces an output gets a toggle button automatically and outputs are visible by default. Readers can hide them if they choose.
This means:
toggle: true to individual cells as it will apply to all.Hover over code blocks to see toggle buttons. "⌄" = visible, "›" = hidden.
print("Hello, world!")Hello, world!print("This has a toggle button.")This has a toggle button.numbers = [1, 2, 3, 4, 5]
print(f"Sum: {sum(numbers)}")Sum: 15print(f"Average: {sum(numbers)/len(numbers)}")Average: 3.0import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9], 'o-')
plt.title("Simple Plot")
plt.show()
data <- c(10, 20, 30, 40, 50)   
cat("Mean:", mean(data), "\n")Mean: 30 cat("Max:", max(data), "\n")Max: 50 barplot(c(23, 45, 32), names.arg = c("A", "B", "C"))
No toggle button will be added, output is always visible.
print("Always visible - no toggle button")Always visible - no toggle buttonecho "Current date:"
dateCurrent date:
Thu May 29 08:42:08 UTC 2025