Skip to content
TGWAY
How-to

How to Format Code in Telegram

Three backticks turn the lines that follow into a code block: monospaced, coloured according to the language, with a header naming it and a control that…

  • LevelL2
In this article
  1. code A container, not a font
  2. settings Sending a block
  3. At a glance
play_circle Video tip • Writing

Three backticks turn the lines that follow into a code block: monospaced, coloured according to the language, with a header naming it and a control that copies the contents.

The copy button is the part that matters. What the reader gets is exactly your characters — no surrounding chat, no corrected quotation marks, no lost indentation.

What you will be able to do

  • check_circle Send code that arrives exactly as written.
  • check_circle Declare the language so it is coloured correctly.
  • check_circle Use inline code for the short things.
  • check_circle Know when to send a file instead.
play_circle Official Telegram video short — formatting code
1080p clip from @TelegramTips #411 • 0:08

The block carries a language label and a copy control in its header.

code A container, not a font

Pasting code into an ordinary message is where most of the wasted time in technical chats comes from. Indentation collapses, quotation marks get replaced with curly ones, a long line wraps somewhere meaningless, and the person on the other end retypes it and introduces a different bug.

A code block makes the text an object. Nothing in it is interpreted as formatting, the copy control puts precisely those characters on the clipboard, and on a desktop a wide line scrolls sideways rather than wrapping. That is worth more than the colours.

The colours still help, and they depend on Telegram knowing the language. It will guess, and the guess is usually right for anything with obvious keywords, but writing the language after the opening backticks removes the question and labels the block for whoever reads it later.

content_copy
Inline code for the short things A single command, a filename, a variable, a hash: wrap it in single backticks. It becomes tap-to-copy in one action, which is why an address or a reference number is better sent this way than as plain text.
terminal Interactive

Four ways to send something technical

The last one is the answer more often than people think.

data_object Several lines that must survive

check_circle A function, a configuration fragment, a stack trace, a query. Anything where whitespace or exact characters carry meaning.
check_circle Name the language on the opening line. The label tells the reader what they are looking at before they read it.
check_circle Long blocks collapse rather than filling the chat, and open on a tap for whoever wants them.

A block preserves exactly what you typed. Past a screenful, send the file and quote the lines.

settings Sending a block

  1. Open with three backticks And the language name if you know it.
  2. Write or paste the code Indentation is preserved as typed.
  3. Close with three backticks Or use the formatting menu on selected text.
  4. Use single backticks for one-liners Commands, paths, reference numbers.
  5. Tell people about the copy control Most recipients never notice it.
  6. Attach a file past a screenful And quote only the relevant lines.
menu_book
Part of the beginner curriculum Step 52 — Text formatting, quotes and spoilers

This page is one kind of block. The curriculum step is the whole set: bold and italic, quotes and collapsible quotes, spoilers, and how formatting survives being copied out of Telegram into something else.

Summary

At a glance

  1. 1Code blocks

    Wrap code so it arrives exactly as written.

  2. 2Language label

    Name the language for colouring.

  3. 3Long code

    Send a file and quote the key lines.

Share this guide

Send it to a friend who has the same question.

Telegram WhatsApp
More

Open on your phonePoint your phone camera here to open this guide.

Updated

Related articles

View all ›