Code Blocks
Code blocks display multiple lines of code with proper formatting and optional syntax highlighting.
Fenced Code Blocks
Use triple backticks to create a code block:
\`\`\`
function hello() {
console.log("Hello, World!");
}
\`\`\`
Syntax Highlighting
Add the language name after the opening backticks:
\`\`\`javascript
const name = "Markdown";
console.log(`Hello, ${name}!`);
\`\`\`
Common Language Identifiers
| Language | Identifier |
|---|---|
| JavaScript | javascript or js |
| TypeScript | typescript or ts |
| Python | python or py |
| HTML | html |
| CSS | css |
| Bash/Shell | bash or sh |
| JSON | json |
| Markdown | markdown or md |
Indented Code Blocks
You can also create code blocks by indenting with 4 spaces:
function hello() {
return "world";
}
⚠️ Fenced code blocks (with backticks) are preferred over indented code blocks.
Best Practices
- Always specify the language for syntax highlighting
- Keep code blocks focused and short
- Add comments in your code for clarity
💡 Code blocks are essential for documentation, tutorials, and README files!