Markdown Code Blocks
Inline code, fenced blocks, and language highlighting
Code in Markdown runs on one character: the backtick. One backtick around a word makes inline code; three backticks above and below make a multi-line block. That's the whole idea.
AI answers are full of code blocks — ChatGPT and Claude fence almost every snippet — so understanding them helps you read, edit, and keep that code. This article covers inline code, fenced blocks, adding a language for highlighting, and why a block sometimes won't render.
New to the syntax overall? Start with How to Write Markdown.
The three ways to show code
| Type | How | When to use |
|---|---|---|
| Inline code | Wrap in single backticks | A command, filename, or short snippet inside a sentence |
| Fenced code block | Three backticks on their own line, above and below | Multi-line code, kept exactly as typed |
| Fenced block + language | Add the language name after the opening fence | Multi-line code you want highlighted (where supported) |
All together — note the backticks are the whole trick:
Inline code uses single backticks:
Run `npm install` first.
A fenced block uses three backticks, with an optional language:
```js
function hello() {
console.log("hi");
}
```
The "js" after the opening fence sets the language for
syntax highlighting (in renderers that support it). Inline code vs a fenced block
- Inline code stays in your sentence — use it for a single command, a
filename.md, or a short value. Wrap it in one backtick on each side. - A fenced block stands on its own — use it for anything multi-line. Everything inside is kept verbatim; Markdown formatting is switched off inside a code block, so your
#,*, and_show as-is.
Adding a language for highlighting
Write the language name right after the opening fence — js, python, bash, and so on. Renderers that support highlighting will colorize the code; the tag itself doesn't change anything, it just labels the language. It's optional, but it makes longer snippets much easier to read.
Why your code block isn't rendering
| Symptom | What happened | Fix |
|---|---|---|
| Block didn't render as code | The opening or closing fence is missing or uneven | Put exactly three backticks on their own line, top and bottom |
| No syntax highlighting | No language after the opening fence | Add the language name right after the opening fence (js, python, …) |
| Code itself contains a fence | Your code has a run of three backticks in it | Fence the whole block with four backticks instead of three |
| Inline code cut off early | A backtick appears inside your inline code | Wrap it in double backticks so the inner one is literal |
The number-one cause: an unbalanced fence. The opening and closing lines each need to be their own line of backticks, with nothing else on them — a stray space or a missing closing fence and the rest of your document turns into code.
Reading and writing code blocks with NoteLoom
Open a .md full of code in Notepad and you get a wall of raw backticks. NoteLoom is an editor that reads and writes local md files right in the browser: its reading view renders fenced blocks as clean monospace blocks, and its source view lets you get the fences right when you write them.
To be clear about the boundaries: NoteLoom has no AI — it won't write code, run it, or explain it. It opens, displays, and saves your local Markdown; the code is yours.
This comes up a lot with the rules files AI coding tools use — AGENTS.md and CLAUDE.md are full of commands and code. Open the folder in NoteLoom, read the blocks cleanly, and edit them in the source view — saved straight back to your disk, no cloud, no account.
FAQ
How do I write inline code in Markdown?
How do I write a multi-line code block?
How do I get syntax highlighting?
Why isn't my code block rendering?
My code contains three backticks — how do I show it?
Can NoteLoom help me read and write code blocks?
Can I do this with NoteLoom on my phone or in Safari?
Read your code blocks without the raw backticks
Open NoteLoom in Chrome / Edge / Arc, mount a local folder, and open any .md — the reading view renders fenced code cleanly, and the source view lets you fix the fences. Saved straight back to your disk, no software to install and no account to sign up for.