Code Blocks
Add syntax-highlighted code blocks with line highlighting, filenames, diff output, and 100+ languages in Hugo Markdown.
Basic Code Block
Wrap code in triple backticks with an optional language identifier:
```python
def hello():
print("Hello, world!")
```def hello():
print("Hello, world!")Supported Languages
Common languages are highlighted automatically. Some popular examples:
| Language | Identifier |
|---|---|
| Python | python |
| JavaScript | javascript or js |
| TypeScript | typescript or ts |
| Go | go |
| Rust | rust |
| HTML | html |
| CSS | css |
| YAML | yaml |
| JSON | json |
| Bash / Shell | bash or sh |
| Markdown | markdown or md |
| LaTeX | latex |
For non-standard languages, you may need to enable them in your configuration.
Line Highlighting
Highlight specific lines to draw attention:
```python {2}
def hello():
print("Hello, world!") # This line is highlighted!
return True
```def hello():
print("Hello, world!") # This line is highlighted!
return TrueHighlight Ranges
```js {1, 3-5}This highlights line 1 and lines 3 through 5.
Inline Code
Use single backticks for inline code:
Run `npm install` to install dependencies.Run npm install to install dependencies.
Inline Code with Backticks
If your code contains backticks, use double backticks:
Use `` `code` `` for inline code.Code Block Titles
Add a title to your code block to show the filename:
```python title="hello.py"
def hello():
print("Hello!")
```def hello():
print("Hello!")Diff Syntax
Show additions and removals with the diff language:
```diff
- const old = "before";
+ const new = "after";
const unchanged = "same";
```- const old = "before";
+ const new = "after";
const unchanged = "same";Ownable uses Expressive Code for code blocks, which provides syntax highlighting, line highlighting, code titles, and more out of the box.
Was this page helpful?
Callouts
Add NOTE, TIP, WARNING, and CAUTION callout boxes (admonitions) to highlight important information in Hugo Markdown.
Math (LaTeX)
Write inline and block mathematical expressions with LaTeX syntax — fractions, matrices, summations, and Greek letters rendered with KaTeX in Hugo.
From the makers of
© 2026 Lore Labs.