Back to Blog
Guide

How to Make a Code Block in Slack: Backticks, Shortcut 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
October 3, 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.

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

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.

In Block Kit, put the code in a section block with text type mrkdwn; a plain_text object shows the backticks as typed. 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

    Guide

    Slack Bot Scopes: The Scope Each API Method Needs, Measured on 44 Methods

    We gave a Slack bot one scope, called 44 common Web API methods, and read the needed field of every missing_scope error. Then we added the scopes and called them again. The table shows which scope clears each method.

    Slack Green Team
    Guide

    Slack File Size Limit: 1 GB Is Exactly 1,073,741,824 Bytes, Tested

    We uploaded files of 50 MB, exactly 1 GiB and 1 GiB plus one byte to Slack through its upload API. The limit is 1,073,741,824 bytes, and a failed upload can still leave a broken file behind.

    Slack Green Team
    Guide

    Slack Dark Mode: Where the Setting Is, and Which Custom Emoji Disappear

    Slack's dark mode is under Preferences > Appearance > Color Mode, with Light, Dark and System. We switched modes in Slack web with three test emoji and measured which ones vanish.

    Slack Green Team