You wrote a README.md or a wiki page, pasted some terminal commands into it, and they show up as flat grey text. Or the colours are there on GitHub but missing in another viewer. The fix is the word you put right after the opening backticks.
To get a markdown bash code block, open the fence with three backticks and the tag bash, paste the commands, and close with three backticks. Use sh, shell or zsh for the same result, and console when you want to show a prompt followed by output. The tags below were checked against GitHub Linguist and the GitHub code block docs. Rendering of the samples was checked with two Markdown parsers (see the summary for what was not tested).
The animation shows the same three lines with no tag, with bash and with console.

- Command Pattern
- Shell – Using Console for bash/shell code in Markdown
- Bash – Using Bash/shell command in Markdown
- Which sites highlight which tags
- Powershell – Using the Powershell command in Markdown
- DOS – Using bat or cmd code blocks in Markdown
- Indented code blocks vs fenced code blocks
- Inline code and escaping backticks
- Make commands copy friendly
- Common mistakes
- Markdown bash code block cheat sheet
- Frequently asked questions
- Summary
The sections below cover these CLI tags, plus where each one is highlighted and the mistakes that switch highlighting off.
- Shell and Bash
- Console for prompt plus output
- Powershell
- DOS (bat, cmd)
Command Pattern
A fenced code block is three backticks, an optional language name (the info string), your code, and three closing backticks. The opening and closing lines must each sit on their own line. This is the general pattern for highlighting code in the language of your choice:
Tilde fences (~~~) work the same way in CommonMark, as long as the closing fence uses the same character and is at least as long as the opening one.
Shell – Using Console for bash/shell code in Markdown
Use console when the block is a terminal session: a prompt, the command, then what the tool printed. In GitHub Linguist console is an alias of the ShellSession language (together with bash session), which is why the prompt and the output get different treatment.
Example
GitHub preview

That is how the block looks with the syntax highlighter in GitHub.
Bash – Using Bash/shell command in Markdown
For scripts and commands that people will run, use bash (or sh). Both of these open the same Shell grammar on GitHub:
In Linguist the Shell language lists the aliases sh, shell-script, bash and zsh. Pick one tag and use it everywhere in the repository so the files stay consistent.

