Code blocks
Code blocks are fenced spans of code, optionally tagged with a language for syntax highlighting and a custom title.
When to use
Use a fenced code block for anything a reader would copy, run, or read as code: commands, source code, configuration, query text, or file contents. For a short literal inside a sentence (a flag, a field name, a value), use inline code with single backticks instead.
Technical details
Open and close a code block with a line of three backticks. Immediately after the opening backticks, add an info string that configures the block:
- Language tag (the first word) drives syntax highlighting, for example
sql,python,bash,scala,json, oryaml. Commonly used ones render with the correct coloring. With no tag, the block renders as plain, unhighlighted text. title="..."sets the label shown in the block's title bar, overriding the default. The language tag still controls highlighting, sosql title="PostgreSQL"gives SQL coloring under a "PostgreSQL" title. Quote the value whenever it contains spaces.- Line highlighting with
{2,4-6}visually emphasizes the listed lines (line2and lines4through6).
These options combine on one info string, for example ```sql title="Lakebase SQL" {2}.
To show a code block inside a code block (for example, when documenting Markdown itself), fence the outer block with four backticks so the inner three-backtick fence doesn't close it early.
Rules
- Tag the language whenever the content has one, so readers get syntax highlighting.
- Quote a
titlevalue that contains spaces:title="Lakebase SQL", nottitle=Lakebase SQL. - When an example contains a three-backtick fence, wrap it in a four-backtick fence.
- Don't add a trailing prompt character (
$,>) to commands the reader is meant to copy.
Style
- Set
title=to a name the reader recognizes (PostgreSQL,Python,Bash) rather than the lowercase highlighter tag. - Keep examples minimal and, where practical, runnable — show only the lines that matter to the point.
- Use one language per block; split mixed content (for example, a command and its output) into separate blocks or tabs.
Template
```sql title="Lakebase SQL"
SELECT * FROM orders WHERE status = 'open';
```
Examples
Example:
Plain block, no highlighting:
```
databricks pipelines list
```
Language tag adds syntax highlighting:
```python
df = spark.read.table("main.default.orders")
```
Custom title over SQL highlighting:
```sql title="Lakebase SQL"
SELECT * FROM orders WHERE status = 'open';
```
Title plus line highlighting:
```python title="ETL job" {2}
raw = spark.read.table("main.default.raw_events")
clean = raw.dropDuplicates(["event_id"])
```
Show a code block inside a code block with a four-backtick outer fence:
````markdown
```python
print("hello")
```
````
Output:
Plain block, no highlighting:
databricks pipelines list
Language tag adds syntax highlighting:
df = spark.read.table("main.default.orders")
Custom title over SQL highlighting:
SELECT * FROM orders WHERE status = 'open';
Title plus line highlighting:
raw = spark.read.table("main.default.raw_events")
clean = raw.dropDuplicates(["event_id"])
Show a code block inside a code block with a four-backtick outer fence:
```python
print("hello")
```
Used in
Content atoms appear in any page section. Code blocks are especially common in Procedure steps, tutorials, and SQL reference pages.