Skip to content

unlayer/elements

Repository files navigation

Unlayer Elements

Unlayer Elements

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

npm version CI 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 clean HTML string — 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 production-ready HTML with no React hydration markers, no framework artifacts, and no client-side JavaScript required.

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:

<Email>              ← sets render mode
  <Row layout={…}>   ← layout container
    <Column>         ← must match layout column count
      <Button />     ← content components
      <Paragraph />
    </Column>
  </Row>
</Email>

Column Layouts

import { Row, Column, ColumnLayouts } from '@unlayer/react-elements';

// Each Row must contain the matching number of <Column> children.
<Row layout={ColumnLayouts.OneColumn}>                {/* [1]         → 100% */}
  <Column>{/* content */}</Column>
</Row>
<Row layout={ColumnLayouts.TwoEqual}>                 {/* [1,1]       → 50% + 50% */}
  <Column>{/* content */}</Column>
  <Column>{/* content */}</Column>
</Row>
<Row layout={ColumnLayouts.TwoWideNarrow}>            {/* [2,1]       → 67% + 33% */}
  <Column>{/* content */}</Column>
  <Column>{/* content */}</Column>
</Row>
<Row layout={ColumnLayouts.ThreeEqual}>               {/* [1,1,1]     → 33% each */}
  <Column>{/* content */}</Column>
  <Column>{/* content */}</Column>
  <Column>{/* content */}</Column>
</Row>
<Row layout={ColumnLayouts.FourEqual}>                {/* [1,1,1,1]   → 25% each */}
  <Column>{/* content */}</Column>
  <Column>{/* content */}</Column>
  <Column>{/* content */}</Column>
  <Column>{/* content */}</Column>
</Row>
<Row cells={[3, 1]}>                                  {/* custom ratio */}
  <Column>{/* content */}</Column>
  <Column>{/* content */}</Column>
</Row>

Documentation

For the full API reference, component props, design patterns, and common mistakes, see the React package documentation.

Packages

Package Description Published
@unlayer/react-elements React components and renderers npm
@unlayer-internal/shared-elements Framework-agnostic shared logic Internal
@unlayer/elements-demo Demo application

Development

# Prerequisites: Node.js (see .nvmrc), pnpm 9+

# Install dependencies
pnpm install

# Build all packages
pnpm build

# Run tests
pnpm test

# Run tests with coverage
pnpm test:coverage

# Launch Storybook
pnpm storybook:hub

Contributing

See CONTRIBUTING.md for setup instructions and guidelines.

License

MIT — Unlayer, Inc.

About

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

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages