GitHub

Unlayer Elements

Write once in React. Render emails, web pages, and PDFs from the same component tree.

npm version CI codecov license downloads


Unlayer Elements: the same JSX rendered as email, web, and document output

Unlayer Elements is an open-source React component library that lets you build content once and render it across three output modes:

  • Email → Outlook, Gmail, Yahoo, Apple Mail
  • Web → Responsive pages and embedded experiences
  • Document → Print-ready HTML for PDF generation

Unlayer Elements: Architecture

Elements is built and maintained by the team behind Unlayer, the content creation platform used by thousands of companies to power email, page, and document experiences inside their products.

Why Elements?

Tool Email Web PDF
React Email
MJML
PDF libraries
Elements

Elements is designed for teams that need to generate email, web, and document experiences from a single React codebase.

Quick Start

npm install @unlayer/react-elements
import {
  Email, Row, Column, ColumnLayouts,
  Heading, Paragraph, Button, renderToHtml
} from '@unlayer/react-elements';
function WelcomeEmail() {
  return (
    <Email backgroundColor="#f0f0f0" contentWidth="600px">
      <Row layout={ColumnLayouts.OneColumn} backgroundColor="#ffffff" padding="20px">
        <Column>
          <Heading
            fontSize="24px"
            fontFamily={{ label: "Arial", value: "arial,helvetica,sans-serif" }}
          >
            Welcome!
          </Heading>
          <Paragraph html="Thanks for signing up." fontSize="14px" />
          <Button
            href="https://example.com"
            backgroundColor="#0879A1"
            color="#ffffff"
          >
            Get Started
          </Button>
        </Column>
      </Row>
    </Email>
  );
}
// Render to a complete HTML document (<!DOCTYPE ...> to </html>) —
// email-client-safe shell included, no React hydration markers
const html = renderToHtml(<WelcomeEmail />);

Features

One Component Tree

Build content once and render it as email, web, or document. Share components, styling, and content across all three output modes from the same React codebase.

React Developer Workflow

Works with React, Next.js, Remix, and Server Components. Use familiar JSX patterns and existing frontend workflows without learning a new templating language.

Production Output

Generates email-safe HTML, responsive web HTML, and print-ready HTML for PDF generation — optimized output for each destination without maintaining separate implementations.

Visual Builder Compatible

Export Unlayer-compatible design JSON with renderToJson() for round-tripping between code and the visual editor. Ideal for teams that want the flexibility of code alongside visual editing workflows.

TypeScript First

Built with TypeScript from the ground up — full type definitions, autocomplete for components and props, and safer development with better IDE support.

Clean HTML Output

renderToHtml() generates a complete, production-ready HTML document with no React hydration markers, no framework artifacts, and no client-side JavaScript required. Need to compose the document yourself? renderToHtmlParts() returns { head, body } chunks.

Lightweight & Tree-Shakeable

~12KB gzipped (under 60KB ESM), tree-shakeable, with zero client-side JavaScript required. Designed for performance-sensitive applications and server-side rendering environments.

Real-World Use Cases

Transactional Emails

Build and maintain order confirmations, password resets, and receipts from the same React codebase that powers your application.

PDF Generation

Generate invoices, contracts, and reports server-side without maintaining a separate PDF system.

CMS-Driven Content

Render content from a CMS, API, or database into emails, web pages, and documents using a shared component model.

Email + Web Parity

Publish the same content as an email campaign, a web archive, and a public landing page from a single source of truth.

Components

Component Description
<Email> Root wrapper — email-safe HTML (tables for Outlook/Gmail)
<Page> Root wrapper — responsive web (div + flexbox)
<Document> Root wrapper — print/PDF optimized
<Row> Layout container with column layout support
<Column> Column inside a Row
<Button> CTA button with hover states and links
<Heading> Heading (h1–h4)
<Paragraph> Rich text with plain text or HTML content
<Image> Responsive image with alt text
<Divider> Horizontal separator
<Social> Social media icon links
<Menu> Navigation menu
<Table> Data table
<Video> YouTube/Vimeo embed
<Html> Custom HTML passthrough

Structure

Components follow a strict hierarchy:

" ← sets render mode ← layout container ← must match layout column count

Read the original on github.com ↗