Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active April 7, 2025 16:41
Show Gist options
  • Save caseywatts/5a1dc6a916b8cd80c93f8a797bcc5747 to your computer and use it in GitHub Desktop.
Save caseywatts/5a1dc6a916b8cd80c93f8a797bcc5747 to your computer and use it in GitHub Desktop.
MJML Template for USWDS

This is a proof of concept, re-creating USWDS styles in MJML.

Why?

Email clients don't render everything the same way as web browsers -- for example, <button> element is not supported in email clients. There are many workarounds to get buttons to work in many email clients, each with pros and cons.

How?

Tools like MJML help make this easier, by providing an abstraction layer over the complex markup we need to ensure cross-email-client compatibility.

I've also taken some inspiration from:

Two files here:

  • One example email template in the .mjml format, with common typography elements and some buttons.
  • An approximation of USWDS base styles for emails in styles.css (not thorough or tested; a work-in-progress)

Running This Locally

To get this running locally, so you can test it:

  1. Install the MJML App
  2. Download this Gist
  3. Open the folder for this Gist in the MJML App

Running This Online

  1. Open the MJML online editor
  2. Copy-paste in the .mjml file below into the web editor.
  3. Copy-paste the .css contents below into the same file, in the mj-head. Like this:
<mjml>
  <mj-head>
    <mj-style inline="inline">
      PASTE HERE
    </mj-style>
  </mj-head>
</mjml>

Ideas for Improvement

  • I think there are better ways we could pull out the typography CSS - I just grabbed the ones I thought were most important, manually.
  • More components, like alert and others. New Jersey Unemployment Insurance has some great examples.
  • If this is helpful, we could move this out of a Gist and into a full GitHub repository.
  • We could make MJML components for some of these. I'm not sure we need to - the css/mj-class approach is pretty good! I think custom components are more important if there is DOM re-writing (like buttons -> tables)
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment