New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

css-inline

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-inline

A WASM package for inlining CSS into HTML documents

  • 0.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23K
decreased by-10.53%
Maintainers
1
Weekly downloads
 
Created
Source

css-inline

ci npm version

Blazing-fast WASM package for inlining CSS into HTML documents.

Features:

  • Removing style tags after inlining;
  • Control if style tags should be processed;
  • Out-of-document CSS to inline;

The project supports CSS Syntax Level 3 implemented with Mozilla's Servo project components.

Usage

import { inline } from "css-inline";

var inlined = inline(
  `
  <html>
    <head>
      <title>Test</title>
      <style>h1 { color:red; }</style>
    </head>
    <body>
      <h1>Test</h1>
    </body>
  </html>
  `,
  { remove_style_tags: true }
)
// Inlined HTML looks like this:
// <html>
//   <head>
//     <title>Test</title>
//   </head>
//   <body>
//     <h1 style="color:red;">Test</h1>
//   </body>
// </html>
// Do something with the inlined HTML, e.g. send an email

If you'd like to skip CSS inlining for an HTML tag, add data-css-inline="ignore" attribute to it:

<head>
    <title>Test</title>
    <style>h1 { color:blue; }</style>
</head>
<body>
    <!-- The tag below won't receive additional styles -->
    <h1 data-css-inline="ignore">Big Text</h1>
</body>
</html>

This attribute also allows you to skip link and style tags:

<head>
    <title>Test</title>
    <!-- Styles below are ignored -->
    <style data-css-inline="ignore">h1 { color:blue; }</style>
</head>
<body>
    <h1>Big Text</h1>
</body>
</html>

Standards support & restrictions

css-inline is built on top of cssparser and relies on its behavior for CSS parsing. Notably:

  • Only HTML 5, XHTML is not supported;
  • Only CSS 3;
  • Only UTF-8 for string representation. Other document encodings are not yet supported.

Keywords

FAQs

Package last updated on 10 Jun 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc