Code Block Macro

The Code Block macro allows you to display source code in your page with syntax highlighting, like the one below:

Add the Code Block Macro

  1. In the Confluence editor, choose Insert > Other Macros
  2. Find and select the required macro

Speeding up macro entry with autocomplete: Type { and the beginning of the macro name, to see a list of suggested macros. Details are in Autocomplete for links, files, macros and mentions.

To edit an existing macro: Click the macro placeholder and choose Edit. A macro dialog window will open, where you can edit the parameters of the macro.

You type the code block directly into the macro placeholder in the editor. Note that any white space contained in the placeholder is not manipulated in any way by the Code Block macro. This is to provide the writer with flexibility over code indentation.


Parameters are options that you can set to control the content or format of the macro output. Where the parameter name used in Confluence storage format or wikimarkup is different to the label used in the macro browser, it will be listed below in brackets (example).




Syntax highlighting


Specifies the language (or environment) for syntax highlighting. The default language is Java but you can choose from one of the following languages/environments:

  • actionscript3
  • bash
  • csharp (C#)
  • coldfusion
  • cpp (C++)
  • css
  • delphi
  • diff
  • erlang
  • groovy
  • html/xml
  • java
  • javafx
  • javascript
  • none (no syntax highlighting)
  • perl
  • php
  • powershell
  • python
  • ruby
  • scala
  • sql
  • vb



Adds a title to the code block. If specified, the title will be displayed in a header row at the top of the code block.



If selected, the code macro's content will be collapsed upon visiting or refreshing the Confluence page. Clicking the expand source link allows you to view this content. If false, the code macro's content is always displayed in full.

Show line numbers


If selected, line numbers will be shown to the left of the lines of code.

First line number


When Show line numbers is selected, this value defines the number of the first line of code.



Specifies the colour scheme used for displaying your code block. Many of these themes are based on the default colour schemes of popular integrated development environments (IDEs). The default theme is Confluence (also known as Default), which is typically black and coloured text on a blank background. However, you can also choose from one of the following other popular themes:

  • DJango
  • Emacs
  • FadeToGrey
  • Midnight
  • RDark
  • Eclipse
  • Confluence

Configure the Code Block macro

You can configure the Code Block macro to use a specific language and theme by default and also upload new lanuages. You need Confluence Administrator permissions to change the default theme and language and System Administrator permissions to upload new languages.

To set the default appearance of code blocks in your site:

  1. Choose the cog icon , then choose General Configuration under Confluence Administration
  2. Choose Configure Code Macro
  3. Select a Default Theme and Default Language
  4. Choose Save

All new code blocks will use the default theme and language unless you specify otherwise. Existing code blocks will be unchanged. 

 To add an additional language:

  1. Choose the cog icon , then choose General Configuration under Confluence Administration
  2. Choose Configure Code Macro
  3. Choose Add a new language
  4. Locate your language file and enter a Name for the new language (this will appear when selecting the language)
  5. Choose Add

Language files must be correctly formatted JavaScript files and adhere to the Custom Brush syntax. You can find some examples of language files here.

To disable or remove a user-installed language:

  1. Choose the cog icon , then choose General Configuration under Confluence Administration
  2. Choose Manage Add-ons
  3. Go to User-installed Add-ons and locate the add-on for your uploaded language - it will appear like this 'Custom Code Macro Highlighting for...'
  4. Choose Uninstall or Disable

The language will no longer appear in the Code Macro. 

Code examples

The following examples are provided for advanced users who want to inspect or edit the underlying markup for a Confluence page. 

Macro name: code

Macro body: Accepts plain text.

Storage format example

The following example shows all parameters and a body:

Below are three examples of the Code Block macro with various optional parameters used.


Markup What you will get
Code block macro with a body and no optional parameters
Code block macro with a body and the optional language parameter defined

Code block macro with a body and optional title, line numbers and language parameters defined

This is my title

Wiki markup example

Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport