A professional framework for building responsive, on-brand HTML emails with MJML and Automatic CSS. This repository provides a highly modular, reusable, and configurable system for developers.
- Project Goal
- The Framework Ecosystem
- Features
- Getting Started
- Project Structure
- How to Use
- Automation
- Security Notice
- Contributing
- License
The goal is to create world-class HTML email templates that perfectly match a website's brand identity by translating styles from the Automatic CSS (ACSS) framework into the MJML email framework.
This repository is the core of a larger system. The full ecosystem consists of three distinct projects:
- Email Design Framework (This Repo): The core library containing all default templates, patterns, layouts, and elements. It is intended to be consumed as a dependency (NPM package).
- Client Email Design Framework: A project template for creating a client-specific version of the framework, allowing for deep customization and style importation.
- Email Boilerplate: A minimal starter project for building a single, specific email (e.g., a newsletter, a transactional email) using either the core or a client-specific framework.
- MJML-Based: Utilizes the powerful MJML framework for generating responsive HTML that works in top email clients.
- Modular Architecture: A five-tier structure (
emails,designs,patterns,layouts,elements) makes templates easy to build, customize, and maintain. - ACSS Integration: Includes a Node.js script to automatically import CSS variables and classes from an
automatic.cssfile, ensuring brand consistency. - Dynamic Content with Tokens: Supports a simple token system (
{{your.token.here}}) for easy integration with any email delivery platform. - Professional DevOps: Pre-configured VS Code environment for streamlined development, formatting, and linting.
- Customizable: Designed to be extended with client-specific styles and components.
Follow these instructions to set up the development environment.
- VS Code: The required editor for this project.
- Node.js & NPM: Required for dependency management and running scripts.
- Git: For version control.
-
Clone the repository:
git clone https://github.com/refine-digital/email-design-framework.git cd email-design-framework -
Install VS Code Extensions: When you open the project in VS Code, you will be prompted to install the recommended extensions listed in
.vscode/extensions.json. Click Install All to proceed. -
Install NPM Dependencies:
npm install
The framework uses a logical, cascading structure within the src/ directory.
/src
├── 1_emails/ # Complete, ready-to-use email themes (e.g., newsletters)
├── 2_designs/ # Reusable email parts (e.g., header, footer, body)
├── 3_patterns/ # UI components combining layouts & elements (e.g., confirmation boxes)
├── 4_layouts/ # Structural components (e.g., sections, columns)
└── 5_elements/ # Basic MJML components (e.g., styled text, buttons)
1_emails: These are the final, composable email templates. Each file represents a complete email theme (e.g., a newsletter, a signature) and is built by including various parts from the2_designsdirectory.2_designs: Contains the main structural parts of an email (top,header,body,footer,bottom). This directory also holds the master styling files (style.mjml,_classes.mjml,_attributes.mjml) and the ACSS import-related files.3_patterns: Reusable UI/UX patterns built from layouts and elements. These are context-aware components like "primary call-to-action," "warning message," or "information box."4_layouts: The foundational structural MJML tags that define the grid and spacing of the email, such as wrappers, sections, columns, and groups.5_elements: The lowest-level components, representing styled, individual MJML elements like<mj-text>,<mj-button>, or<mj-image>.
- Open any
.mjmlfile from thesrc/1_emails/directory. - Open the VS Code Command Palette (
Cmd+Shift+P). - Run the command MJML: Open Preview to the Side.
The preview will automatically update as you edit and save the main file or any of its included partials.
-
Create a new file, e.g.,
src/1_emails/2_newsletters/my-new-newsletter.mjml. -
Build your email by including the necessary design parts:
<mjml> <mj-head> <!-- Include shared head content, styles, and attributes --> <mj-include path="../2_designs/style.mjml" /> </mj-head> <mj-body> <!-- Include design parts to compose the email --> <mj-include path="../2_designs/2_header/_header-1.mjml" /> <mj-include path="../2_designs/3_body/_body-1.mjml" /> <mj-include path="../2_designs/4_footer/_footer-1.mjml" /> </mj-body> </mjml>
For client projects, you can automatically generate style.mjml from an automatic.css file.
- Place your client's
automatic.cssfile in/src/2_designs/acss/. - Configure
/src/2_designs/acss/style.jsonto specify which CSS categories to import. - Run the import script from the root directory:
node ./scripts/import-style-from-acss.js
This will generate a new style.mjml file in /src/2_designs/ with all the corresponding MJML classes.
This template uses MJML v4, which has known high-severity vulnerabilities in its transitive dependencies (html-minifier and mjml-migrate). These issues cannot be resolved with npm audit fix in this version.
The long-term solution is an upgrade to MJML v5 or newer once stable. For local development and static email compilation, the direct threat of these vulnerabilities is generally low, but users should evaluate the risk for their own use case.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name). - Make your changes. Ensure your code adheres to the formatting rules (2-space tabs).
- Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature/your-feature-name). - Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE.md file for details.