HTML markup can be used directly in the Information and Question blocks for formatting messages in Telegram. All <, >, and & symbols that are not part of the markup must be replaced with their corresponding HTML codes:
< → <> → >& → &This article is based on the official Telegram documentation and is relevant as of March 6, 2024.
Below are all possible ways to use HTML formatting in Telegram via the API:
| Markup | Description |
|---|---|
<b>Bold</b> |
Bold. |
<i>Italic</i> |
Italic. |
<s>Strikethrough</s> |
|
<u>Underlined</u> |
Underlined. |
<tg-spoiler>Hidden</tg-spoiler> |
Hidden. |
<a href="https://google.com">Link text</a> |
Link: Link text. |
<a href="tg://user?id=123456">User mention text</a> |
User mention. |
<tg-emoji emoji-id="5458425656759032455">🙀</tg-emoji> |
Displays a custom sticker (or emoji if the bot does not have access to custom stickers). Custom stickers are only available to bots with a paid Fragment subscription. |
<code>Monospaced</code> |
<code>Monospaced</code> text (can be copied when clicked). |
<pre>Multiline monospaced</pre> |
Multiline monospaced text (formats multiple lines at once). |
To highlight code, use pre and code, specifying the programming language:
<pre><code class="language-python">
def hello(name: str = "World"):
print(f'Hello, {name}!')
hello()
hello("John")
</code></pre>
Result:
def hello(name: str = "World"):
print(f'Hello, {name}!')
hello()
hello("John")
To create quotes, use <blockquote>:
<blockquote>
First line of the quote
Second line of the quote
</blockquote>
Result:
First line of the quote Second line of the quote
If you use Markdown formatting, every opening symbol must have a corresponding closing symbol.
Example:
Incorrect:
Hello! *How are you?
Correct:
Hello! *How are you?*
If you need to use a standalone formatting symbol without applying formatting, escape it with a backslash \:
mail\_sample@mail\.com
Will be displayed as:
mail_sample@mail.com
In Server Request blocks, the escaping symbol is \.
This article is based on the official Telegram documentation and is relevant as of March 6, 2024.
Below are all possible ways to use MarkdownV2 formatting in Telegram via the API:
| Example | Markup |
|---|---|
*Bold* |
Bold. |
_Italic_ |
Italic. |
_Underlined_ |
Underlined. |
~Strikethrough~ |
|
||Hidden|| |
Hidden text, displayed only when clicked. |
*bold _italic and bold ~italic, bold, and strikethrough ||italic, bold, strikethrough, and hidden||~ __underlined, italic, and bold___ bold* |
Example of complex formatting. |
[Link text](https://google.com) |
Link. The displayed text is inside [], and the actual link is inside (). |
[User mention text](tg://user?id=123456) |
User mention. The user ID is inside (). |
 |
Displays a custom sticker by its ID (or emoji inside [] if the bot does not have access to custom stickers). Custom stickers are only available to bots with a paid Fragment subscription. |
`Monospaced` |
Monospaced text, which can be copied when clicked. |
Multiline monospaced |
Multiline monospaced text (formats multiple lines at once). |
Use triple backticks (```) and specify the programming language:
```python
def hello(name: str = "World"):
print(f'Hello, {name}!')
hello()
hello("John")
Result:
```python
def hello(name: str = "World"):
print(f'Hello, {name}!')
hello()
hello("John")
To create quotes, use > before each line:
> First line of the quote.
> Second line of the quote.
Result:
First line of the quote.
Second line of the quote.