
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
| Introduction | Installation | Usage |
MJML is a markup language created by Mailjet and designed to reduce the pain of coding a responsive email. Its semantic syntax makes the language easy and straightforward while its rich standard components library shortens your development time and lightens your email codebase. MJML’s open-source engine takes care of translating the MJML you wrote into responsive HTML.
You can install MJML with NPM to use it with NodeJS or the Command Line Interface. If you're not sure what those are, head over to Usage for other ways to use MJML.
npm install mjml
Don't want to install anything? Use the free online editor!
MJML comes with tools and plugins, check out:
For more tools, check the Community page.
Compiles the file and outputs the HTML generated in
output.html
mjml input.mjml -o output.html
You can pass optional arguments to the CLI and combine them.
| argument | description | default value |
|---|---|---|
mjml [input] -o [output] | Writes the output to [output] | |
mjml [input] -s | Writes the output to stdout | |
mjml [input] -s --noStdoutFileComment | Writes the output to stdout without file comment in the first line | |
mjml -w [input] | Watches the changes made to [input] (file or folder) | |
mjml [input] --config.allowIncludes | Enables mj-include processing (true or false) | false |
mjml [input] --config.allowMixedSyntax | Allows mixing block and CSS variable syntax when sanitizeStyles is enabled (true or false) | false |
mjml [input] --config.beautify | Beautifies the output (true or false) | true |
mjml [input] --config.includePath | Adds allowlisted include root(s), as a string path or JSON array of paths | |
mjml [input] --config.minify | Minifies the output (true or false) | false |
mjml [input] --config.minifyOptions | Options for HTML minifier, use minifyCss to control CSS minification | See mjml-cli documentation |
mjml [input] --config.juicePreserveTags | Preserve some tags when inlining CSS | See mjml-cli documentation |
mjml [input] --config.mjmlConfigPath | Path to .mjmlconfig file for custom components | current working directory |
mjml [input] --config.sanitizeStyles | Sanitizes template variables inside CSS before minification (true or false) | false |
mjml [input] --config.useMjmlConfigOptions | Allows to use the options attribute from .mjmlconfig file | false |
mjml [input] --config.templateSyntax | Sets custom template delimiters as JSON array ([{"prefix":"{{","suffix":"}}"}]) | [{"prefix":"{{","suffix":"}}"},{"prefix":"[[","suffix":"]]"}] |
See mjml-cli documentation for more information about config options.
import mjml2html from 'mjml'
/*
Compile an mjml string
*/
async function renderMjml() {
const htmlOutput = await mjml2html(`
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text>
Hello World!
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
`, options)
/*
Print the responsive HTML generated and MJML errors if any
*/
console.log(htmlOutput)
}
renderMjml()
You can pass optional options as an object to the mjml2html function:
| option | unit | description | default value |
|---|---|---|---|
| allowMixedSyntax | boolean | Allows mixed block/value/property template syntaxes during CSS sanitization | false |
| beautify | boolean | Option to beautify the HTML output | false |
| filePath | string | Path of file, used for relative paths in mj-include instances | . |
| fonts | object | Default fonts imported in the HTML rendered by MJML | See in index.js |
| ignoreIncludes | boolean | Option to ignore mj-include instances | true |
| includePath | string or string[] | Additional allowlisted include root(s), used when ignoreIncludes is false | |
| juicePreserveTags | object | Preserve some tags when inlining CSS, see documentation for more info | |
| keepComments | boolean | Option to keep comments in the HTML output | true |
| minify | boolean | Option to minify the HTML output | false |
| minifyOptions | object | Options for htmlnano minification (including minifyCss), see documentation for more info | |
| mjmlConfigPath | string | The path or directory of the .mjmlconfig file (for custom components use) | process.cwd() |
| preprocessors | array of functions | Preprocessors applied to the xml before parsing. Input must be xml, not json. Functions must be (xml: string) => string | [] |
| sanitizeStyles | boolean | Sanitizes template variables in CSS before minification | false |
| templateSyntax | array of objects | Custom template delimiters used by sanitization ([{ prefix, suffix }]) | [{"prefix":"{{","suffix":"}}"},{"prefix":"[[","suffix":"]]"}] |
| useMjmlConfigOptions | boolean | Allows to use the options attribute from .mjmlconfig file | false |
| validationLevel | string | Available values for the validator: strict, soft, skip | soft. |
var mjml2html = require('mjml-browser')
/*
Compile a mjml string
*/
mjml2html(`
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text>
Hello World!
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
`, options).then(function (htmlOutput) {
/*
Print the responsive HTML generated and MJML errors if any
*/
console.log(htmlOutput)
})
A free-to-use MJML API is available to make it easy to integrate MJML in your application. Head over here to learn more about the API.
MJML wouldn't be as cool without its amazing community. Head over the Community Slack to meet fellow MJML'ers.
Handlebars is a popular templating engine that can be used to create dynamic HTML content, including emails. Unlike MJML, Handlebars does not provide built-in responsive design features, so you would need to handle the CSS and media queries yourself.
Pug (formerly Jade) is another templating engine that can be used to generate HTML. While it is powerful and flexible, it does not offer the same level of abstraction for responsive email design as MJML does.
Nunjucks is a templating engine inspired by Jinja2. It is highly extensible and can be used to generate HTML for emails. However, like Handlebars and Pug, it does not provide built-in support for responsive email design.
FAQs
MJML: the only framework that makes responsive-email easy
The npm package mjml receives a total of 1,216,010 weekly downloads. As such, mjml popularity was classified as popular.
We found that mjml demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.