MailMode Preview first. Panic less.
Docs Learn Changelog About Status Terms Privacy
← Back to MailMode
MailMode Learn Technical reference

MJML Dark Mode Email Guide

A technical reference for building dark-mode-aware MJML templates, inspecting compiled HTML and applying client-specific fallbacks safely.

Published: 9th June 2026 Last updated: 9th June 2026
sourceMJML components
outputGenerated table HTML
ruleTest compiled HTML
MJML compiles

Generated HTML

Source MJML becomes nested responsive table markup, so dark mode selectors must target the compiled result, not the source tree.

Head CSS matters

mj-head layer

Use mj-style, mj-raw and head-level declarations for dark CSS, meta tags and client patches.

Test output

Compiled checks

Many dark mode bugs only appear after MJML wraps, inlines or restructures your original components.

Client reality

Different strategies

Apple Mail, Gmail, Outlook.com and classic Outlook Windows need different dark mode fallbacks.

This is an independent MailMode guide, not official MJML, Apple, Google or Microsoft documentation. MJML compiler output, email client behaviour and account-specific support can change, so use these patterns as practical checks rather than universal guarantees.

Key takeaways

MJML helps structure email, not dark mode itself

  • MJML does not provide native dark mode support or a magic dark mode switch; the hard constraints come from email clients.
  • MJML components compile into generated wrappers, tables and inline styles that can change where classes and styles land.
  • css-class may be placed on an outer generated node, so inspect the compiled HTML before writing final selectors.
  • Current MJML can place css-class from mj-body on the generated body tag, which is useful for Gmail targeting, but this still needs compiled-output verification.
  • MJML 5 changed body/class placement and minification behaviour, so upgrades should trigger a visual dark mode re-check.
  • Dark mode CSS usually belongs in <mj-style> inside <mj-head>.
  • Keep media queries and client-targeting selectors in embedded mj-style, not mj-style inline="inline".
  • Dark mode meta tags usually need <mj-raw> inside <mj-head>.
  • Apple Mail is the strongest target for authored prefers-color-scheme CSS.
  • Gmail requires targeted selector patterns like u + .body, and those do not cover every Gmail account type.
  • Outlook.com can require [data-ogsc] and [data-ogsb] reaction selectors.
  • Classic Outlook for Windows remains the MSO/VML fallback path, not a modern CSS target.
  • Use mj-attributes, mj-class or your build system for colour tokens; runtime CSS variables are not production-safe across Gmail, Outlook and Yahoo.
  • Always test the compiled HTML, not just the MJML source.
Try MailMode

See your email in every mode

Test your email across light, dark, partial invert and full invert modes.

Try MailMode for free ->

No signup required

Light Dark Partial Full
Compilation model

MJML dark mode work happens in the generated HTML

MJML is a source format. The email that Apple Mail, Gmail and Outlook receive is the compiled HTML output, with generated tables, wrapper cells, inline attributes and client fallbacks.

A class added to mj-section, mj-wrapper or mj-button may not sit on the element you expected after compilation. That matters when writing dark mode selectors, Gmail selectors or Outlook reaction selectors.

MJML release changes can alter body structure, class placement and minified CSS output. Treat compiler upgrades like rendering changes: recompile, inspect and visually test again.

Inspect the compiled HTML before writing dark mode selectors. The safest workflow is: write MJML, compile it, inspect the generated selectors, then test the compiled HTML in MailMode and real clients.

Source MJML MJML compiler Generated table HTML Client dark transform
Building blocks

MJML tools for dark mode email

MJML behaviour notes are based on official MJML documentation, compiler output considerations, email-client support references and email developer testing sources. Always test compiled HTML because output can vary by MJML version, build setup and email client.

