Markdown Code Blocks: Languages, Highlighting, and Tips
Code blocks are the backbone of technical documentation. Done right, they make your content instantly credible and easy to follow.
Fenced vs. Indented
Always use fenced ā it supports language identifiers for syntax highlighting:
markdown```javascript
const hello = "world";
Indented blocks (4 spaces) are legacy ā avoid them.
## Language Identifiers
### Web
`html`, `css`, `javascript`/`js`, `typescript`/`ts`, `jsx`, `tsx`
### Backend
`python`/`py`, `ruby`/`rb`, `go`, `rust`, `java`, `kotlin`, `csharp`/`cs`, `php`
### Data & Config
`json`, `yaml`/`yml`, `toml`, `xml`, `sql`
### Shell
`bash`, `sh`, `zsh`, `powershell`
### Special
`diff` (shows + / - highlighting), `markdown`/`md`, `text` (no highlighting)
## Diff Blocks
```diff
function greet(name) {
- return "Hello, " + name;
+ return `Hello, ${name}!`;
}
Lines with - highlight red, + highlight green.
Inline Code
Use backticks for single values, function names, file paths:
markdownCall `authenticate()` before making requests.
The config lives in `~/.config/myapp/settings.json`.
Set `NODE_ENV=production` before deploying.
Use inline code for: function names, variables, file names/paths, CLI commands, env variables, HTTP methods, status codes
Don't use for: technology names (React, Node.js), general emphasis
Writing Good Examples
Use Realistic Values
typescript// Bad
const user = getUser("user_id");
// Good
const user = await getUser("usr_8f3kA9xm");
Show Expected Output
bashnpm run build
textā Compiled successfully ā 24 pages generated ā Build complete in 3.2s
Comment the Non-Obvious
bash# Decode a base64-encoded Kubernetes secret
echo "c2VjcmV0" | base64 --decode
Common Mistakes
Missing language identifier ā always specify. An unspecified block renders as plain text.
Nesting backticks ā if your code contains backticks, use more fences:
markdown
Code with backticks inside
Real credentials in examples ā never put API keys or passwords. Use YOUR_API_KEY placeholders.
Quick Reference
| Goal | Syntax |
|---|---|
| JavaScript block | js |
| Shell command | bash |
| Show changes | diff |
| No highlighting | text |
| Inline code | \code`` |
Preview your code blocks live in MarkGenie ā syntax highlighting renders in real time.