npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

tailwindinline

v1.0.0

Published

tailwind html to inline style html

Readme

TailwindInline

A utility that converts HTML with Tailwind CSS classes into HTML with inline styles. Perfect for scenarios where you need to convert Tailwind-styled HTML into a format that works with PDF generation services or email clients that don't support external stylesheets.

Why?

I use this library to build a document that looks like the PDF I'd like with Tailwind, use the frontend framework I'm using at the moment to insert data and/or graphs (that render to SVG, I recommend Apache ECharts for this rendering functionality) and then output pure HTML from whatever format the framework uses (in React this is accomplished with ReactDOMServer.renderToString(component)), convert it to inline styled HTML with this package, and then send the pure HTML file to an HTML-to-PDF API like api2pdf (which while unaffiliated seems relatively cheap).

It enables you to at runtime convert from an HTML string with Tailwind classes to an HTML string with inline styles. I find this easier than supplying the PDF API with two files since I haven't found the most reliable PDF generation APIs.

Features

  • Converts Tailwind CSS classes to inline styles
  • Supports custom Tailwind configurations
  • Allows adding custom CSS that gets processed alongside Tailwind
  • Pure in-memory processing with no file system operations
  • Preserves existing inline styles
  • Handles arbitrary values and complex class combinations
  • Fully asynchronous and efficient

Installation

npm install tailwindinline

Usage

import TailwindToInline from 'tailwindinline'

// Basic usage
const twi = new TailwindToInline()
const htmlWithInlineStyles = await twi.convert('<div class="pt-2 pb-[40px] border-2 border-[#0f0]"></div>')
/*
<div 
  class="pt-2 pb-[40px] border-2 border-[#0f0]" 
  style="padding-top: 0.5rem; padding-bottom: 40px; border-width: 2px; border-color: #0f0; box-sizing: border-box;"
></div>
*/

// With custom Tailwind config
const twiWithConfig = new TailwindToInline({ 
  config: './path/to/tailwind.config.js'
})

// With custom CSS
const twiWithCustom = new TailwindToInline({ 
  custom: `
    .custom-button { 
      background-color: purple;
      border-radius: 9999px;
    }
  `
})

// With both custom config and CSS
const twiWithBoth = new TailwindToInline({ 
  config: './path/to/tailwind.config.js',
  custom: `
    .custom-button { 
      background-color: purple;
      border-radius: 9999px;
    }
  `
})

// All methods return promises
const result = await twiWithBoth.convert('<button class="custom-button p-4">Click me</button>')

Parameters

  • config: Optional path to your tailwind.config.js file (relative path). Use this if you have custom theme extensions like colors, spacing, or other Tailwind customizations.
  • custom: Optional CSS string that gets processed alongside Tailwind. Perfect for adding custom styles that aren't part of your Tailwind config.

How It Works

  1. Takes your HTML with Tailwind classes and processes it in memory
  2. Applies your custom Tailwind config (if provided) to handle any theme extensions
  3. Merges in your custom CSS (if provided) with the Tailwind styles
  4. Uses PostCSS and the Tailwind CSS API to generate the final styles
  5. Converts all applicable classes to inline styles while preserving any existing inline styles
  6. Returns the processed HTML with all styles inlined

The library now processes everything in memory without creating temporary files or running CLI commands, making it faster and more reliable. It properly handles async operations and ensures all styles (Tailwind, custom theme extensions, and custom CSS) are correctly merged and applied.

Contributing

Questions/comments/improvements/suggestions? Contributions welcome.

License

MIT