
Security News
Suno Breached via Shai-Hulud Worm, Leaked Code Exposes AI Music Scraping
A Shai-Hulud infection exposed Suno's source code, which shows the AI music startup stream-ripped tracks to train its models.
minify-html-css
Advanced tools
🔽 A JavaScript (TypeScript) library to minify HTML and CSS.
I created this project to bring together the most performant HTML and CSS minifier libraries (according to my tests and findings) as clean, easy-to-use functions with well-documented options. The goal is to make web minification accessible, fast, and developer-friendly.
npm install minify-html-css
import { minifyHTML } from 'minify-html-css';
const html = `
<div>
<!-- This is a comment -->
<h1> Hello World! </h1>
<style>
body { color: red; }
</style>
</div>
`;
const minifiedHtml = minifyHTML(html).code;
console.log(minifiedHtml); // "<div><h1>Hello World!</h1><style>body{color:red}</style></div>"
minifyHTML(input: string, options?: MinifyHTMLOptions): TransformOutputDescription:
Minifies an HTML string by removing unnecessary whitespace, comments, and compressing inline JS and CSS (where supported). Returns an object containing code property for transformed code and errors array for possible errors.
Implementation note: This function is a wrapper around the
@swc/htmlpackage and uses its minification logic under the hood.
Parameters:
input (string): The HTML code to minify.options? (MinifyHTMLOptions): Configuration object for fine-grained control.The available options are:
| Option | Type | Default | Description |
|---|---|---|---|
collapseWhitespaces | 'none' | 'all' | 'smart' | 'conservative' | 'advanced-conservative' | 'only-metadata' | 'all' | Controls how whitespace is collapsed and removed throughout the document. |
removeEmptyMetadataElements | boolean | true | Removes empty metadata elements such as <script>, <style>, <meta>, and <link>. |
removeComments | boolean | true | Removes all HTML comments unless matched by preserveComments. |
preserveComments | string[] | Array of regex strings; comments matching any are preserved. You can override the default patterns. | |
minifyConditionalComments | boolean | true | Minifies IE conditional comments. |
removeEmptyAttributes | boolean | true | Removes empty attributes from HTML tags (when safe). |
removeRedundantAttributes | 'none' | 'all' | 'smart' | 'smart' | Controls removal of redundant or default attributes. |
collapseBooleanAttributes | boolean | true | Collapses boolean attributes to their short form (e.g. checked). |
normalizeAttributes | boolean | true | Cleans up attribute values by removing unnecessary spaces, and strips javascript: from event handlers. |
minifyJson | boolean | { pretty?: boolean } | true | Minifies embedded JSON within <script type="application/json">. |
minifyJs | boolean | true | Minifies inline JavaScript. |
minifyCss | boolean | true | Minifies inline CSS. |
minifyAdditionalScriptsContent | [string, MinifierType][] | Minifies additional <script> types, specifying type pattern and minifier. | |
minifyAdditionalAttributes | [string, MinifierType][] | Minifies additional attribute values, specifying attribute name pattern and minifier. | |
sortSpaceSeparatedAttributeValues | boolean | false | Sorts space-separated attribute values like class or rel. |
sortAttributes | boolean | false | Sorts all attributes of each element in reverse alphabetical order. |
tagOmission | boolean | true | Omits optional end tags when valid per HTML spec. |
quotes | boolean | false | Always wrap attribute values in quotes. |
For detailed type definitions and documentation, see src/minify-html-types.ts.
minifyCSS(input: string, options?: MinifyCSSOptions): TransformResultDescription: Minifies CSS code by removing unnecessary whitespace, optimizing values, and applying various transformations.
Implementation note: This function is a wrapper around the
lightningcsspackage and uses its minification logic under the hood.
Parameters:
input (string): The CSS code to minify.options? (MinifyCSSOptions): Configuration object for fine-grained control.For detailed type definitions and documentation for options, see src/minify-css-types.ts.
minifyCSS) built on top of Lightning CSSWe welcome contributions!
Requirements:
Steps:
git switch -c my-featurebun run lint && bun test (This is automatically done when you open a pull request) to ensure everything passes.git commit -m "Add my feature"Please read our CONTRIBUTING.md for more details.
This project is licensed under the MIT License.
Types License Notice:
src/minify-html-types.ts are adapted from the SWC Project and are licensed under the Apache License, Version 2.0.@swc/html under the hood for actual HTML minification.FAQs
🔽 A library to minify HTML and CSS.
The npm package minify-html-css receives a total of 11 weekly downloads. As such, minify-html-css popularity was classified as not popular.
We found that minify-html-css demonstrated a healthy version release cadence and project activity because the last version was released less than 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
A Shai-Hulud infection exposed Suno's source code, which shows the AI music startup stream-ripped tracks to train its models.

Security News
Vercel is formalizing a monthly release program for Next.js. The change follows React2Shell and a sharp rise in AI-assisted vulnerability discovery.

Research
/Security News
11 malicious NuGet tools pose as game cheats to deploy Windows payloads, track hosts, and use Google Sheets for telemetry and control.