Use code blocks in Microsoft Teams
Code blocks let you share and edit code within the compose box of Microsoft Teams. You can use code blocks to share any kind of code, like Java, Python, or Bash. They're different from code snippets and let you share and edit code more easily.
Important: You'll no longer be able to create code snippets beginning May 30, 2025, but you can still view those that have already been created.
Insert a code block
You can add a code block to your message in a few different ways:
-
Slash Command: Type /code in the compose box.
-
Keyboard Shortcut: Select Ctrl + Shift + Alt + B.
-
Markdown: Type three backticks (```) in the compose box.
You can also select Show Formatting options
Select a language
-
Once you insert a code block, select the dropdown to choose your language (such as Python or Plain Text) from the list of languages.
Note: There’s no need to choose a language every time you share code. Code Block remembers the last language you used.
-
The code block will format the code using syntax highlighting based on the chosen language.
Tip: If the syntax highlighting isn't working, check that you've selected the right language for your code.
Write and edit code
Write and edit code directly in the compose box. Once you're done, select Send to send the message.
Note: Anyone can copy the code directly from a sent message.
Wrap text
If your code has long lines, you can wrap the text. This keeps the code block from getting too wide.
Make it collaborative
Turn your code block into a Loop component before sending it so anyone in the chat can edit it.
-
Before sending the code, select More options
inside the code block. -
Select Make this collaborative.
Note: You'll only see the option to make it collaborative before sending the code block. If you're having trouble with collaborative editing, make sure everyone has the necessary permissions to edit Loop components.