PreMailer.Net 2.6.0

dotnet add package PreMailer.Net --version 2.6.0
NuGet\Install-Package PreMailer.Net -Version 2.6.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PreMailer.Net" Version="2.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PreMailer.Net --version 2.6.0
#r "nuget: PreMailer.Net, 2.6.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PreMailer.Net as a Cake Addin
#addin nuget:?package=PreMailer.Net&version=2.6.0

// Install PreMailer.Net as a Cake Tool
#tool nuget:?package=PreMailer.Net&version=2.6.0

PreMailer.Net .NET Core build Nuget count

C# Library for moving CSS to inline style attributes, to gain maximum E-mail client compatibility.


Static method on PreMailer class

string htmlSource = File.ReadAllText(@"C:\Workspace\testmail.html");

var result = PreMailer.MoveCssInline(htmlSource);

result.Html 		// Resultant HTML, with CSS in-lined.
result.Warnings 	// string[] of any warnings that occurred during processing.

Set up PreMailer instance

string htmlSource = File.ReadAllText(@"C:\Workspace\testmail.html");

var pm = new PreMailer(htmlSource);
pm.AddAnalyticsTags(source, medium, campaign, content, domain = null); // Optional to add analytics tags

var result = pm.MoveCssInline(...);

result.Html 		// Resultant HTML, with CSS in-lined.
result.Warnings 	// string[] of any warnings that occurred during processing.


The following options can be passed to the PreMailer.MoveCssInline method to configure it's behaviour:

  • baseUri(Uri = null) - Base URL to apply to link elements with href values ending with .css.
  • removeStyleElements(bool = false) - Removes elements that were used to source CSS (currently, only style is supported).
  • ignoreElements(string = null) - CSS selector of element(s) not to inline. Useful for mobile styles (see below).
  • css(string = null) - A string containing a style-sheet for inlining.
  • stripIdAndClassAttributes(bool = false) - True to strip ID and class attributes.
  • removeComments(bool = false) - True to remove comments, false to leave them intact.

External style sheets

Sometimes it's handy to reference external style sheets with a <link href="..." /> element. PreMailer will download and use external style sheets as long as the value of href ends with .css.

Both absolute and relative URLs are supported. If the URL is relative, you must specify the baseUri parameter in either the constructor, or when calling the static MoveCssInline method.

<link /> elements that match the ignoreElements selector won't be downloaded.

Media queries

If you want to apply mobile styles to your e-mail, you should put your mobile specific styles in its own style block that targets the appropriate devices using media queries.

But since you cannot know by the time of sending an e-mail whether or not it will be viewed on a mobile device, the style block that targets mobile devices should not be inlined!

To ignore a style block, you need to specify an ignore selector when calling the MoveCssInline method, like this:

var result = PreMailer.MoveCssInline(input, false, ignoreElements: "#ignore");

And your mobile specific style block should have an ID of ignore:

<style type="text/css" id="ignore">.target { width: 1337px; }</style>

Premailer specific CSS becomes HTML attributes

Premailer looks for the use of CSS attributes prefixed with -premailer and will proxy the value through to the DOM element as an attribute.

For example

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

will make a table element render as

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

Custom DOM Processing

using(var pm = new PreMailer(html)){

  var document = pm.Document;

  // use AngleSharp to process document before moving css inline ...

  var result = pm.MoveCssInline();


  • Pseudo classes/elements which not supported by external dependencies, or doesn't make sense in email, will be ignored and logged to the InlineResult.Warnings collection.


NuGet: PreMailer.Net


Among others


PreMailer.Net is available under the MIT license. See the LICENSE file for more info.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (30)

Showing the top 5 NuGet packages that depend on PreMailer.Net:

Package Downloads
Kentico.Xperience.Libraries The ID prefix of this package has been reserved for one of the owners of this package by

The runtime assemblies for libraries and applications that use Kentico Xperience API.


ASP.NET Core based CMS


Evernote Cloud SDK for Windows


Package Description


Application Component for the Alliance Business Suite.

GitHub repositories (5)

Showing the top 5 popular GitHub repositories that depend on PreMailer.Net:

Repository Stars
Open Source ASP.NET MVC Enterprise eCommerce Shopping Cart Solution
A modular, scalable and ultra-fast open-source all-in-one eCommerce platform built on ASP.NET Core 7
An open source CMS, Relationship Management System (RMS) and Church Management System (ChMS) all rolled into one.
OAuth providers for Owin
Smtp server for mass emailing, managing email lists and more. Built on .NET Core. Linux, MAC and Windows compatible.
Version Downloads Last updated
2.6.0 16,540 5/22/2024
2.5.0 232,283 11/24/2023
2.4.0 2,648,081 11/2/2021
2.3.0 68,545 10/8/2021
2.2.0 2,790,346 4/8/2020
2.1.3 520,321 10/30/2019
2.1.1 62,323 9/16/2019
2.1.0 34,209 9/6/2019
2.0.1 615,909 12/7/2018
2.0.0 944,248 7/18/2018
2.0.0-beta2 94,699 3/21/2017
2.0.0-beta1 2,758 3/21/2017
1.5.5 833,676 11/7/2016
1.5.4 132,626 8/2/2016
1.5.3 80,205 4/15/2016
1.5.2 17,452 4/12/2016
1.5.1 20,071 3/29/2016
1.5.0 23,696 2/23/2016
1.4.3 43,857 12/16/2015
1.4.2 174,641 7/29/2015
1.4.1 42,518 5/22/2015
1.4.0 4,576 5/3/2015
1.3.1 69,054 3/22/2015
1.3.0 64,784 3/1/2015
1.2.9 161,150 11/19/2014
1.2.8 17,993 10/28/2014
1.2.7 257,900 7/28/2014
1.2.6 33,398 5/22/2014
1.2.5 2,304 5/22/2014
1.2.4 112,187 2/18/2014
1.2.3 7,824 11/25/2013
1.2.2 2,566 11/13/2013
1.2.1 2,342 11/12/2013
1.2.0 2,367 11/11/2013
1.1.3 2,668 11/7/2013
1.1.2 16,566 6/5/2012
1.1.1 15,168 11/5/2011
1.1.0 3,111 9/29/2011
1.0.0 3,714 9/12/2011

What's Changed

     * Bump AngleSharp from 1.0.7 to 1.1.0. Only the IMarkupFormatter from AngleSharp is exposed as public api and that interface has not changed in that version jump so this should not cause any breakages for users.
     Full Changelog: