Code Blocks
Syntax highlighting, line highlighting, colored diffs, focus, and line numbers
VitePress uses Shiki for syntax highlighting with powerful code block features.
Syntax Highlighting
Specify language after opening backticks:
```js
export default {
name: 'MyComponent'
}
```
Supports all languages available in Shiki.
Line Highlighting
Highlight specific lines:
```js{4}
export default {
data() {
return {
msg: 'Highlighted!' // Line 4 highlighted
}
}
}
```
Multiple lines and ranges:
Inline highlighting with comment:
Blur other code and focus specific lines:
Focus multiple lines:
Show additions and removals:
Errors and Warnings
Color lines as errors or warnings:
Enable globally:
Per-block override:
Start from specific number:
Tabbed code blocks:
Import Code Snippets
From external files:
With highlighting:
Specific region:
With language and line numbers:
In code groups:
Add filename labels to code blocks:
Use // [!code highlight] for inline highlighting
Use // [!code focus] to focus with blur effect
Use // [!code ++] and // [!code --] for diffs
Use // [!code error] and // [!code warning] for status
:line-numbers and :no-line-numbers control line numbers per block
@ in imports refers to source root
Code groups create tabbed interfaces