@mdo

Formatting code on GitHub

April 23, 2013

I see a fair number of issues, pull requests, and comments on GitHub from folks who don’t know how to highlight snippets of code. While this is a problem in it’s own right and we should solve that, I figure I’d drop some knowledge until we figure that other stuff out at GitHub.

Inline code

Inline code is wrapped in backticks—the ``` character.

This is an example of inline ```.

Unlike normal HTML, there is no need to escape angle brackets—GitHub Flavored Markdown does that for you.

Code blocks

Multiple lines of code are easily created by placing three backticks before and after a code block.

```
.element {
  ...
}
```

Language-specific code blocks

You can optional specify a language for proper syntax highlighting on code blocks. Just add the language identifier after the first set of backticks.

```css
.element {
  ...
}
```

Further reading

More of the GitHub Flavored Markdown nuances are documented on the GitHub Help site. Check it out for information on autolinking, task lists, Emoji, and more.