Quick reference

Premailer Cheatsheet

Quick reference guide for Premailer CSS inliner for HTML emails, covering custom CSS attributes and inline styling rules.

· Published

Premailer inlines CSS styles into HTML email templates for consistent rendering across email clients.

Custom Attribute Extensions

Premailer supports special -premailer- CSS properties to control HTML table attributes:

table, th, td {
  /* Set width attribute on table and cell tags */
  -premailer-width: 600px;
}

table, tr, th, td {
  /* Set height attribute on elements */
  -premailer-height: 50px;
}

table {
  /* Set HTML attributes on table tag */
  -premailer-cellpadding: 0;
  -premailer-cellspacing: 0;
  -premailer-border: 0;
}

CLI Usage

# Process input HTML file into inlined output
premailer input.html > output.html

# Fetch remote HTML template
premailer https://example.com/newsletter.html > inlined.html

Ruby API

require 'premailer'

premailer = Premailer.new('email.html', warn_level: Premailer::Warnings::SAFE)

# Output inlined HTML
File.open("output.html", "w") do |file|
  file.puts premailer.to_inline_css
end

# Output plain text alternative
File.open("output.txt", "w") do |file|
  file.puts premailer.to_plain_text
end
```\n

Related topics