Code blocks in Markdown
Use single backticks for short inline snippets, and triple-backtick “fences” for multi-line code blocks. Add a language after the opening fence for syntax highlighting.
Inline code
Use `inline code` inside a sentence with single backticks.
Use inline code inside a sentence with single backticks.
Fenced code block with a language
Put the language name right after the opening ``` (e.g. python, js, bash):
```python
def greet(name):
return f'hello {name}'
```def greet(name):
return f'hello {name}'
Plain fenced block
Omit the language for plain, unhighlighted text:
``` plain code block — no language, no highlighting ```
plain code block — no language, no highlighting
Good to know
- To show literal backticks inline, wrap with a longer run of backticks, e.g.
`` `code` ``. - Fenced blocks preserve whitespace and never apply other Markdown formatting inside.
Related: full cheat sheet · live editor.
Have a document instead of text?
Convert PDFs, Word, PowerPoint, Excel, and images into clean Markdown — free, no signup.
Convert a file to Markdown →