Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

mjml

Package Overview
Dependencies
Maintainers
7
Versions
180
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mjml

MJML: the only framework that makes responsive-email easy

latest
Source
npmnpm
Version
5.0.1
Version published
Weekly downloads
1.3M
10.49%
Maintainers
7
Weekly downloads
 
Created
Source

Developed by

github actions

| Introduction | Installation | Usage |

Introduction

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.

Installation

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

Usage

Online

Don't want to install anything? Use the free online editor!

try it live

Applications and plugins

MJML comes with tools and plugins, check out:

For more tools, check the Community page.

Command line interface

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.

argumentdescriptiondefault value
mjml [input] -o [output]Writes the output to [output]
mjml [input] -sWrites the output to stdout
mjml [input] -s --noStdoutFileCommentWrites 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.allowIncludesEnables mj-include processing (true or false)false
mjml [input] --config.allowMixedSyntaxAllows mixing block and CSS variable syntax when sanitizeStyles is enabled (true or false)false
mjml [input] --config.beautifyBeautifies the output (true or false)true
mjml [input] --config.includePathAdds allowlisted include root(s), as a string path or JSON array of paths
mjml [input] --config.minifyMinifies the output (true or false)false
mjml [input] --config.minifyOptionsOptions for HTML minifier, use minifyCss to control CSS minificationSee mjml-cli documentation
mjml [input] --config.juicePreserveTagsPreserve some tags when inlining CSSSee mjml-cli documentation
mjml [input] --config.mjmlConfigPathPath to .mjmlconfig file for custom componentscurrent working directory
mjml [input] --config.sanitizeStylesSanitizes template variables inside CSS before minification (true or false)false
mjml [input] --config.useMjmlConfigOptionsAllows to use the options attribute from .mjmlconfig filefalse
mjml [input] --config.templateSyntaxSets custom template delimiters as JSON array ([{"prefix":"{{","suffix":"}}"}])[{"prefix":"{{","suffix":"}}"},{"prefix":"[[","suffix":"]]"}]

See mjml-cli documentation for more information about config options.

Inside Node.js

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:

optionunitdescriptiondefault value
allowMixedSyntaxbooleanAllows mixed block/value/property template syntaxes during CSS sanitizationfalse
beautifybooleanOption to beautify the HTML outputfalse
filePathstringPath of file, used for relative paths in mj-include instances.
fontsobjectDefault fonts imported in the HTML rendered by MJMLSee in index.js
ignoreIncludesbooleanOption to ignore mj-include instancestrue
includePathstring or string[]Additional allowlisted include root(s), used when ignoreIncludes is false
juicePreserveTagsobjectPreserve some tags when inlining CSS, see documentation for more info
keepCommentsbooleanOption to keep comments in the HTML outputtrue
minifybooleanOption to minify the HTML outputfalse
minifyOptionsobjectOptions for htmlnano minification (including minifyCss), see documentation for more info
mjmlConfigPathstringThe path or directory of the .mjmlconfig file (for custom components use)process.cwd()
preprocessorsarray of functionsPreprocessors applied to the xml before parsing. Input must be xml, not json. Functions must be (xml: string) => string[]
sanitizeStylesbooleanSanitizes template variables in CSS before minificationfalse
templateSyntaxarray of objectsCustom template delimiters used by sanitization ([{ prefix, suffix }])[{"prefix":"{{","suffix":"}}"},{"prefix":"[[","suffix":"]]"}]
useMjmlConfigOptionsbooleanAllows to use the options attribute from .mjmlconfig filefalse
validationLevelstringAvailable values for the validator: strict, soft, skipsoft.

Client-side (in browser)

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)
})

API

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 Slack

MJML wouldn't be as cool without its amazing community. Head over the Community Slack to meet fellow MJML'ers.

FAQs

Package last updated on 16 Apr 2026

Did you know?

Socket

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.

Install

Related posts