Back to Blog
Guide

How to Make a Code Block in Slack: Backticks, Shortcut and Snippets

Type three backticks in the Slack message field, then paste or type your code and send. The shortcut is Cmd+Alt+Shift+C on Mac and Ctrl+Alt+Shift+C on Windows. Inline code, snippets with syntax highlighting, mobile steps, bot messages and fixes when a code block does not show.

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

To make a code block in Slack, type three backticks in the message field. Slack turns the field into a gray code block. Paste or type your code, then press Enter to send. You can also select text and press Cmd+Alt+Shift+C on a Mac or Ctrl+Alt+Shift+C on Windows and Linux, or click the Code block button in the formatting toolbar. For one command inside a sentence, wrap it in a single backtick on each side to get inline code, like npm ci.

The backtick is the key left of 1 on a US keyboard. Slack code blocks keep your spacing and line breaks and use a monospace font. They do not color the syntax. For highlighting by language, use a snippet, covered below.

We build Slack Green, which keeps your Slack status green from our servers during the hours you set. We also make free Slack formatting tools: the Markdown to Slack converter turns GitHub markdown, fenced code included, into text Slack formats correctly.

How to make a code block in Slack: type three backticks, press Cmd+Alt+Shift+C, or use the Code block button

Three ways to make a code block in Slack

Three ways to start a Slack code block: type three backticks, formatting toolbar, keyboard shortcut, markup preference

Type three backticks. Click in the message field of a channel, DM or thread and type three backticks. The field switches to a code block right away. Paste your code. Press Shift+Enter to add lines inside the block without sending (more on that in how to add a new line in Slack).

Use the formatting toolbar. Paste your code first, select it, and click the Code block button in the toolbar under the message field. Slack's help center lists Code block next to Bold, Italic, Underline, Strikethrough, Code, Block quote and the two list buttons. Click the button again to leave the block.

Use the keyboard shortcut. Select the text and press:

FormatMacWindows and Linux
Code blockCmd+Alt+Shift+CCtrl+Alt+Shift+C
Inline codeCmd+Shift+CCtrl+Shift+C
New line without sendingShift+EnterShift+Enter
Turn typed text into a snippetCmd+Shift+EnterCtrl+Shift+Enter

These come from Slack's own shortcut list. More are in our Slack keyboard shortcuts guide.

If you turned on Format messages with markup in Preferences, Advanced, Slack hides the toolbar and applies formatting only after you send. Then you wrap the code in three backticks at both ends, like this:

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

Inline code vs code block vs snippet

Inline code, code block or snippet compared: markup, best use, syntax highlighting, mobile, shortcut

  • • Inline code (one backtick on each side) is for a command, a file name or a variable inside a normal sentence, such as "run npm ci first".
  • • A code block (three backticks) is for anything with more than one line: a stack trace, a config file, a SQL query, or a terminal command you want people to copy.
  • • A snippet is a file that shows up in the conversation. It has a title, syntax highlighting, a raw view, comments and a download option. It is the better choice for long files.
  • Can a Slack code block have syntax highlighting?

Never appear "away" on Slack again

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

No. A code block in a Slack message has no language setting. If you type a language name right after the opening backticks, as you would on GitHub, Slack does not read it. The word shows up as the first line of the block:

```python
print("hello")
```

In Slack that posts a block whose first line is the word python. Remove the word, or name the language in the sentence above the block.

