Many email clients support CSS background gradients. In this tutorial, you will learn how to use the tailwindcss-gradients plugin to add colorful gradients to your HTML email templates. We will also cover how to add a VML fallback for Outlook on Windows.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/maizzle/maizzle.com/llms.txt
Use this file to discover all available pages before exploring further.
Getting started
Let’s start by creating a new Maizzle project../example-gradients, and select the Default Starter.
Choose Yes when prompted to Install dependencies.
After dependencies finish installing, change the current directory to example-gradients:
tailwindcss-gradients plugin:
example-gradients folder in your favorite code editor.
CSS Gradients
Let’s configure and usetailwindcss-gradients with Tailwind CSS.
Tailwind CSS config
We need to tell Tailwind CSS to use the plugin. Edittailwind.config.js and require() the plugin inside the plugins: [] array:
tailwind.config.js
theme: {} key from tailwind.config.js.
For example, let’s register linear gradients based on the existing color palette:
tailwind.config.js
tailwindcss-gradients can generate many other types of gradients (although not all are supported in email). See all configuration options.Use in HTML
Simply add the utility class on an element that supportsbackground-image CSS.
We also specify a background color first, so that email clients that don’t support CSS background-image gradients can display a fallback:
emails/example.html
Outlook VML
Outlook for Windows doesn’t support CSS gradients, but we can use VML. You need to add it right after the element with the CSS gradient class:emails/example.html
<v:rect> element - it is recommended instead of using mso-width-percent: 1000;, as that is pretty buggy (especially in Outlook 2013).
The width of the
<v:rect> element needs to match the width of its parent element.Body gradient
We can also add a VML gradient to the body of the email. To achieve this, we:- create a
<div>that wraps our template: this will be used as the solid background color fallback - place the VML code immediately inside that div, basically wrapping our entire template. Note how we’re using
mso-width-percent: 1000;instead of a fixed width on the<v:rect>
emails/example.html
Avoid inlining
Most email clients that support CSS gradients also support@media queries.
We can register a screen breakpoint to prevent Juice from inlining our gradient:
tailwind.config.js
emails/example.html
Resources
- tailwindcss-gradients plugin
- GitHub repository for this tutorial