Tailwind configuration
Every email template requires aTailwind wrapper component with configuration:
Tailwind configuration object that extends the default theme
Dark mode strategy. Use
"class" for manual controlColor system
Define your brand colors in the Tailwind config for consistent theming:Brand colors
Primary brand color (hex format recommended)
Muted or secondary color for less prominent elements
Background color (supports HSL with CSS variables)
Text color for content on background
Color usage in classes
Once defined, use colors with standard Tailwind syntax:Use opacity modifiers (
/80, /75, /60) for lighter color variants: text-primary/80 creates 80% opacity.Spacing utilities
Spacing in email templates uses Tailwind’s spacing scale, but explicit pixel values often work more reliably:Margin classes
Margin on all sides
m-0- 0pxm-4- 16pxm-8- 32px
Horizontal margin (left and right)
mx-auto- Auto margins (centers element)mx-0- 0px horizontal margin
Vertical margin (top and bottom)
my-4- 16px vertical marginmy-8- 32px vertical margin
Individual side margins
mt-4- 16px top marginmb-8- 32px bottom margin
Padding classes
Padding on all sides
p-0- 0pxp-4- 16px
Horizontal padding
px-4- 16px horizontal paddingpx-[24px]- Explicit 24px padding
Vertical padding
py-5- 20px vertical paddingpy-[12px]- Explicit 12px padding
Typography
Text styling classes for fonts, sizes, weights, and line heights:Font family
Stick to web-safe fonts (Arial, Helvetica, Georgia, Times New Roman) or use font stacks with fallbacks for maximum compatibility.
Font size
Predefined sizes:
text-xs- 12pxtext-sm- 14pxtext-base- 16pxtext-lg- 18pxtext-xl- 20pxtext-[14px]- Explicit pixel valuetext-[32px]- Large explicit size
Font weight
Weight options:
font-normal- 400 (regular)font-medium- 500font-semibold- 600font-bold- 700
Line height
Line height values:
leading-tight- 1.25leading-6- 24px (1.5rem)leading-[4rem]- Explicit 4rem value
Text alignment
Alignment options:
text-left- Left aligntext-center- Center aligntext-right- Right align
Text decoration
Adds underline to text (commonly used for links)
Controls underline distance:
underline-offset-2- 2px offset
Border and radius
Border utilities for creating outlines and rounded corners:Border width
Border width:
border- 1px borderborder-[1px]- Explicit 1pxborder-2- 2px border
Border style
Solid border style (default)
Border color
Border color:
border-zinc-200- Light grayborder-[#eaeaea]- Explicit hex color
Border radius
Corner rounding:
rounded-lg- Large radius (from config)rounded-[8px]- Explicit 8px radius (recommended)rounded-[12px]- Explicit 12px radiusrounded-2xl- Very large radius
Background colors
Background color:
bg-white- White backgroundbg-brand- Brand color backgroundbg-[hsl(240,4.8%,95.9%)]- HSL colorbg-[hsl(240,4.8%,95.9%)]/50- With 50% opacity
Layout utilities
Display
Flexbox display (limited email client support - use with caution)
Width:
w-full- 100% widthw-fit- Fit contentw-1/2- 50% widthw-1/3- 33.33% widthw-[50px]- Explicit 50px width
Height:
h-auto- Auto heighth-[200px]- Explicit height
Alignment
Vertical alignment (use with flex):
items-center- Center verticallyitems-start- Align to top
Horizontal alignment (use with flex):
justify-center- Center horizontallyjustify-between- Space between items
Flex direction
Flex direction:
flex-col- Vertical stackingflex-row- Horizontal layout
Object fit
For images:Image object fit:
object-cover- Covers area, may cropobject-contain- Contains within area
Aspect ratio:
aspect-video- 16:9 ratioaspect-square- 1:1 ratio
Opacity
Control element transparency:Opacity level:
opacity-50- 50% opacityopacity-75- 75% opacity
Cursor
Cursor style:
cursor-pointer- Pointer on hover (for clickable elements)
Inline styles
For properties not supported by Tailwind or that need precise control, use inline styles:Use inline styles for:
- Border properties on table elements
- Precise positioning
- Properties not available in Tailwind
- Client-specific workarounds
Common style patterns
Reusable style combinations for common email elements:Card/panel styling
Primary button
Secondary button
Body text
Heading text
Link text
Email client compatibility
Not all CSS properties work in all email clients. Here’s what to avoid:Avoid these CSS features
Safe alternatives
- Instead of Grid: Use table-based layouts with Row/Column
- Instead of Flexbox: Use table cells with alignment
- Instead of position: Use table structure and spacing
- Instead of box-shadow: Use borders or background gradients
Testing recommendations
Always test your styled emails in these clients:
- Gmail (web, iOS, Android)
- Outlook (Windows, Mac, web)
- Apple Mail (iOS, macOS)
- Yahoo Mail
- Thunderbird
Best practices
- Use explicit values: Prefer
px-[24px]overpx-6for consistency - Test across clients: Always test in major email clients before sending
- Progressive enhancement: Start with basic styling, add enhancements carefully
- Inline critical styles: Use inline styles for essential layout properties
- Keep it simple: Simpler designs have better cross-client compatibility
- Use color opacity: Leverage
/80,/75modifiers instead of separate color definitions