.agents/skills/react-email/references/COMPONENTS.md
Complete reference for all React Email components. All examples use the Tailwind component for styling.
Important: Only import the components you need. Do not use components in the code if you are not importing them.
All components are imported from @react-email/components:
The recommended way to style React Email components. Wrap your email content and use utility classes.
import { Tailwind, pixelBasedPreset, Html, Body, Container, Heading, Text, Button } from '@react-email/components';
export default function Email() {
return (
<Html lang="en">
<Tailwind
config={{
presets: [pixelBasedPreset],
theme: {
extend: {
colors: {
brand: '#007bff',
accent: '#28a745'
},
},
},
}}
>
<Body className="bg-gray-100 font-sans">
<Container className="max-w-xl mx-auto p-5">
<Heading className="text-2xl font-bold text-brand mb-4">
Welcome!
</Heading>
<Text className="text-base text-gray-700 mb-4">
Your content here.
</Text>
<Button
href="https://example.com"
className="bg-brand text-white px-6 py-3 rounded-lg block text-center"
>
Get Started
</Button>
</Container>
</Body>
</Tailwind>
</Html>
);
}
Props:
config - Tailwind configuration objectHow it works:
<style> tag in <head>Important:
pixelBasedPreset - email clients don't support rem unitsRoot wrapper for the email. Always use as the outermost component.
import { Html, Tailwind, pixelBasedPreset } from '@react-email/components';
<Html lang="en" dir="ltr">
<Tailwind config={{ presets: [pixelBasedPreset] }}>
</Tailwind>
</Html>
Props:
lang - Language code (e.g., "en", "es", "fr")dir - Text direction ("ltr" or "rtl")Contains head components, related to the document such as style and meta elements. Place inside <Tailwind>.
import { Head } from '@react-email/components';
<Head>
<title>Email Title</title>
</Head>
A React component to wrap emails.
import { Body } from '@react-email/components';
<Body className="bg-gray-100 font-sans">
</Body>
A layout component that centers your content horizontally on a breaking point. Has a max-width constraint of 37.5em.
import { Container } from '@react-email/components';
<Container className="max-w-xl mx-auto p-5">
</Container>
Display a section that can also be formatted using rows and columns.
import { Section } from '@react-email/components';
<Section className="p-5 bg-white">
</Section>
Row displays content areas horizontally, Column displays content areas vertically. A Column needs to be used in combination with a Row component.
import { Section, Row, Column } from '@react-email/components';
<Section>
<Row>
<Column className="w-1/2 p-2 align-top">
Left column content
</Column>
<Column className="w-1/2 p-2 align-top">
Right column content
</Column>
</Row>
</Section>
Column widths:
A preview text that will be displayed in the inbox of the recipient.
import { Preview } from '@react-email/components';
<Preview>Welcome to our platform - Get started today!</Preview>
Best practices:
<Body>A block of heading text (h1-h6).
import { Heading } from '@react-email/components';
<Heading as="h1" className="text-2xl font-bold text-gray-800 mb-4">
Welcome to Acme
</Heading>
<Heading as="h2" className="text-xl font-semibold text-gray-600 mb-3">
Getting Started
</Heading>
Props:
as - HTML heading level ("h1" through "h6")A block of text separated by blank spaces.
import { Text } from '@react-email/components';
<Text className="text-base leading-6 text-gray-800 my-4">
Your paragraph content here.
</Text>
A link that is styled to look like a button. Has workaround for padding issues in Outlook.
import { Button } from '@react-email/components';
<Button
href="https://example.com/verify"
target="_blank"
className="bg-blue-600 text-white px-5 py-3 rounded block text-center no-underline font-medium"
>
Verify Email Address
</Button>
Props:
href (required) - URL to link totarget - Default is "_blank"Styling tips:
block for full-width buttonstext-center for centered textno-underline to remove underlineA hyperlink to web pages, email addresses, or anything else a URL can address.
import { Link } from '@react-email/components';
<Link href="https://example.com" target="_blank" className="text-blue-600 underline">
Visit our website
</Link>
Props:
href (required) - URL to link totarget - Default is "_blank"Display an image in your email.
import { Img } from '@react-email/components';
Props:
src (required) - Image URL (must be absolute)alt (required) - Alt text for accessibilitywidth - Image width in pixelsheight - Image height in pixelsBest practices:
block class to avoid spacing issuesDisplay a divider that separates content areas in your email.
import { Hr } from '@react-email/components';
<Hr className="border-gray-200 my-5" />
Display code with a selected theme and regex highlighting using Prism.js.
import { CodeBlock, dracula } from '@react-email/components';
const Email = () => {
const code = `export default async (req, res) => {
try {
const html = await renderAsync(
EmailTemplate({ firstName: 'John' })
);
return NextResponse.json({ html });
} catch (error) {
return NextResponse.json({ error });
}
}`;
return (
<div className="overflow-auto">
<CodeBlock
fontFamily="monospace"
theme={dracula}
language="javascript"
code={code}
/>
</div>
);
};
Props:
code (required) - The actual code to render in the code block. Just a plain string, with the proper indentation includedlanguage (required) - The language under the supported languages defined in PrismLanguage (e.g., "javascript", "python", "typescript")theme (required) - The theme to use for the code block (import from "@react-email/components": dracula, github, nord, etc.)fontFamily (optional) - The font family to use for the code block (e.g., "monospace")lineNumbers (optional) - Whether or not to automatically include line numbers on the rendered code block (boolean, default: false)Important:
lineNumbers prop unless specifically requestedCodeBlock component in a div tag with the overflow-auto class to avoid padding overflowDisplay a predictable inline code HTML element that works on all email clients.
import { Text, CodeInline } from '@react-email/components';
<Text className="text-base text-gray-800">
Run <CodeInline className="bg-gray-100 px-1 rounded">npm install</CodeInline> to get started.
</Text>
A Markdown component that converts markdown to valid react-email template code.
import { Html, Markdown } from '@react-email/components';
const Email = () => {
return (
<Html lang="en" dir="ltr">
<Markdown
markdownCustomStyles={{
h1: { color: "red" },
h2: { color: "blue" },
codeInline: { background: "grey" },
}}
markdownContainerStyles={{
padding: "12px",
border: "solid 1px black",
}}
>{`# Hello, World!`}</Markdown>
<Markdown children={`# This is a ~~strikethrough~~`} />
</Html>
);
};
Props:
children (required) - Markdown stringmarkdownCustomStyles - Style overrides for HTML elements (h1, h2, p, a, codeInline, etc.)markdownContainerStyles - Styles for container divA React Font component to set your fonts.
import { Head, Font } from '@react-email/components';
<Head>
<Font
fontFamily="Roboto"
fallbackFontFamily="Arial, sans-serif"
webFont={{
url: "https://fonts.gstatic.com/s/roboto/v27/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2",
format: "woff2"
}}
/>
</Head>
Props:
fontFamily (required) - Font family namefallbackFontFamily - Fallback fontswebFont - Object with url and formatSupported formats: