Prompt
How do I build email templates that my developers can version and reuse?
Latest observation
A good way to do this is to treat emails like a small design system: separate content, layout, and branding, then store them in version control like any other code.
Recommended approach
1. Use a templating language
Pick something your app can render server-side, such as:
- Handlebars
- MJML
- Liquid
- React Email
- Twig / Jinja / ERB depending on your stack
This lets developers reuse components and inject dynamic data cleanly.
2. Break emails into reusable components
Create shared pieces like:
- header
- footer
- button
- text block
- image banner
- spacer/divider
Then compose templates from these parts instead of copying full HTML.
3. Keep templates in git
Store them in your repo, for example:
/email-templates
/components
button.hbs
header.hbs
footer.hbs
/layouts
base.hbs
/templates
welcome.hbs
password-reset.hbs
invoice.hbs
This gives you:
- version history
- code review
- rollback
- branching and releases
4. Use a base layout
Have one master layout with:
- branding
- typography
- table-based structure for email compatibility
- inline-friendly classes or styles
Then individual emails extend it.
5. Pass data in a structured way
Define a clear contract for each template:
{
"firstName": "Ava",
"resetLink": "https://example.com/reset",
"expiresIn": "30 minutes"
}
Document required vs optional variables so templates don’t break.
6. Centralize styles and tokens
Use shared design tokens for:
- colors
- spacing
- fonts
- button styles
If your workflow allows it, generate emails from a design system so branding stays consistent.
7. Test in preview and email clients
Developers should be able to:
- render templates with mock data locally
- preview them in Storybook or a similar tool
- send test emails to Gmail/Outlook/etc.
- validate links, dark mode, and mobile responsiveness
8. Use a release process
Treat template changes like app changes:
- version changes in git
- tag releases if needed
- deploy templates with your application or email service
- keep backward compatibility for shared components where possible
Practical setup examples
If you want simple and robust
- Use Handlebars + MJML
- Version in git
- Build step compiles MJML to HTML
- Shared components via partials
If you want a modern developer experience
- Use React Email
- Build reusable React components
- Render previews locally
- Version templates in git
- Easier for frontend teams to maintain
If your app already uses server-side rendering
- Use your existing template engine
- Create partials/layouts
- Add a preview route and test fixtures
Best practices
- Prefer simple HTML and tables for layout
- Inline CSS or use a build step that inlines it
- Avoid overly complex client-side behavior
- Keep copy editable separately when possible
- Name templates by purpose, not by campaign date
- Add snapshot tests for template output
A simple rule of thumb
If developers should reuse it, make it a component.
If they should change it safely, put it in version control.
If it should work across email clients, keep the HTML conservative.
If you want, I can also show:
- a recommended folder structure,
- an example template system in your stack, or
- a starter email component architecture.