Repository navigation
Mobile responsiveness & Container padding in React Email #3630
DoniyorLatipov
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
First off — if anyone can point me to solid documentation on responsiveness in React Email, I'd really appreciate it. Everything below is just what I pieced together on my own, because I couldn't find anything more useful.
Adding responsiveness
Here's the Tailwind config I've been using. These are just the values I found convenient — feel free to change them:
From there you use it exactly like normal Tailwind responsive classes (e.g.
sm:p-2).Problems I ran into
@media (600px >= width)), which aren't handled reliably across email clients.Solution
Merge all of those generated queries into a single
@media (max-width: 600px)block.I wrote a small script —
post-export-media-fix.mjs— that does exactly this. You can run it as part ofnpm run export.👉 Gist / script link
A side effect of this approach
The
sm:padding on theContainercomponent behaves unexpectedly.The regular padding classes get inherited by the inner
<td>, but thesm:classes stay on the outer<table>. Because of that, when you actually want to reduce padding on phones, you can end up increasing it instead — the base padding (on the<td>) and thesm:padding (on the<table>) stack on top of each other.My workaround
Manually move the
sm_p-*class off the<table>and onto the child<td>.Bonus: stacking columns on mobile
This one's also handy — a utility class that turns a row into a stacked column. Apply it to each
<td>you want to stack:Thanks for reading! Any feedback is very welcome. 🙌
P.S. Another side effect — still unresolved
Because the correct output depends on the post-export script, the built-in test-email feature becomes unreliable. React Email sends the test message using the raw
exportoutput — i.e. the HTML before my script has finalized it — so the email that actually lands in the inbox still has the scattered, un-merged media queries and doesn't render the way the finalized version does. Right now the only way I trust a preview is to check HTML that has already been through the script, but I haven't found a clean way to make the built-in test-send respect that step. Ideas welcome 🧐All reactions