Sub topic 10
Alerts for notes and warnings
This chapter assumes you can write GFM blockquotes and headings, and that you have edited a README in a GitHub repository. Alerts are GitHub's way to make a short passage stand out from the surrounding text.
What an alert is
An alert is a blockquote whose first line is a marker in the form [!TYPE]. Standard Markdown shows a blockquote as indented, quoted text. GitHub sees the marker and renders the block as a colored box with an icon and a title.
GitHub supports five types:
| Marker | Use it for |
|---|---|
| `[!NOTE]` | Information a reader should know even when skimming |
| `[!TIP]` | Optional advice that makes a task easier |
| `[!IMPORTANT]` | A requirement the reader needs in order to succeed |
| `[!WARNING]` | Something that may cause problems if ignored |
| `[!CAUTION]` | Actions with serious negative consequences, such as data loss |
Writing an alert
Put the marker alone on the first line. Start the text on the next line. Every line of the alert must begin with >.
> [!NOTE]
> Requires Node.js 18 or later.
> [!WARNING]
> Running `npm run reset` deletes your local database.The marker must be uppercase and must have no other text on its line. A line such as > [!note] Heads up or > [!Note] does not match. GitHub then falls back to a plain blockquote that shows the literal text [!note].
The alert ends at the first line that does not start with >. A blank line in the middle of the text must therefore be written as > alone. Without the >, the alert ends and the next paragraph renders outside the box.
> [!TIP]
> Run the tests before you commit.
>
> Use `npm test -- --watch` to rerun them on every save.Alerts can contain inline formatting such as bold, links, and inline code. They cannot be nested inside other elements, including lists and other alerts.
How GitHub decides
Common errors
- Alerts only render on GitHub and in tools that copy its extensions. Other Markdown renderers, including some documentation sites and package registries, show a plain blockquote with the literal
[!NOTE]text. Write the content so it still makes sense without the box. - Too many alerts dilute each one. Keep at most one or two per section, and save
[!CAUTION]for real risk. - Use the type that matches the consequence. A missing prerequisite is
[!IMPORTANT]. A destructive command is[!CAUTION]. - Put long troubleshooting text in a collapsible section instead, since alerts work best as short, scannable text.
Exercise
A README contains these three lines. GitHub renders a plain blockquote that shows the text "[!Warning]". What two changes make it render as a warning alert? The lines are: "> [!Warning] Do not run this in production." and "> The command drops all tables." and a blank line followed by "> Back up first."
Show answer
Change the marker to uppercase, [!WARNING], and put it alone on the first line, with the sentence on the next line. Also replace the blank line with a line containing only >, so that "Back up first." stays inside the alert.