For inline code (that does not hold newlines), any of the following will work:
- Enclose with backticks:
`<html>`.
- Embed within
<code> tags, and manually encode HTML entities: <code><html></code>
- Select the partial text and hit CtrlK (CtrlK, or ⌘K on OS X) or click the
{} code button above the editor (pictured below)
For blocks of code, to preserve newlines, use one of the following methods:
- Use the
{} code button above the editor (pictured below)
- Paste your code, select the full lines, and hit CtrlK (CtrlK, or ⌘K on OS X)
- Indent everything four (4) spaces
- Encase in
<pre> or <pre><code> tags (in that order; using <code><pre> is invalid), and encode HTML entities (like < for <) yourself
Code copy/pasted from an IDE is often already tabbed. When rendering, tabs are replaced with spaces.

Code within a blockquote
To include code within a blockquote, make sure to include the space after the > as well as the four spaces before the code.
> Lorem ipsum dolor sit amet, consectetur adipiscing elit.
> for(;;)
echo 'badger ';
Or, put the blockquote character (and its following space) at the beginning of every blank line, including the one immediately before the code.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
>
for(;;)
echo 'badger ';
Code within a list
If your code appears inside a list, you must indent a further four spaces for every level of nesting.
- First bullet (is the deepest)
for(;;)
echo 'ow ';
- Second bullet
Syntax highlighting
Prettify is used to add colour to the code, but only if the language can be uniquely determined given the tags of the question, or if manual hints have been provided in HTML comments, using:
<!-- language: lang-or-tag-here -->
code goes here
<!-- language: lang-or-tag-here -->
code goes here
You can also specify the syntax for all codeblocks in your post with the language-all hint:
<!-- language-all: lang-or-tag-here -->
code goes here
More text not in code blocks
code goes here
See the full specification and list of languages hints.
Note that:
- The HTML comments must not be indented
- The blank line between
<!-- language: ... --> and the indented code block is required
- The space between
language: and the language is required
- When using a tag to specify language, the tag name is case-sensitive
If no language is defined then no highlighting occurs at all. But in the preview, or if multiple language tags define very different languages and no manual definition is used, a default highlighting is used in which Prettify makes a best guess.
There is a delay before the preview text highlighting is applied after you stop editing your markdown source, of around 5 seconds.
Using mobile devices
- One sometimes need to press and hold the regular single quote to get the backtick.
Backticks in text
- To include a backtick without accidentally starting some inline code, escape it:
\`
like \` so yields: like ` so
<kbd>Alt Gr</kbd>+<kbd>\`</kbd> gets `|` yields: Alt Gr+` gets |
Backticks within backticks
- To use literal backticks within a code span, use any unique number of multiple backticks as the opening and closing delimiters: both
``literal backtick (`) here`` and, for example, ``````literal backtick (`) here`````` yield literal backtick (`) here. This works in comments too.
- To use literal backticks at the start and/or end, add one space to both the opening and closing delimiters:
`` `<html>` `` yields `<html>`, and `` $` `` yields the Perl $` operator. In comments, the additional space in the delimiters is not supported. Instead, escape the backtick: `\`<html>\`` and `$\`` to get `<html>` or $` in a comment.