Skip to main content
These components form the foundational HTML structure of your email. Every email should include these components in the proper hierarchy.

Html

The root HTML element that wraps your entire email. Automatically includes the proper DOCTYPE for email compatibility.

Props

lang
string
default:"en"
Language code for the email content
dir
'ltr' | 'rtl' | 'auto'
default:"ltr"
Text direction for the email
style
string
Inline CSS styles
children
snippet
Email content (typically Head and Body components)
All standard HTML attributes are also supported via HTMLHtmlAttributes.

Usage

<Html lang="en" dir="ltr">
  <Head />
  <Body>
    <!-- Email content -->
  </Body>
</Html>
<Html>
  <Head />
  <Body>
    <Text>Hello World</Text>
  </Body>
</Html>

Contains meta tags and email client compatibility settings. Automatically includes essential meta tags for responsive emails.

Props

children
snippet
Additional head content (style tags, meta tags, etc.)

Default Meta Tags

The Head component automatically includes:
  • content-type with UTF-8 charset
  • viewport for mobile responsiveness
  • x-apple-disable-message-reformatting for Apple Mail
  • x-ua-compatible for IE Edge mode

Usage

<Head>
  <!-- Optional: Add custom styles or meta tags -->
</Head>
<Html>
  <Head />
  <Body>
    <!-- Content -->
  </Body>
</Html>

Body

The email body wrapper. Uses table-based layout for maximum email client compatibility.

Props

style
string
Inline CSS styles applied to the body content wrapper
class
string
Tailwind CSS classes or custom CSS classes
children
snippet
Email body content
All standard HTML body attributes are supported via HTMLAttributes<HTMLBodyElement>.

Usage

<Body class="bg-gray-50 font-sans">
  <Container>
    <!-- Email content -->
  </Container>
</Body>
<Body>
  <Text>Email content goes here</Text>
</Body>

Preview

Defines the preview text that appears in email client inboxes before the email is opened. This is crucial for engagement.

Props

preview
string
required
The preview text (max 150 characters)
All standard HTML div attributes are supported via HTMLAttributes<HTMLDivElement>.

Features

  • Automatically truncated to 150 characters
  • Hidden from the visible email content
  • Fills remaining space with invisible characters to prevent email clients from showing body text

Usage

<Preview preview="Your order has been confirmed and will ship soon!" />
<Body>
  <Preview preview="Welcome to our newsletter!" />
  <Container>
    <!-- Email content -->
  </Container>
</Body>

Complete Example

Here’s a complete email structure using all four components:
<script lang="ts">
  import { Html, Head, Body, Preview, Container, Heading, Text } from 'better-svelte-email';
</script>

<Html lang="en">
  <Head />
  <Body class="bg-white font-sans">
    <Preview preview="Your weekly digest is ready!" />
    <Container class="mx-auto my-10 max-w-xl p-5">
      <Heading as="h1" class="text-2xl font-bold text-gray-900">
        Your Weekly Digest
      </Heading>
      <Text class="text-gray-700">
        Here are the highlights from this week.
      </Text>
    </Container>
  </Body>
</Html>

Best Practices

Always include all four components in your email. The proper hierarchy is: Html > Head + Body > Preview + Container + Content
Write compelling preview text that encourages recipients to open your email. Think of it as a mini subject line.
The Body component uses table-based layout for compatibility. This is required for older email clients like Outlook.

Build docs developers (and LLMs) love