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 Teams format icon in the compose box, then select Code Block Code block button icon..  

Select a language 

  1. 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. 

  2. 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 Microsoft Teams more options icon inside the code block. Then select Wrap text under Display option in the code block. 

Make it collaborative 

Turn your code block into a Loop component before sending it so anyone in the chat can edit it.

  1. Before sending the code, select More options Microsoft Teams more options icon inside the code block.

  2. 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. 

Related topics

Send code snippets in a message in Microsoft Teams

Use Markdown formatting in Microsoft Teams

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.