Back to Blog
Guide

Slack Code Block: Shortcut, Syntax Highlighting and Snippets

Type three backticks in the Slack message field or press Cmd+Alt+Shift+C. We tested what happens to a language name after the backticks, made a real highlighted snippet, and found that bot code blocks over 4,000 characters split and stop rendering.

Slack Green Team
September 27, 2026
November 9, 2026
4 min read
Share:
slack
formatting
code block
slack tips
developers

To make a code block in Slack, type three backticks in the message field. The field turns into a gray code block right away; paste or type your code and press Enter to send. You can also select text and press Cmd+Alt+Shift+C on a Mac (Ctrl+Alt+Shift+C on Windows), or click the Code block button in the formatting toolbar. For a command inside a sentence, wrap it in one backtick on each side for inline code, like npm ci. A code block has no syntax highlighting; for colored code, send a snippet, as shown below.

We tested each of these in Slack on 3 October 2026, in a direct message to ourselves, and read back how Slack stored the messages. The test messages and the snippet were deleted afterwards.

Three ways to start a code block

What you doWhat happened in our test
Type three backticksThe field became a code block as soon as the third backtick was typed
Select two lines, press Cmd+Alt+Shift+CBoth lines became one code block
Type a word between single backticksInline code, inside the sentence

Press Shift+Enter for a new line inside the block; plain Enter sends it (see how to add a new line in Slack). Slack stores a sent code block as a rich_text_preformatted element, so your spacing and line breaks stay exactly as typed. The font is Roboto Mono (what font Slack uses). In a canvas the code block shortcut is the same, Cmd+Option+Shift+C; Slack canvas shortcuts has the rest.

If Format messages with markup is on under Preferences, Advanced, the field does not change while you type. Wrap the code in three backticks at both ends, and Slack formats it when you send:

```
git pull
pnpm install
pnpm test
```

Can a Slack code block have syntax highlighting?

No. A message code block has no language setting. We typed the GitHub way, three backticks and then python, and Slack kept the word as the first line of the block:

A Slack code block whose first line is the word python, followed by print("hello"), because Slack does not read a language name after the backticks

For colored syntax, send a snippet instead:

  • Click the + button in the message field and choose Text snippet, or press Cmd+Shift+Enter (Ctrl+Shift+Enter).
  • Give it a title, such as greet.py. Type starts on Auto Detect Type; you can pick a language there.
  • Paste the code into Content, keep Share this file ticked, and click Create Snippet.
  • Our snippet came out like this. Slack detected Python on its own, numbered the lines, and added an arrow next to the title that collapses the snippet:

    A real Slack snippet named greet.py with line numbers 1 to 4 and Python syntax colors, and a collapse arrow next to the title

    Through the API, the snippet was a file with mode: snippet, filetype: python and lines: 4. Message code blocks have no collapse control: a 40-line block posted in our test showed all 40 lines, 738 pixels tall. Long logs belong in a snippet. Slack's help center says snippets cannot be created in the mobile apps.

Never appear "away" on Slack again

Cloud-based. No downloads. Works 24/7 even when your laptop is off.

Code blocks in bot and API messages

Three backticks in the text field of chat.postMessage or an incoming webhook become a code block, because Slack reads that field as mrkdwn:

curl -X POST -H 'Content-type: application/json' \
  --data '{"text":"Deploy failed:\n```npm ERR! code ELIFECYCLE```"}' \
  "$SLACK_WEBHOOK_URL"

That breaks for long code. Slack splits a text-only message at about 4,000 characters, and the split does not respect your backticks. We posted a 150-line block of 5,285 characters. It arrived as two messages of 3,988 and 1,297 characters, and neither was a code block: both showed the raw backticks. Read back from the API:

message 1: 3,988 chars, starts "API test, 150-line code block:\n```line 001 ...", block type rich_text_section
message 2: 1,297 chars, ends "line 150: npm ERR! code ELIFECYCLE```",           block type rich_text_section

A 40-line block of 1,395 characters in the same test rendered fine. For long output from a bot, upload it as a file or snippet, or split it yourself into blocks under 4,000 characters. Limits for every message type are in Slack message character limit. Our Python logging handler and winston formatter wrap each stack trace in backticks this way and cut it at 3,500 or 3,000 characters, under that split. Our Django error alert does the same with a 2,500-character cap.

In Block Kit, put the code in a section block with text type mrkdwn; a plain_text object shows the backticks as typed. Slack draws inline code in red, which is why a text progress bar wrapped in backticks looked like an error in our test. Escape &, < and > as &amp;, &lt; and &gt; inside the code. To convert a GitHub-style markdown file with fenced code, use our Markdown to Slack converter.

Slack code block not showing

  • • Raw backticks while typing. Format messages with markup is on, so formatting appears after you send. Turn it off under Preferences, Advanced, Input Options.
  • • The wrong character. Three apostrophes or curly quotes do nothing. On German, French and some other layouts the backtick is a dead key: press it, then Space.
  • • A long bot message. Over about 4,000 characters, Slack splits it and the code block falls apart, as in the test above.
  • • A plain_text field in Block Kit. Switch it to mrkdwn.
  • FAQ

    How do I get out of a code block in Slack?

    Slack's help center says to click the Code block button in the toolbar again; the next text you type is normal text.

    Can I make a code block on my phone?

    Yes, by typing three backticks (on iPhone, hold the apostrophe key on the 123 keyboard) or with the code block button under Aa. We did not test the mobile apps; snippets are desktop only.

    Always Active

    Stop Jiggling Your Mouse.

    Join hundreds of remote workers who never worry about their Slack status. Set it up once, stay green forever.

    Related Articles

    Troubleshooting

    Slack Formatting Toolbar Missing? How to Get It Back

    The Slack formatting toolbar hides when you click Aa, and Slack remembers it. With Format messages with markup on, the toolbar and the Aa button both vanish. Tested fixes, the 10 buttons and their shortcuts.

    Slack Green Team
    Guide

    Slack Message Character Limit: 40,000 Max, 4,000 Advised

    Slack keeps up to 40,000 characters in a message's text and truncates anything longer, and its developer docs advise staying under 4,000 characters. Block Kit sections stop at 3,000 characters and headers at 150. What happens with long messages, other Slack text limits, and how to split a long post.

    Slack Green Team
    Guide

    How to Add a Hyperlink in Slack: Paste, Shortcut or Markup

    To add a hyperlink in Slack, copy the URL, select the words in your message, and paste with Cmd+V or Ctrl+V. Or select the words and press Cmd+Shift+U (Ctrl+Shift+U) to add the link. Markup mode, bot and webhook syntax, mobile, and how to change or remove link text.

    Slack Green Team