Skip to main content

Search

Type a word or a question to search the help articles.

How do I add code with colours and a copy button to a story?

In this story

Where: Stories → All stories → The story editor

Open this page: admin.<your-site>/articles (replace <your-site> with your site address). Then open the one you want.

Steps

  1. Open the story in the editor.
  2. Put the cursor where the code should go.
  3. Open the Insert menu and choose More blocks, then Code block.
  4. Paste or type the code.
  5. Choose the language from the language list so the colours are right. Choose Plain text if you do not want colours.
  6. Publish the story.

For the full list of block options, see Code and maths.

Good to know

  • Languages you can pick: Plain text, Bash, C, C++, C#, CSS, Dart, Diff, Dockerfile, Go, GraphQL, HTML, INI, Java, JavaScript, JSON, Kotlin, Less, Lua, Makefile, Markdown, Objective-C, Perl, PHP, PowerShell, Python, R, Ruby, Rust, SCSS, Shell session, SQL, Swift, TOML, TypeScript, XML and YAML.
  • Copy code. On the website, each code block has a Copy code button. It shows up when the reader's browser allows copying.
  • Inline code. For one word or a short command inside a sentence, use the Inline code mark in the toolbar instead.
  • You can put a code block inside a Callout, a Toggle or a Column.
  • Don't paste secrets. Never put passwords, keys or tokens in a story. Readers can see everything you publish.

Questions

Frequently asked questions

Can readers run the code?

No. The block only shows and copies code.

Can I keep the code out of search snippets?

Yes. Blocks have a "no snippet" choice in the block actions. See Story SEO.

Feedback

Was this helpful?

Also available in

Still need help?