MJML featureUseDark mode roleRiskRecommendation
<mj-head>Head containerHead CSSOnly useful if children compile correctly.Place styles, attributes and raw meta tags here.
<mj-body css-class>Body-level hookClient-specificCompiler-version behaviour matters.Use for Gmail body-class targeting, then verify the generated body output.
<mj-style>Embedded CSSRuntime CSSEmail clients can strip or ignore parts of it.Use for media queries and client selectors.
<mj-style inline="inline">Inline selected CSSCompile-timeCan flatten rules that need to remain in the head.Do not inline media queries or Gmail/Outlook targeting rules.
<mj-raw>Literal outputHead CSSInvalid placement can break output.Use for meta tags and carefully scoped MSO comments.
<mj-attributes>Component defaultsCompile-timeLight defaults can be transformed by clients.Use for baseline colours, spacing and typography.
<mj-class>Reusable MJML attributesCompile-timeNot the same as a CSS class.Use as compile-time design tokens, not runtime client targeting.
<mj-html-attributes>HTML attributes on generated nodesUse with cautionSelector paths are compiler-dependent.Use only after inspecting output.
css-classAdd class to generated markupClient-specificMay land on an outer wrapper.Verify exactly where the class compiles.
Inline component attrsSet colours directlyCompile-timeGenerated inline styles can be hard to override.Use for safe baseline values and pair with dark CSS.
Post-compile editsPatch final HTMLUse with cautionCan drift from source templates.Automate if needed; avoid manual one-off edits.
Meta tags

Declare dark mode support through mj-raw

Base dark mode declarations in MJML
<mjml>
  <mj-head>
    <mj-raw>
      <meta name="color-scheme" content="light dark">
      <meta name="supported-color-schemes" content="light dark">
    </mj-raw>

    <mj-style>
      :root {
        color-scheme: light dark;
        supported-color-schemes: light dark;
      }
    </mj-style>
  </mj-head>
</mjml>

These declarations are most useful for standards-friendly clients such as Apple Mail. color-scheme is the modern hint, while supported-color-schemes remains useful for Apple Mail history. They do not force Gmail, Yahoo or Outlook Windows to behave like Apple Mail.

Authored dark CSS

prefers-color-scheme inside MJML

Standards-based dark CSS in mj-style
<mj-head>
  <mj-style>
    @media (prefers-color-scheme: dark) {
      .email-shell {
        background-color: #111114 !important;
      }

      .surface {
        background-color: #1b1b22 !important;
        color: #f5f5f7 !important;
      }

      .muted-text div {
        color: #b8b8c7 !important;
      }
    }
  </mj-style>
</mj-head>

<mj-body css-class="email-shell" background-color="#f6f4ff">
  <mj-section css-class="surface" background-color="#ffffff">
    <mj-column>
      <mj-text css-class="muted-text">Dark mode-aware copy</mj-text>
    </mj-column>
  </mj-section>
</mj-body>

The selector .muted-text div is intentional: many mj-text styles land on a generated inner div. This media query is mainly for standards-friendly clients such as Apple Mail; it should not be treated as a Gmail or Yahoo dark mode strategy. Inspect your compiled HTML before relying on the exact selector.

Components

MJML component dark mode risks

mj-body

Email shell

Generates: document/body wrapper backgrounds. Risk: client rewrites create unexpected page colour. Safer: set both MJML background and dark CSS fallback.

mj-section

Section surfaces

Generates: table wrappers and cells. Risk: class may land outside the coloured cell, and Outlook background support has limits. Safer: inspect output before targeting backgrounds.

mj-wrapper

Grouped panels

Generates: nested wrappers. Risk: inner and outer surfaces can transform differently, causing seams. Safer: give each visible layer explicit colours.

mj-column

Responsive cells

Generates: table cells and mobile responsive rules. Risk: background-color and inner-background-color can become separate surfaces. Safer: test mobile compiled HTML.

mj-text

Copy blocks

Generates: an inner div. Risk: dark text on transformed surfaces. Safer: target the generated text element and use readable dark values.

mj-image

Logos and icons

Generates: linked image markup. Risk: transparent logos lose contrast. Safer: use image swaps, padding, outlines or alternate assets.

