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.
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Â on Windows and web. Select Cmd + Shift + Option + B on Mac.Â
-
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.Â
To wrap text, select More options
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.
Notes:Â
-
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.
-
If you paste code that has more than 30,000Â characters into a code block, it will be converted to a collaborative code block. This allows you and others to see all the code you want to share while maintaining syntax highlighting.