How Rendering Works
Better Svelte Email uses a multi-step process to transform your Svelte components into email-safe HTML with inline styles that work across all email clients.The Rendering Pipeline
TheRenderer class orchestrates the entire rendering process:
Step-by-Step Process
Svelte Compilation
Your Svelte component is rendered to HTML using Svelte’s server-side rendering (This produces raw HTML with class attributes intact.
svelte/server).HTML Parsing
The HTML is parsed into an Abstract Syntax Tree (AST) using
parse5, enabling programmatic manipulation of the DOM structure.Class Collection
The renderer walks through the AST and collects all class names used in your components.From
src/lib/render/index.ts:152-164:Tailwind CSS Generation
Tailwind CSS v4 generates only the styles needed for the classes you actually used, keeping file sizes minimal.
Style Classification
Styles are separated into two categories:
- Inlinable: Basic styles that can be converted to inline
styleattributes - Non-inlinable: Responsive classes, pseudo-selectors, and media queries that must stay in
<style>tags
src/lib/render/utils/css/is-rule-inlinable.ts:6-39:Media Query Injection
Non-inlinable styles (responsive classes, hover states) are injected into a
<style> tag in the <head>:Style Priority
When multiple styles apply to an element, they’re combined in this order (lowest to highest priority):- Global styles - Universal selectors (
*) and element selectors (div,p) - Existing inline styles - Styles already in the
styleattribute - Class styles - Styles from Tailwind classes
src/lib/render/utils/tailwindcss/add-inlined-styles-to-element.ts:80-81:
Later styles override earlier ones, so your explicit inline styles always take precedence over class-based styles.
Configuration Options
Renderer Options
Render Options
Error Handling
Missing Head Element
If you use responsive classes without a<head> element, you’ll get a helpful error:
Unknown Classes
If you use classes that Tailwind doesn’t recognize, you’ll see a warning:Performance Considerations
Minimal CSS Generation
Better Svelte Email only generates CSS for classes you actually use. If you use 10 Tailwind classes, only those 10 classes are compiled.Caching Strategy
For production use, consider caching rendered emails:Next Steps
Tailwind Support
Learn how Tailwind classes are converted to inline styles
Plain Text
Generate plain text versions for accessibility