mj-button

CTA buttons

Generates: HTML button structures, not a complete bulletproof VML button. Risk: fill, text and border mismatch in dark clients. Safer: test the compiled button and use a dedicated MSO/VML fallback if Outlook desktop is critical.

mj-hero

Hero backgrounds

Generates: complex image/table layout with explicit dimensions. Risk: text over imagery and fallback colours become fragile. Safer: keep text contrast independent from automatic inversion.

Image swaps

Swap logos and critical assets deliberately

Light/dark logo swap in MJML
<mj-head>
  <mj-style>
    .dark-logo { display: none; max-height: 0; overflow: hidden; }

    @media (prefers-color-scheme: dark) {
      .light-logo { display: none !important; max-height: 0 !important; overflow: hidden !important; }
      .dark-logo { display: block !important; max-height: none !important; }
    }
  </mj-style>
</mj-head>

<mj-section>
  <mj-column>
    <mj-image css-class="light-logo" src="https://example.com/logo-light.png" alt="Brand" width="160px" />
    <mj-image css-class="dark-logo" src="https://example.com/logo-dark.png" alt="Brand" width="160px" />
  </mj-column>
</mj-section>

This works best in standards-friendly clients. MJML may place the class on a generated container rather than directly on the img, so confirm the compiled selector. Some clients may download both assets, hide/show differently or ignore the embedded CSS. Transparent logos still need testing on changed surfaces. Use hosted production asset URLs rather than relying on local filenames.

Gmail-specific

Target Gmail from compiled MJML carefully

Gmail notes are based on Gmail CSS support documentation and email developer testing references. Gmail Web, Gmail iOS, Gmail Android and Gmail Apps with Non-Google Accounts should be treated as separate test surfaces.

