Code blocks

Code blocks allow you to display code in your documentation with proper formatting and syntax highlighting.

Syntax

Code blocks in MyST Markdown are created using the triple backtick syntax. The general format is:

```{language}
Your code here
```

Examples

Python

```{python}
def hello_world():
    print("Hello, world!")
```

Renders:

def hello_world():
    print("Hello, world!")

Bash

```{bash}
echo "Hello, world!"
```

Renders:

echo "Hello, world!"

JavaScript

```{javascript}
console.log("Hello, world!");
```

Renders:

console.log("Hello, world!");

See also


Last update: 29 Jan 2025