Overview
TheRenderer class is the core of Better Svelte Email. It converts Svelte components into email-safe HTML with fully inlined Tailwind CSS styles, ensuring maximum compatibility across email clients.
Import
Constructor
TheRenderer constructor supports two overloads for backward compatibility:
Constructor Overload 1: With RendererOptions
Configuration options for the renderer. See RendererOptions for details.
Constructor Overload 2: Legacy TailwindConfig (Deprecated)
Tailwind CSS configuration object (v3). This overload is maintained for backward compatibility. Use the
RendererOptions overload instead.The constructor automatically detects which overload you’re using based on the argument provided. If the object contains
tailwindConfig, customCSS, or baseFontSize properties, it’s treated as RendererOptions. Otherwise, it’s treated as a legacy TailwindConfig.Methods
render()
Renders a Svelte component to email-safe HTML with inlined Tailwind CSS.The Svelte component to render. Import your
.svelte file and pass it directly.Options for rendering the component. See RenderOptions for details.
A promise that resolves to an email-safe HTML string with inlined styles and XHTML 1.0 Transitional DOCTYPE.
What render() does automatically
Therender() method performs several transformations to ensure email compatibility:
- Inlines Tailwind classes - Converts all Tailwind utility classes to inline
styleattributes - Extracts media queries - Places non-inlinable styles (responsive classes, pseudo-classes) into a
<style>tag in the<head> - Replaces DOCTYPE - Changes DOCTYPE to XHTML 1.0 Transitional for better email client compatibility
- Removes comments - Strips HTML comments from the output
- Cleans Svelte artifacts - Removes Svelte-specific attributes and markers
- Resolves CSS variables - Resolves custom properties defined in
customCSSor Tailwind config - Applies global styles - Inlines styles from global selectors (
*, element selectors,:root)
If you use non-inlinable Tailwind classes (like responsive utilities or hover states), your component must include a
<head> element. The renderer will inject a <style> tag with media queries into it. Without a <head>, the render will throw an error.Usage Examples
Basic usage
With custom Tailwind configuration
With custom CSS (e.g., app theme variables)
With component props
Complete example with all options
Using CSS variables with @property
Type Definitions
See Also
- RendererOptions - Configuration options for the Renderer
- RenderOptions - Options for the render() method
- toPlainText() - Convert HTML to plain text