Which sites highlight which tags
There is no single Markdown highlighter. Each site picks its own, so the same tag can look different. This is what the official documentation says, and which rows could not be confirmed:
| Where | Highlighter and rule | Checked |
|---|---|---|
| GitHub (README, wiki) | Linguist decides the grammar. Valid keywords are in the languages YAML file. | Yes, GitHub docs and languages.yml |
| GitLab | Rouge library. Add the language after the three backticks. Inline code is not highlighted. | Yes, GitLab docs. Per-tag support: see the Rouge list |
| Azure DevOps wiki | highlight.js identifiers after three backticks. The Markdown dashboard widget shows plain text. | Yes, Microsoft Learn |
| Stack Overflow | highlight.js. The language is often inferred from the question tags, or set with lang-bash style tags. | Yes, editing help page |
| Bitbucket Data Center | CodeMirror. Add the language name after the backticks. | Yes for Data Center docs. Bitbucket Cloud page not reachable, so not verified |
| VS Code Markdown preview | Built-in preview of fenced blocks. | Not verified which tags are coloured. Open the preview and look |
Details worth knowing: GitHub documents that the identifiers are looked up in Linguist, and GitLab says it uses Rouge (GitLab Markdown docs). Azure DevOps points to the highlight.js language list (Azure DevOps Markdown guidance). In highlight.js, bash has the aliases sh and zsh, while the session style language answers to console and shellsession. That was read from the highlight.js source on its main branch, not from the exact version each site runs.
Powershell – Using the Powershell command in Markdown
PowerShell uses its own tag. In Linguist the aliases are posh and pwsh, and the file extension is .ps1. Do not put Linux commands in a powershell block, because the colours follow the PowerShell grammar:
DOS – Using bat or cmd code blocks in Markdown
For Windows batch files use bat (Linguist Batchfile aliases: bat, batch, dosbatch, winbatch). highlight.js also accepts dos and cmd, which is what Azure DevOps wikis and Stack Overflow use. Whether GitHub accepts cmd or dos as a tag was not verified, so prefer bat on GitHub.
Indented code blocks vs fenced code blocks
Markdown has two ways to make a code block. A fenced block uses backticks and accepts a language tag. An indented block is any run of lines indented by four spaces, and it has no place for a language, so it is never language-highlighted:
Azure DevOps documents the same behaviour: a line that starts with four spaces converts to a code block, and the docs recommend three backticks so you can name the language. Use fences for shell code.
Inline code and escaping backticks
For a command or a file name inside a sentence, wrap it in single backticks, like npm install. GitLab states inline code is never syntax highlighted, and a language tag cannot be added to it. So put anything longer than a short command in a fenced block.
To show the fence itself, for example in a style guide, wrap it in a longer fence. A closing fence must be at least as long as the opening one, so four backticks can contain three:
GitHub documents the same trick: wrap triple backticks inside quadruple backticks. If the code itself contains a line of three backticks (a shell heredoc that writes Markdown, for instance), use a fence of four or more, or switch to tildes.
Make commands copy friendly
- Keep prompts out of blocks people will paste. A
$at the start of a line is copied along with the command and then fails in the shell. - Split input and output. Put the commands in a
bashblock, then show the result in a separateconsoleorplaintextblock. - Use
\line continuation only at the end of a line, with nothing after it, so a pasted multi-line command still works. - Quote values that contain spaces or
$so the pasted line behaves the same in bash and zsh. - Use a comment line starting with
#above a command to explain it, instead of trailing text that would be pasted too.
Common mistakes
- Backticks not on their own line: the opening and closing fences must each start a line, with no text before them.
- Wrong tag spelling:
Bashmay work on one site and fail on another. Use lower case, as GitHub documents for GitHub Pages sites. - Indented block inside a list: an indented code block inside a list item needs more indentation. Prefer a fence indented to the list text.
- Tag that the site does not know: an unknown word still renders a code box, just without colours. Try
shorbashinstead. - Closing fence shorter than the opening: a three-backtick close does not end a four-backtick block, so the rest of the page turns into code.
- Smart quotes pasted from a word processor: curly quotes in the code break the command even if the colours are right.
Related posts: display a table in README.md, add JSON to a Git README and add images to README.md.
Markdown bash code block cheat sheet
| You want to show | Fence tag | Notes |
|---|---|---|
| A script or commands to run | bash (or sh, zsh) | Aliases of Shell in Linguist |
| Prompt plus output | console | ShellSession in Linguist; no prompt in code people copy |
| Output only | text or no tag | Not coloured |
| PowerShell | powershell (or pwsh) | Not for Linux commands |
| Windows batch | bat | cmd and dos are highlight.js aliases only |
| Fence inside a fence | Four backticks outside | Closing fence at least as long as the opening |
| Command inside a sentence | Single backticks | Never highlighted |
Frequently asked questions
What is the language tag for bash in a Markdown code block?
Write bash after the opening three backticks. sh, shell and zsh also work on GitHub, where they map to the same Shell grammar. Use console when the block shows a terminal session with a $ prompt and output.
How do I show a terminal prompt and its output in a Markdown code block?
Open the fence with console and start each command line with $ . Output lines follow without the prefix. If readers will copy the block, use a bash block for the commands and a separate console or plaintext block for the output.
How do I put triple backticks inside a Markdown code block?
Wrap the block in a longer fence. Four backticks on the opening and closing lines let you show three backticks inside, because a closing fence must be at least as long as the opening one. A tilde fence also works.
Summary
Open a fence with three backticks and a tag: bash for commands, console for a prompt with output, powershell and bat for the Windows shells. Each site chooses its own highlighter, so check the result where your readers will see it. Tested here: the sample README (bash, sh, shell, zsh, console, untagged, tilde, indented and four-backtick blocks) rendered with markdown-it-py and Python-Markdown, which confirmed the fences parse and carry the language name. Not tested: the actual colours on GitHub, GitLab, Azure DevOps, Bitbucket, Stack Overflow and VS Code, the copy button of each site, and Bitbucket Cloud.
That’s all. References: GitHub: creating and highlighting code blocks, Linguist languages.yml.
Found this useful?
Bookmark this page and share it with your team. Get new .NET, cloud and database tutorials in your inbox.
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!