There are two good ways to add Astro callouts. In MDX, import a Callout component and wrap the text: <Callout type="tip">...</Callout>. In plain Markdown, enable :::tip container directives with remark-directive and a short plugin that turns them into <aside> elements. Both give you note, tip and warning boxes that you style once with CSS.
Key Takeaways
- MDX plus a component is the simplest route and keeps callouts type-checked.
- For
.mdfiles,remark-directiveadds:::nameblocks; a tiny plugin maps them to HTML.- Astro does not render GitHub
> [!NOTE]alerts by default; they appear as plain blockquotes.- Use
<aside>with arole="note"and a visible title so callouts make sense without color.
Option 1: an MDX component
---
// src/components/Callout.astro
interface Props {
type?: 'note' | 'tip' | 'warning';
title?: string;
}
const { type = 'note', title } = Astro.props;
const labels = { note: 'Note', tip: 'Tip', warning: 'Warning' };
---
<aside class={`callout callout-${type}`} role="note">
<p class="callout-title">{title ?? labels[type]}</p>
<slot />
</aside>
{/* src/content/blog/deploy.mdx */}
import Callout from '../../components/Callout.astro';
<Callout type="warning" title="Back up first">
Deploying replaces the live site. Keep the previous build until you have checked the new one.
</Callout>
To use it without an import in every file, pass it through the components prop when rendering: <Content components={{ Callout }} />. Our custom MDX components guide covers that pattern.
Option 2: directives in plain Markdown
Install the remark pipeline and the directive plugin:
npm install @astrojs/markdown-remark remark-directive unist-util-visit
// src/plugins/remark-callouts.mjs
import { visit } from 'unist-util-visit';
const TYPES = new Set(['note', 'tip', 'warning']);
export default function remarkCallouts() {
return (tree) => {
visit(tree, 'containerDirective', (node) => {
if (!TYPES.has(node.name)) return;
node.data = { hName: 'aside', hProperties: { className: ['callout', `callout-${node.name}`], role: 'note' } };
const first = node.children[0];
if (first?.data?.directiveLabel) {
first.data.hProperties = { className: ['callout-title'] };
}
});
};
}
// astro.config.mjs
import { defineConfig } from 'astro/config';
import { unified } from '@astrojs/markdown-remark';
import remarkDirective from 'remark-directive';
import remarkCallouts from './src/plugins/remark-callouts.mjs';
export default defineConfig({
markdown: {
processor: unified({ remarkPlugins: [remarkDirective, remarkCallouts] }),
},
});
Now write callouts in any .md file, with an optional title in brackets:
:::tip[Faster builds]
Cache `node_modules` and `.astro` between CI runs.
:::
Unknown directive names are left alone, so :::details will not become a callout by accident. Our custom remark plugin tip explains the plugin shape. If you prefer GitHubβs > [!NOTE] syntax, community rehype plugins add support for it through the same unified() processor.
Style them once
/* src/styles/global.css */
.callout {
margin-block: 1.5rem;
padding: 1rem 1.25rem;
border-left: 4px solid var(--callout-color);
background: color-mix(in srgb, var(--callout-color) 8%, transparent);
border-radius: 0.375rem;
}
.callout-title { font-weight: 600; margin: 0 0 0.25rem; }
.callout-note { --callout-color: #2563eb; }
.callout-tip { --callout-color: #0f766e; }
.callout-warning { --callout-color: #b45309; }
Check contrast in dark mode; a tinted background that works on white can disappear on a dark page. The remark-directive README documents the syntax. Our blog and editorial themes include callout styles, and the content docs show where MDX components live.
FAQ
How do I add a callout box in Astro Markdown?
Use MDX with a Callout component, or enable :::note style directives in plain Markdown with remark-directive and a small plugin that maps them to <aside> elements.
Does Astro support GitHub-style alerts like [!NOTE]?
Not by default. They render as ordinary blockquotes. Add a community rehype plugin through the unified() processor, or use directives or an MDX component instead.
Should callouts use aside or div?
<aside> is a good fit for tangential notes, and role="note" tells assistive tech what it is. Always include a visible title so the meaning does not rely on color alone.