Writing & Markdown

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:

LanguageIdentifier
Pythonpython
JavaScriptjavascript or js
TypeScripttypescript or ts
Gogo
Rustrust
HTMLhtml
CSScss
YAMLyaml
JSONjson
Bash / Shellbash or sh
Markdownmarkdown or md
LaTeXlatex

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 True

Highlight 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!")
```
hello.py
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?

From the makers of

© 2026 Lore Labs.

On this page