Why specify a language?
Mintlify uses the language identifier after the opening backticks to apply syntax highlighting. Without it, the code renders as plain monospace text.Example with and without a language tag
- Shell and commands:
bash,sh,powershell - Languages:
python,javascript,typescript,go,ruby,java,sql - Data and config:
json,yaml,toml - Markup and styles:
mdx,html,css - Plain output:
text
Filenames and titles
A filename tells readers where this code lives in their project. A title tells them what it does if a filename doesn’t apply.Example code block with a filename
docs.json appears as a label on the code block. Readers know immediately that this is what goes in the docs.json file.
Use a filename when the code belongs in a specific file. Use a descriptive title when the code is a command or snippet without a natural filename.
Example code block with a descriptive
Draw attention to the lines that matter
When a code block is long and you want to emphasize a few lines, usehighlight with the line numbers or ranges.
Example line highlighting
focusdims every line except the ones you name. Use it when the surrounding lines are context the reader needs to see but not study.- Diff markers show lines as added or removed. Add
[!code ++]or[!code --]in a comment at the end of a line. Use them when you’re showing a change to existing code, like an upgrade guide.
Example diff
The copy button
Mintlify adds a copy button to code blocks automatically. Users running commands from documentation expect to paste them directly. If the code has a trailing space, a curly quote instead of a straight quote, or wraps in a way that introduces a line break, the command won’t run and users won’t know why. Write commands exactly as they should be typed without extra spaces or decorative characters. Test them before publishing. Some code blocks aren’t meant to be copied, like terminal output or an ASCII diagram. Addnocopy to hide the copy button so readers don’t paste output as if it were a command.
Keep examples short
Code blocks that contain more than the reader needs force them to figure out which parts apply and which are setup they already did. When showing a configuration change, show only the relevant section, and tell readers where it goes.Example of only part of a config file
expandable so the block starts collapsed and readers can open it if they need the whole thing.
Next up: When to explain code and when to just show it—how to place code blocks within explanations so readers understand what to do and why.