How To Show Code In Slack

Slack is a popular tool for team collaboration, enabling seamless communication and cooperative work. A standout feature of Slack is its facility for sharing code snippets, proving invaluable during discussions of technical matters or when diagnosing problems. In this guide, I aim to show you the process for displaying code in Slack, and I’ll be offering my own tips and insights throughout.

Step 1: Formatting your code

Before you can share code in Slack, it’s important to format it properly so that it remains readable and easy to understand. There are a few different ways you can do this.

Inline code

If you want to highlight a short snippet or a few lines of code within a sentence or paragraph, you can use backticks (`) to enclose the code. For example, `print("Hello, world!")` will display as print("Hello, world!").

Code blocks

For longer sections of code, it’s best to use code blocks. To create a code block in Slack, simply start a new line with three backticks (“`) followed by the programming language to specify syntax highlighting. Then, paste your code on the next lines and end the code block with three backticks. Here’s an example:

def greet():
    print("Hello, world!")

This will display the code block with syntax highlighting, making it much easier to read and understand.

Step 2: Sharing code in Slack

Once you have formatted your code, it’s time to share it in Slack. There are a couple of ways you can do this.

As a message

If you want to share code as a standalone message, simply copy and paste the formatted code into the message field. Slack will automatically detect the code formatting and display it as a code block. You can add additional context or explanation above or below the code as needed.

As a snippet

If you want to share code that you want to refer back to later or share with others in a more organized manner, you can create a code snippet in Slack. To do this, click on the “More actions” (three dots) button in the message input field and select “Create a snippet”.

A new window will appear where you can enter the snippet details, including the snippet title, description, and programming language. You can also specify who can access the snippet. Once you’ve entered all the details, click “Create snippet” and then paste your formatted code into the snippet.

Step 3: Adding comments and context

When sharing code in Slack, it’s often helpful to add comments or provide some context to help others understand what the code does or why you’re sharing it. You can do this by adding additional text before or after the code snippet, or by using inline comments within the code itself. This extra information can make your code more understandable and can save others time when trying to figure out its purpose.


Sharing code in Slack is a great way to collaborate with your team and discuss technical concepts. By following these steps and formatting your code properly, you can ensure that your code remains readable and easy to understand. Don’t forget to add comments and context to provide additional clarity. Happy coding!