How to Format Code Blocks in Microsoft Teams
Teams code blocks need the built-in Code snippet control or an exact typed sequence. Pasted triple backticks stay literal. Convert first so code arrives as a monospace block.
Direct answer
Teams does not turn pasted triple backticks into a code block. Typing three backticks in the compose box triggers the built-in code control, but pasting them does not. Convert your Markdown here: fenced blocks become a preformatted monospace block with a light background, and Copy Rich pastes them into Teams as formatted code rather than as raw backticks.
Open Markdown to Teams converterWhen to use this
- A pasted snippet in Teams shows ``` characters around the code.
- Code loses its indentation and line breaks when shared in a channel.
- You are sending a command, log excerpt, or config block to a teammate.
Steps
- Wrap the code in triple backticks in the Markdown input box.
- Keep the rest of the message in the same input so it converts in one pass.
- Press Copy Rich.
- Paste into the Teams compose box.
- For long code, use the Teams Format menu's Code snippet control instead, which adds syntax highlighting.
Example conversion
Run this on the box before you page anyone: ```bash kubectl -n prod get pods | grep checkout ``` If `CrashLoopBackOff` appears, roll back with `helm rollback checkout`.
<p style="font-family:'Segoe UI',system-ui,sans-serif;font-size:14px;line-height:1.5;color:#242424;margin:10px 0;">Run this on the box before you page anyone:</p> <pre style="font-family:Consolas,'Courier New',monospace;font-size:13px;background:#f6f8fa;padding:12px;border-radius:4px;border:1px solid #e1e4e8;white-space:pre-wrap;margin:12px 0;">kubectl -n prod get pods | grep checkout</pre> <p style="font-family:'Segoe UI',system-ui,sans-serif;font-size:14px;line-height:1.5;color:#242424;margin:10px 0;">If <code style="font-family:Consolas,'Courier New',monospace;font-size:13px;background:#f3f3f3;padding:2px 5px;border-radius:3px;">CrashLoopBackOff</code> appears, roll back with <code style="font-family:Consolas,'Courier New',monospace;font-size:13px;background:#f3f3f3;padding:2px 5px;border-radius:3px;">helm rollback checkout</code>.</p>
Common mistakes
- Do not expect syntax highlighting from the paste. The output is monospace with a background, not a highlighted snippet.
- Do not paste code into chat without a code block. Teams collapses runs of spaces and can mangle indentation.
- Do not rely on the language tag after the opening fence. It is used to end the fence correctly but does not colour the output.
FAQ
- Why do backticks stay visible in Teams?
- Teams applies its typed shortcuts to keystrokes, not to clipboard content. Pasted backticks are just characters, so they stay on screen.
- Does inline code work?
- Yes. Single-backtick spans become an inline code element with a monospace font and a light background, which Teams keeps on paste.
- Should I use the Teams Code snippet control instead?
- For a long file, yes — it adds highlighting and a copy button. For a short command inside a normal message, the rich paste keeps everything in one message.
- Do line breaks inside the code survive?
- Yes. The code block preserves the original line breaks and spacing because the output uses a preformatted element with wrapping enabled.
Related Teams guides
How to Paste Markdown Into Microsoft Teams
Teams does not parse Markdown on paste, so **bold** and [link]() stay literal. Convert to rich HTML, press Copy Rich, then paste into the Teams compose box.
How to Send ChatGPT Output in a Teams Message
AI answers are Markdown. Pasted into Teams they show raw ## and ** characters. Convert the answer to rich HTML and paste it as formatted text.
How to Put a Markdown Table Into Teams
Pipe tables paste into Teams as rows of vertical bars. Convert the table to real HTML table markup first, then paste as rich text.
Why Microsoft Teams Does Not Render Markdown
Teams uses a rich-text editor with a few typed shortcuts, not a Markdown parser. That is why pasted syntax stays literal — and why a rich-text paste fixes it.