Based on my research and also the lack of answers, it looks like the overall MJML tooling ecosystem is not in the best of states. I think for now the best option is to use the workaround I provided. Here is a detailed breakdown of the options available.
Style element <mj-style>
: (most likely the best option)
<!-- prettier-ignore -->
<mj-style css-inline="inline" />
.content {
color: green !important;
}
</mj-style>
Pros:
Cons:
- No Prettier formatting (ref).
An external CSS file:
<mj-include path="./default.css" type="css" css-inline="inline" />
- Pros:
- You can import a CSS file that will get normal Prettier treatment.
- Standard pattern where CSS lives outside the document.
- Cons:
- It also won't work with the online MJML editor tool without merging back your CSS file. This is very annoying and makes it hard to maintain.
<mj-include>
can report miss flagged error depending on our your project is setup.
- It does not work with the "official" VSCode plugin (you have to use this one).
MJML inline styles:
<mj-text color="#fff" padding="0" font-weight="400" font-size="16px" line-height="1.65" />
- Pros:
- Cons:
- You possibly will repeat a lot of the same style and maintenance can become problematic.
Style element <mj-class>
:
<mj-class name="blue" color="blue" />
Pros:
- Benefits from the re-usability of CSS without having to use CSS, avoiding Prettier issues.
Cons:
- Not as flexible as CSS in terms of selectors which can lead to repetition and maintenance issues.