
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
inline-html-styles
Advanced tools
Inline (Tailwind) CSS stylesheets into HTML style attributes.
English | 中文
When you use Vue / React and TailwindCSS to develop a static page for the following scenarios. You can use this method to inline the CSS stylesheet into HTML style attributes.
Of course, I advice you should compile to Static Site Generation (SSG). To make it easier for you to work directly with html and css strings.
bun add inline-html-styles
pnpm add inline-html-styles
yarn add inline-html-styles
npm install inline-html-styles
You can also add -D to install it as a development dependency, depending on your project or usage scenario.
rem to pxYou can convert CSS units from rem to px.
import inlineStyles from 'inline-html-styles'
const html = `<div class="my-style"></div>`
const css = `.my-style { width: 10rem }`
const result = inlineStyles(html, css)
// Result: <div style="width: 160px;"></div>
calcThe function can simplify basic calc expressions in your CSS.
import inlineStyles from 'inline-html-styles'
const html = `<div class="my-style"></div>`
const css = `.my-style { width: calc(20px - 4px) }`
const result = inlineStyles(html, css)
// Result: <div style="width: 16px;"></div>
calcEven nested calc expressions can be simplified.
import inlineStyles from 'inline-html-styles'
const html = `<div class="my-style"></div>`
const css = `.my-style { width: calc(20px - calc(10px - 6px)) }`
const result = inlineStyles(html, css)
// Result: <div style="width: 16px;"></div>
calc Will Not Be SimplifiedWhen calc expressions involve different units, they will not be simplified but will be converted appropriately.
import inlineStyles from 'inline-html-styles'
const html = `<div class="my-style"></div>`
const css = `.my-style { width: calc(100vh - 4rem) }`
const result = inlineStyles(html, css)
// Result: <div style="width: calc(100vh - 64px);"></div>
CSS variables that are numerical can also be processed. And participate in calc Simplify
import inlineStyles from 'inline-html-styles'
const html = `<div class="my-style"></div>`
const css = `.my-style { --tw-space-y: 2; margin-top:calc(.5rem * var(--tw-space-y)) }`
const result = inlineStyles(html, css)
// Result: <div style="margin-top: 16px;"></div>
CSS color variables can be applied as well.
import inlineStyles from 'inline-html-styles'
const html = `<div class="my-style"></div>`
const css = `.my-style { --my-color: #888888; color: var(--my-color) }`
const result = inlineStyles(html, css)
// Result: <div style="color: #888888;"></div>
You can also use multiple properties, including custom properties (CSS variables), in a single style rule.
import inlineStyles from 'inline-html-styles'
const html = `<div class="my-style"></div>`
const css = `
.my-style {
--tw-space-y: 2;
--my-color: #888888;
width: 10rem;
margin-top:calc(.5rem * var(--tw-space-y));
height: calc(100vh - 4rem);
color: var(--my-color);
}`
const result = inlineStyles(html, css)
// Result: <div style="width: 160px; margin-top: 16px; height: calc(100vh - 64px); color: #888888;"></div>
Whether to convert rem to px.
Type: boolean
Default: true
Whether to convert CSS variables to static.
Type: boolean
Default: true
FAQs
Inline (Tailwind) CSS stylesheets into HTML style attributes.
We found that inline-html-styles demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.