Copy button

Add a copy button to each of your code cells to make it easy for users to copy and paste code.

ui

About this Extension

Automatically adds copy buttons to all code blocks in your documentation. Users can click the button to copy code to their clipboard instead of manually selecting and copying text.

Features

  • Adds copy buttons to all code blocks automatically
  • Works with any Sphinx theme
  • Removes shell prompts ($, >>>) from copied content
  • Shows “Copied!” feedback when button is clicked
  • Configurable selectors for which elements get buttons

Useful for

  • API documentation with code examples
  • Installation instructions with command-line snippets
  • Configuration file examples
  • Code tutorials and guides

The extension is particularly valuable on mobile devices where selecting text is difficult.

Configuration

# conf.py
extensions = ['sphinx_copybutton']

# Optional: customize which prompts to remove
copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "

# Optional: specify which elements get copy buttons
copybutton_selector = "div.highlight pre"

Zero configuration required - just add to extensions and copy buttons appear on all code blocks.

Author

Chris Holdgraf

License

MIT License

Try it out!

We have not been able to validate your subscription.
You have been subscribed to SphinxThemes.com

We've got more coming...

Join the community and get notified every time we list a new Sphinx theme or extension.