For colored syntax, create a snippet instead. Slack's help center gives these steps:

  • On desktop, click the + icon next to the message field.
  • Choose Create a text snippet.
  • Add a title if you want, and pick a file type such as Python, JavaScript or SQL. That choice sets the highlighting.
  • Paste your code into Content.
  • Check Share this file, pick a conversation, and click Create Snippet.
  • If you have already typed the code into the message field, press Cmd+Shift+Enter (Mac) or Ctrl+Shift+Enter (Windows and Linux) to turn it into a snippet. Snippets are on all plans, for members and guests. You cannot create snippets in Slack's mobile apps.

    That also answers how to share code in Slack. Short code goes in a code block. Long files, and anything people will download, go in a snippet. Whole repositories stay in GitHub, with a link in the message.

    Code blocks on iPhone and Android

    The mobile apps make code blocks too, in two ways:

  • Type the backticks. On iPhone, open the 123 keyboard and hold the apostrophe key to find the backtick. On Android with Gboard, it is on the ?123 page, then the next symbols page. Type three of them, your code, and three more.
  • Use the formatting buttons. Tap the Aa icon in the message field to show formatting options, then pick code block.
  • On a phone, long lines in a code block scroll sideways instead of wrapping. For a long log, send it from desktop as a snippet so people can open the raw file.

    Slack code block not showing

    Slack code block not showing: markup preference, wrong backtick character, rich text paste, bot or API message

  • • You see raw backticks while typing. You have Format messages with markup turned on, so formatting appears only after you press Send. Turn it off under Preferences, Advanced, Input Options to see the block as you type.
  • • The wrong character. A code block needs the backtick. Three apostrophes or curly quotes do nothing. On German, French and some other layouts the backtick is a dead key: press it, then Space, to get the character.
  • • Pasted text keeps the old formatting. Text copied from a web page or Word can arrive as rich text. Paste as plain text with Cmd+Shift+V (Ctrl+Shift+V), then add the backticks. If you paste markdown, run it through the Markdown to Slack converter first.
  • • A message from a bot or an app. Slack renders backticks only in mrkdwn text. See the next section.
  • Code blocks in Slack bot and API messages

    Never appear "away" on Slack again

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

    When you post through the API, an incoming webhook, or a tool such as the Slack GitHub Action, three backticks in the text field render as a code block, because Slack reads that field as mrkdwn by default:

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

    In Block Kit, put the code in a section block whose text type is mrkdwn. A plain_text object shows the backticks as they are:

    {
      "blocks": [
        {
          "type": "section",
          "text": {
            "type": "mrkdwn",
            "text": "Build log:\n```error: missing semicolon at line 42```"
          }
        }
      ]
    }

    Escape &, < and > as &amp;, &lt; and &gt; inside the code, or Slack may read them as links and mentions. To write and check mrkdwn before you post, use the Slack message formatter.

    For how long a message or a code block can be before Slack cuts it, see Slack message character limit.

    FAQ

    What is the shortcut for a code block in Slack? Cmd+Alt+Shift+C on Mac, Ctrl+Alt+Shift+C on Windows and Linux. Select the text first.

    How do I do inline code in Slack? Wrap the text in one backtick on each side, or select it and press Cmd+Shift+C (Ctrl+Shift+C).

    How do I get out of a code block in Slack? Click the Code block button in the toolbar again. The next text you type is normal text.

    Can I set the language of a Slack code block? No. Message code blocks have no language setting. Use a snippet and pick its file type for syntax highlighting.

    Why does Slack not format my code block? Usually the markup preference is on, so it formats after you send, the characters are not backticks, or a bot sent the text as plain_text.

    More formatting tips are in Slack tips and tricks.

    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

    Ideas

    Slack Emoji for Announcements, Updates and Reminders

    The standard Slack emoji for an announcement is 📣 :mega: or 📢 :loudspeaker: at the start of the post. Use 🚨 :rotating_light: only for real emergencies, 🆕 :new: for updates, ⏰ :alarm_clock: for reminders, and ask readers to react with ✅ :white_check_mark: once they have read it. Templates and a custom emoji idea.

    Slack Green Team•5 min read
    Templates

    Slack Status for a Doctor Appointment: 24 Statuses and Emoji

    A Slack status for a doctor appointment says you are out and when you are back, such as 🏥 'At an appointment, back at 2 PM.' You do not have to say what kind. 24 statuses for doctor, dentist and other appointments, the emoji codes, and how to schedule the status so it clears by itself.

    Slack Green Team•5 min read
    Templates

    Slack Status for Limited Availability: 30 Statuses to Copy

    A Slack status for limited availability says you are around but slow, until when, and how to reach you if it is urgent, such as ⏳ 'Limited availability today, replies after 3 PM. Urgent: @mention me.' 30 statuses for busy days, slow replies and catching up, the emoji to use, and when to pause notifications too.

    Slack Green Team•5 min read