HEEx function components for building emails, ported from react-email.
Every component renders client-compatible HTML (tables for layout, inline
styles, MSO conditional comments for Outlook) and accepts a style
attribute with either an inline CSS string or a style object (map or
keyword list), e.g. style={%{"font-size" => "14px", padding: 12}}.
Default styles are merged with the user's, user styles last so they win
by cascade. All other HTML attributes are forwarded to the underlying tag.
use PhoenixEmail
def welcome(assigns) do
~H"""
<.email>
<.head />
<.preview>What the inbox shows next to the subject</.preview>
<.body>
<.container>
<.heading as="h1">Hello</.heading>
<.text>Welcome aboard.</.text>
<.button href="https://example.com" style="padding:12px 20px">Start</.button>
</.container>
</.body>
</.email>
"""
end
Summary
Functions
The <body> of the email.
A link styled as a button.
A block of code with inline-styled syntax highlighting.
A piece of inline code.
A column (<td>) inside a <.row>.
Centered layout table that caps the email width at 37.5em (600px).
Root element of the email. Renders the <html> tag.
A web font, declared inside <.head>.
The <head> of the email, with the content-type and Apple message
reformatting meta tags. Put <.font> and extra meta tags in the slot.
A heading (h1–h6, chosen with as).
A horizontal divider.
An image with the resets email clients need.
A hyperlink, opening in a new tab by default.
Markdown rendered as email-safe HTML with inline styles.
Preview text shown by inboxes next to the subject line.
A table row. Put <.column> components in the slot.
Full-width layout table used to group content into blocks.
A paragraph of text.
Translates Tailwind utilities to an inline style string.
Functions
The <body> of the email.
Attributes
class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
A link styled as a button.
Padding declared in style (shorthand or longhands, px) is parsed and
reproduced with MSO conditional comments so the button keeps its size in
Outlook, which ignores padding on <a> tags — the same hack react-email
uses.
Attributes
href(:string) (required)target(:string) - Defaults tonil.class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
A block of code with inline-styled syntax highlighting.
Highlighting requires the optional :makeup dependency plus a lexer for
the language (for example :makeup_elixir); without them — or for unknown
languages — the code renders escaped but unstyled.
The theme is a map from makeup token type to inline CSS, plus a :base
entry for the <pre> tag. See PhoenixEmail.Highlight.default_theme/0.
<.code_block language="elixir" code={~S'''
defmodule Hello do
def world, do: :ok
end
'''} />Attributes
code(:string) (required)language(:string) - Defaults tonil.theme(:map) - Defaults tonil.class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
A piece of inline code.
Attributes
class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
A column (<td>) inside a <.row>.
Attributes
class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["align", "valign", "width", "height", "bgcolor"].
Slots
inner_block(required)
Centered layout table that caps the email width at 37.5em (600px).
Attributes
class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
Root element of the email. Renders the <html> tag.
Named email instead of html to read naturally alongside the other
components.
Attributes
lang(:string) - Defaults to"en".dir(:string) - Defaults to"ltr".- Global attributes are accepted.
Slots
inner_block(required)
A web font, declared inside <.head>.
Renders a <style> tag with an @font-face rule (plus mso-font-alt for
Outlook) and applies the family to every element.
<.font
font_family="Roboto"
fallback_font_family="Verdana"
web_font={%{url: "https://fonts.gstatic.com/.../roboto.woff2", format: "woff2"}}
/>Attributes
font_family(:string) (required)fallback_font_family(:string) - Defaults to"Verdana".web_font(:map) - a map with:urland:formatkeys. Defaults tonil.font_weight(:any) - Defaults to400.font_style(:string) - Defaults to"normal".
The <head> of the email, with the content-type and Apple message
reformatting meta tags. Put <.font> and extra meta tags in the slot.
Attributes
- Global attributes are accepted.
Slots
inner_block
A heading (h1–h6, chosen with as).
Margins can be set with the shorthand attributes m, mx, my, mt,
mr, mb and ml. Numbers are treated as px; strings are used as-is.
Attributes
as(:string) - Defaults to"h1". Must be one of"h1","h2","h3","h4","h5", or"h6".class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.m(:any) - Defaults tonil.mx(:any) - Defaults tonil.my(:any) - Defaults tonil.mt(:any) - Defaults tonil.mr(:any) - Defaults tonil.mb(:any) - Defaults tonil.ml(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
A horizontal divider.
Attributes
class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
An image with the resets email clients need.
Attributes
src(:string) (required)alt(:string) - Defaults tonil.width(:any) - Defaults tonil.height(:any) - Defaults tonil.class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
A hyperlink, opening in a new tab by default.
Attributes
href(:string) (required)target(:string) - Defaults to"_blank".class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
Markdown rendered as email-safe HTML with inline styles.
Requires the optional :earmark_parser dependency. Override the default
per-tag styles with the styles map (tag name to inline CSS); see
PhoenixEmail.Markdown.default_styles/0.
<.markdown content={@changelog} styles={%{h1: "color:#5e6ad2"}} />Attributes
content(:string) (required)styles(:map) - Defaults to%{}.container_style(:any) - Defaults tonil.- Global attributes are accepted.
Preview text shown by inboxes next to the subject line.
Renders a hidden div with the slot text (capped at 150
characters) padded with invisible characters so clients don't leak the
email body into the preview. Excluded from the plain text version.
Attributes
- Global attributes are accepted.
Slots
inner_block(required)
A table row. Put <.column> components in the slot.
Attributes
class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
Full-width layout table used to group content into blocks.
Attributes
class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
A paragraph of text.
Attributes
class(:string) - tailwind utilities, seePhoenixEmail.Tailwind. Defaults tonil.style(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
Translates Tailwind utilities to an inline style string.
Components take a class attribute directly; use tw/1 for raw HTML tags
inside templates, where react-email's <Tailwind> would also inline:
<span style={tw("text-black")}>{@username}</span>