Gmail targeting pattern in MJML
<mj-head>
  <mj-style>
    u + .body .gmail-surface {
      background: #1f1f23 !important;
      background-image: linear-gradient(#1f1f23, #1f1f23) !important;
      color: #ffffff !important;
    }

    u + .body .gmail-surface div {
      color: #ffffff !important;
    }

    div > u + .body .gmail-android-fix {
      background-color: #1f1f23 !important;
    }
  </mj-style>
</mj-head>

<mj-body css-class="body">
  <mj-section css-class="gmail-surface" background-color="#663399">
    <mj-column>
      <mj-text>Gmail-targeted content</mj-text>
    </mj-column>
  </mj-section>
</mj-body>

This pattern depends on a doctype and a generated body class. Gmail Apps with Non-Google Accounts can have reduced CSS support, and blend-mode or single-colour gradient workarounds are targeted hacks rather than reliable universal fixes. Do not assume Gmail iOS, Gmail Android, Gmail Web and GANGA behave the same.

Outlook-specific

Use Outlook.com selectors and MSO fallbacks separately

Outlook notes distinguish web, mobile, Mac, new Outlook and classic Outlook Windows paths. MSO/VML guidance is for classic Outlook Windows only and should not be applied as a universal Outlook strategy.

Outlook.com reaction selectors
<mj-head>
  <mj-style>
    [data-ogsc] .outlook-surface {
      background-color: #1f2937 !important;
      color: #ffffff !important;
    }

    [data-ogsc] .outlook-surface div {
      color: #ffffff !important;
    }

    [data-ogsb] .outlook-button {
      border-color: #8b5cf6 !important;
    }
  </mj-style>
</mj-head>
Scoped MSO fallback with mj-raw
<mj-raw>
  <!--[if mso]>
  <style>
    .mso-button { background: #111827 !important; color: #ffffff !important; }
  </style>
  <![endif]-->
</mj-raw>

data-og* is for Outlook.com-style rewriting and some related app surfaces. MSO conditionals and VML are for classic Outlook Windows. Outlook.com, new Outlook and classic Outlook Windows are not the same rendering model.

Support matrix

How MJML dark mode patterns map to clients

Client support describes practical dark-mode strategy, not exact output. CSS support, MJML compiler output and forced dark-mode behaviour are separate concerns that need compiled HTML testing.

ClientMJML output concernsDark CSS supportBest strategyCaution
Apple MailGenerated selectors need inspection.Standards-friendlyUse meta tags, prefers-color-scheme and image swaps.Rich HTML, simple mail and OS versions can differ.
GmailBody class and compiled wrappers matter.Reduced CSSUse targeted Gmail selectors for narrow fixes, not prefers-color-scheme.Gmail Web, iOS, Android and GANGA differ.
Outlook.comColour reaction selectors apply after rewrite.Partial invertUse data-og* patches and resilient HTML buttons.Not a VML client.
Classic Outlook WindowsVML/MSO paths are separate from HTML branch.Full invert riskUse MSO fallbacks sparingly and test exact output.Word rendering and DPI can affect layout.
New Outlook WindowsTreat as web-family, not classic Outlook.Mixed supportTest separately from classic Outlook.Do not assume VML applies.
Yahoo MailEmbedded CSS support can be selective.Mixed supportUse defensive colours and real-client checks.Do not rely on standards-only dark CSS.
Samsung EmailMobile layout and image handling matter.Mixed supportTest mobile output and avoid fragile contrast.App/device versions vary.
ThunderbirdModern CSS can work better than in webmail.Standards-friendlyUse authored dark CSS, but keep fallbacks.User settings and versions can still vary.
Failure patterns

Common MJML dark mode failures

Compiled selectors

Selector misses the visible cell

What breaks: dark CSS targets the wrapper but not the coloured table cell. Safer: inspect compiled HTML and target the generated element.

Gmail

Body class targeting is missing

What breaks: u + .body never matches. Safer: add css-class="body" to mj-body and verify output.

Apple Mail

Dark meta without complete CSS

What breaks: the client is told dark mode exists but surfaces, text or borders are incomplete. Safer: style the full visible component.

Outlook.com

Using standards CSS for Outlook reaction bugs

What breaks: rewritten colours are not patched. Safer: use data-og* selectors for tested Outlook.com cases.

Outlook Windows

Assuming mj-button is bulletproof

What breaks: VML, HTML fill, border and text can diverge. Safer: inspect the compiled button and test the VML branch.

Images

Transparent logo disappears

What breaks: surrounding surface changes but logo pixels do not. Safer: use alternate assets, outlines, padding or non-transparent marks.

Inlining

Inlining flattens useful rules

What breaks: media queries and client selectors are lost or changed. Safer: keep runtime dark CSS in normal mj-style.

Compiler upgrade

MJML version changes output

What breaks: class placement, minified CSS or body structure changes after an upgrade. Safer: re-run compiled HTML QA whenever the compiler changes.

Source drift

Manual post-compile edits get lost

What breaks: build output stops matching tested HTML. Safer: automate post-compile patches or keep fixes in MJML source.

Best practices

A safer MJML dark mode workflow

  • Start with a robust light email that remains readable if a client makes no colour changes.
  • Keep component defaults in mj-attributes, but keep runtime dark CSS in mj-style.
  • Add dark mode meta tags deliberately through mj-raw.
  • Use css-class for semantic hooks, then verify where those hooks land in the compiled HTML.
  • Use a body class for Gmail targeting when needed, but confirm how your MJML version emits it.
  • Use prefers-color-scheme for standards-friendly clients, especially Apple Mail.
  • Use Gmail and Outlook targeting only for their own client families.
  • Avoid exact black/white as the only contrast plan; use near-black, off-white and explicit border tokens.
  • Prefer MJML compile-time tokens or build-time variables over runtime CSS variables for production email colours.
  • Test logos, buttons, borders, cards and footer sections in the compiled HTML.
  • Track your MJML compiler version so output changes are visible during QA.
MailMode mapping

How this maps back to MailMode previews

For MJML templates, compile the MJML first and preview the resulting HTML. MailMode checks the final email output users will send, not the source component tree. For supported inputs and renderer limitations, see the MailMode MJML documentation.

Authored CSS mode helps check intentional dark CSS from mj-style and dark mode declarations from mj-raw.

Partial invert helps approximate selective client adjustments like Outlook.com/mobile or some Gmail Android-style cases where surfaces and text may be changed separately.

Full invert helps stress-test aggressive forced dark behaviour, including the kinds of surface, text, VML/background and button mismatches that can appear in classic Outlook-style rendering.

These preview modes are useful approximations, not exact replicas of every email client or every MJML compilation edge case.

Related guides: Dark Mode CSS guide · Outlook VML guide · Outlook dark mode guide · Gmail dark mode guide · Apple Mail dark mode guide · React Email guide · Support matrix

Compile MJML Inspect output Preview modes Real-client QA
Known limitations

What MJML dark mode guidance cannot guarantee

Compiler output

MJML versions can change markup

Selectors that work today can miss after compiler updates, minification changes, package changes or custom build steps.

Gmail

Gmail is not one renderer

Gmail Web, iOS, Android and non-Google accounts can support different CSS and transform colours differently.

Outlook

Outlook is multiple families

Classic Outlook Windows, new Outlook, Outlook.com, Mac and mobile should be tested separately.

VML

Button fallbacks are fragile

Compiled mj-button output is not a guarantee against classic Outlook dark mode mismatches.

Tokens

Runtime variables are limited

CSS custom properties can be useful in supported clients, but should not be the only colour system for Gmail, Outlook or Yahoo.

Simulation

No preview is perfect

MailMode can highlight likely issues, but real clients still vary by version, OS, account and remote-content settings.

Try MailMode

Test the email you are building

Paste HTML, MJML or React Email and compare light mode, dark mode and inversion previews before you send.

Try MailMode for free → Preview an MJML email in dark mode

No signup required

Related Guides

Keep exploring MailMode Learn

Read nextDark Mode CSS for HTML Email

Meta tags, media queries, client targeting and defensive patterns.

Read nextReact Email Dark Mode Previewing

Rendered HTML, Tailwind caveats and safe preview workflows.

Read nextGmail Dark Mode Email Rendering

Gmail Web, iOS, Android and GANGA rendering risks.

Read nextOutlook VML Buttons and Dark Mode

Classic Outlook button fallbacks, VML fills and dark mode risks.

Read nextEmail Client Dark Mode Support Matrix

A practical map of client families, techniques and MailMode preview modes.

References

Sources & Further Reading

Last Updated: 9th June 2026Sources Reviewed: 9th June 2026

Research note

This guide combines vendor documentation, industry testing references and MailMode’s own observations of common email rendering behaviour.

Email client behaviour can change over time, especially across app versions, operating systems and account types. Treat this guide as a practical developer reference rather than official documentation from Microsoft, Google, Apple or any other email client provider.

Official MJML/project docs

MJML documentationMJML GitHubMJML releases

MJML component docs

mj-headmj-stylemj-rawmj-html-attributesmj-bodymj-button

Gmail developer references

Google: Gmail CSS supportHTeuMeuLeu: Gmail blend-mode workaroundHowToTarget.email Gmail selectors

Outlook platform references

Outlook.com data-og* notesMicrosoft Support: dark mode in OutlookMicrosoft: New Outlook for Windows overview

Apple and standards references

WebKit dark mode supportCan I Email: prefers-color-schemeCan I Email: color-scheme meta

CSS support data

Can I Email: CSS variablesCan I Email: mix-blend-modeCan I Email: linear-gradientCan I Email: display noneCan I Email: max-height

MJML issue research

MJML body class issuesMJML Outlook button issuesMJML Apple Mail image issues
© 2026 MailMode. Technical email guides. Docs · Learn · Changelog · About · Status · Privacy · Terms