How to format an inline code in Confluence?
To insert inline monospace font in Confluence, surround the text in double curly-braces.
This is an {{example}}
.
If you're using Confluence 4.x or higher, you can also just select the "Preformatted" option from the paragraph style menu. Please note that will apply to the entire line.
Full reference here.
By default Confluence renders monospaced text with transparent background. You can edit global CSS to add grey color. From Confluence manual:
- Choose the cog icon at top right of the screen, then choose Confluence Admin.
- Choose Stylesheet.
- Choose Edit.
- Paste your custom CSS into the text field.
- Choose Save.
Custom CSS for displaying grey background in monospaced blocks:
code {
padding: 1px 5px 1px 5px;
font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;
background-color: #eeeeee;
}
If you're using Confluence OnDemand (cloud):
- Click the cog/gear in the bottom of the sidebar on the left
- Select Look and Feel
- Click the Sidebar, Header and Footer tab
- Paste your custom CSS into the Header field
- Wrap the code in a
{style}
block - Save
Paste the following:
{style}
code {
padding: 1px 5px 1px 5px;
font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif;
background-color: #eeeeee;
}
{style}
After that you'll get nice and tidy stackoverflow-stylish inline code spans just by writing {{sometext}}
.
You could ask your fiendly Confluence administrator to create a macro for you. Here is an example of a macro for Confluence 3.x
Macro Name: inlinecode
Macro Title: Markup text like stackoverflow inline code
Categories: Formatting
Macro Body Processing: Convert wiki markup to HTML
Output Format: HTML
Template:
## Macro title: Inline Code
## Macro has a body: Y
## Body processing: Convert wiki markup to HTML
## Output: HTML
##
## Developed by: My Name
## Date created: dd/mm/yyyy
## Installed by: My Name
## This makes the body text look like inline code markup from stackoverflow
## @noparams
<span style="padding: 1px 5px 1px 5px; font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif; background-color: #eeeeee;">$body</span>
Then users can use {inlinecode}like this{inlinecode}
You could also use the {html}
or {style}
macros if they are installed or add this style to the stylesheet for your space.
While you are at it ask your Confluence admin to create a kbd macro for you. Same as the above, except Macro name
is kbd and Template
is:
<span style="padding: 0.1em 0.6em;border: 1px solid #ccc; font-size: 11px; font-family: Arial,Helvetica,sans-serif; background-color: #f7f7f7; color: #333; -moz-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset; -webkit-box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset; box-shadow: 0 1px 0px rgba(0, 0, 0, 0.2),0 0 0 2px #ffffff inset; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; display: inline-block; margin: 0 0.1em; text-shadow: 0 1px 0 #fff; line-height: 1.4; white-space: nowrap; ">$body</span>
Then you can write documentation to tell users to hit the F1 and Enter keys.
As of Confluence 4 and above, typing two curly brackets does not work.
You now need to select Monospace font. Highlight the text you want to change and:
Windows: Ctrl + Shift + M
Mac: Command + Shift + M
Alternatively, you can type a backtick (`) and Confluence will format everything until you type another backtick
Alternatively, next to the bold and italic options, you can click the "more" drop down and select Monospace: