How to Share Code in Slack and Discord Without Breaking the Formatting
Updated November 5, 2026 · 7 min read
Slack and Discord both support code formatting, but it's easy to get wrong: paste code as normal text and you can lose indentation, get curly quotes, or trigger auto-formatting. Paste 200 lines and the whole channel scrolls away. Here's how to share short code properly in each app, and when to use a link instead.
The two kinds of code formatting
| Inline code | Code block | |
|---|---|---|
| Syntax | `npm install` (one backtick each side) | Three backticks on the lines before and after |
| Use for | A command, a variable name, a file path | Several lines of code, logs, JSON |
Slack
- Type
```to start a code block, or click the code block button in the formatting toolbar. - Paste your code. Use Shift + Enter for new lines if your settings send on Enter.
- Close it with
```and send.
- Inline code: wrap text in single backticks.
- Longer code: Slack also offers a text snippet option in the + (attachments) menu, which creates a collapsible snippet. Availability and naming depend on your Slack version and workspace settings.
- Reply in threads so code and discussion stay together.
Discord
- Type three backticks followed by the language name, then a new line:
```python def greet(name): return f"Hello, {name}" ``` - Discord applies syntax highlighting for common languages such as
js,python,json,bashandcss. - Messages have a length limit, so very long code may be split or turned into a file attachment.
Keep the formatting intact
- Always use backticks for code, so quotes and symbols aren't changed.
- Watch indentation: some apps convert tabs to spaces; that matters for Python and YAML. Check the result.
- Don't paste screenshots of code. Nobody can copy or search it.
- Edit your message if formatting comes out wrong, rather than posting again.
When to share a link instead
Chat is great for a few lines. For more, a snippet link is better:
- Long code or logs (more than about 15 to 20 lines) stays out of the channel's way.
- Line numbers let people say "line 37 is the bug".
- The raw view makes copying exact.
- One link works everywhere: Slack, Discord, a ticket, an email and a pull request.
- Formatting can't be mangled by any app along the way.
Paste the code into the code sharing tool, choose the language, and post the link with one sentence: "Login handler, the null check on line 18 never fires." Details in how to share code snippets online.
Etiquette for code in channels
- Say what you need: a review, a bug hunt, or an opinion.
- Include the error message as text.
- Remove keys, tokens and customer data before posting (how).
- Use threads for back-and-forth.
Sharing a screenshot of a UI problem instead? See sharing screenshots in Slack, Discord and Teams.
Line numbers, raw view, 23 language labels, no account. Paste once, share anywhere.
Frequently asked questions
How do I make a code block in Slack?
Type three backticks (```), paste your code, and close with three more backticks. You can also use the code block button in the formatting toolbar.
How do I get syntax highlighting in Discord?
Add the language name right after the opening backticks, for example ```python on the first line. Discord highlights many common languages.
Why do my quotes change in Slack?
Some setups and devices convert straight quotes into curly "smart" quotes outside code formatting. Put code inside backticks so it stays exactly as typed.
How long a code snippet should I paste into chat?
Up to about 15 to 20 lines is comfortable. Beyond that, share a snippet link so the channel stays readable and people can refer to line numbers.
Related articles
How to Share Code Snippets Online Without Breaking the Formatting
Share code so indentation survives: why chat apps mangle code, how to share a clean link with line numbers and a raw view, how to choose between a snippet link, a gist and a screenshot, and what to remove first.
Read More →Sharing Screenshots in Slack and Discord with Direct Image Links
Share screenshots in Slack and Discord as links instead of uploads: when to use a direct image link, how previews work, and tips for cleaner threads.
Read More →How to Share an Error Log, Stack Trace or Terminal Output So Someone Can Help
How to capture and share logs, stack traces and terminal output properly: copying the full output, saving it to a file, trimming to what matters, removing secrets, and sharing a link with line numbers.
Read More →