Skip to content
Preflight for HTML email
Branch: master
Clone or download
Pull request Compare This branch is 88 commits behind premailer:master.
alexdunae Remove Dialect copyright notices from CSS files
The CSS was always intended to be under the main project’s license (BSD
3-clause).  These extra copyright notices should be removed to prevent
any ambiguity.
Latest commit be30fae Jun 1, 2016
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin cleanup Mar 16, 2016
lib fix for semicolon within brackets in style May 18, 2016
misc Hello, GitHub! Nov 27, 2009
test Remove Dialect copyright notices from CSS files Jun 1, 2016
.gitignore lock down versions so we can run safely in the future Mar 17, 2016
.jrubyrc Fix .jrubyrc to follow… May 15, 2013
.travis.yml lock down versions so we can run safely in the future Mar 17, 2016
Gemfile maxitest Mar 17, 2016
Gemfile.lock lock down versions so we can run safely in the future Mar 17, 2016 Doc cleanup Mar 21, 2012 Update README for 'ignore' flag Feb 9, 2016
Rakefile cleanup Mar 16, 2016
premailer.gemspec maxitest Mar 17, 2016

Premailer README Build Status

What is this?

For the best HTML e-mail delivery results, CSS should be inline. This is a huge pain and a simple newsletter becomes un-managable very quickly. This script is my solution.

  • CSS styles are converted to inline style attributes
    • Checks style and link[rel=stylesheet] tags and preserves existing inline attributes
  • Relative paths are converted to absolute paths
    • Checks links in href, src and CSS url('')
  • CSS properties are checked against e-mail client capabilities
    • Based on the Email Standards Project's guides
  • A plain text version is created (optional)

Premailer 2.0 is coming

I'm looking for input on a version 2.0 update to Premailer. Please visit the Premailer 2.0 Planning Page and give me your feedback.


Install the Premailer gem from RubyGems.

gem install premailer

or add it to your Gemfile and run bundle.


require 'rubygems' # optional for Ruby 1.9 or above.
require 'premailer'

premailer ='', :warn_level => Premailer::Warnings::SAFE)

# Write the HTML output"output.html", "w") do |fout|
  fout.puts premailer.to_inline_css

# Write the plain-text output"output.txt", "w") do |fout|
  fout.puts premailer.to_plain_text

# Output any CSS warnings
premailer.warnings.each do |w|
  puts "#{w[:message]} (#{w[:level]}) may not render properly in #{w[:clients]}"

Ruby Compatibility

Premailer is tested on Ruby 1.8.7, Ruby 1.9.2, Ruby 1.9.3, and Ruby 2.x.0 . It also works on REE. JRuby support is close; contributors are welcome. Checkout the latest build status on the Travis CI dashboard.

Premailer-specific CSS

Premailer looks for a few CSS attributes that make working with tables a bit easier.

CSS Attribute Availability
-premailer-width Available on table, th and td elements
-premailer-height Available on table, tr, th and td elements
-premailer-cellpadding Available on table elements
-premailer-cellspacing Available on table elements
data-premailer="ignore" Available on link and style elements. Premailer will ignore these elements entirely.

Each of these CSS declarations will be copied to appropriate element's attribute.

For example

table { -premailer-cellspacing: 5; -premailer-width: 500; }

will result in

<table cellspacing='5' width='500'>


Contributions are most welcome. Premailer was rotting away in a private SVN repository for too long and could use some TLC. Fork and patch to your heart's content. Please don't increment the version numbers, though.

A few areas that are particularly in need of love:

  • Improved test coverage
  • Move un-repeated background images defined in CSS for Outlook

Credits and code

Thanks to all the wonderful contributors for their updates.

Thanks to Greenhood + Company for sponsoring some of the 1.5.6 updates, and to Campaign Monitor for supporting the web interface.

The web interface can be found at

The source code can be found on GitHub.

Copyright by Alex Dunae (, e-mail 'code' at the same domain), 2007-2012. See for license details.

You can’t perform that action at this time.