🌐
PyPI
pypi.org › project › minify-html
minify-html
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Readthedocs
htmlmin.readthedocs.io
htmlmin — htmlmin 0.1 documentation
You can also explicitly tell it ... a command-line tool for easy invocation and integration with existing workflows. To install via pip: pip install htmlmin ·...
🌐
PyPI
pypi.org › project › htmlmin
htmlmin · PyPI
A configurable HTML Minifier with safety features.
      » pip install htmlmin
    
Published   Dec 29, 2017
Version   0.1.12
🌐
GitHub
github.com › adamchainz › django-minify-html
GitHub - adamchainz/django-minify-html: Use minify-html, the extremely fast HTML + JS + CSS minifier, with Django.
Work smarter and faster with my book Boost Your Django DX which covers many ways to improve your development experience. Python 3.10 to 3.14 supported. Django 4.2 to 6.0 supported. Install with pip: python -m pip install django-minify-html ·
Starred by 158 users
Forked by 8 users
Languages   Python
🌐
PyPI
pypi.org › project › django-minify-html
django-minify-html · PyPI
Work smarter and faster with my book Boost Your Django DX which covers many ways to improve your development experience. Python 3.9 to 3.14 supported. Django 4.2 to 6.0 supported. Install with pip: python -m pip install django-minify-html ·
      » pip install django-minify-html
    
Published   Oct 27, 2025
Version   1.14.0
🌐
PyPI
pypi.org › project › minify-html › 0.4.5
minify-html · PyPI
Add the PyPI project as a dependency and install it using pip or pipenv. import minify_html try: minified = minify_html.minify("<p> Hello, world!
      » pip install minify-html
    
Published   Apr 06, 2021
Version   0.4.5
🌐
PyPI
pypi.org › project › Flask-Minify
Flask-Minify · PyPI
pip install Flask-Minify[go] With setup-tools · git clone https://github.com/mrf345/flask_minify.git · cd flask_minify · python setup.py install · In this example the extension will minify every HTML request, unless it's explicitly bypassed.
      » pip install Flask-Minify
    
Published   Mar 29, 2025
Version   0.50
Top answer
1 of 5
26

You can use htmlmin to minify your html:

import htmlmin

html = """
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Case</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body> 
<div class="container">
  <h2>Well</h2>
  <div class="well">Basic Well</div>
</div>
</body>
</html>
"""

minified = htmlmin.minify(html.decode("utf-8"), remove_empty_space=True)
print(minified)
2 of 5
12

htmlmin and html_slimmer are some simple html minifying tools for python. I have millions of html pages stored in my database and running htmlmin, I am able to reduce the page size between 5 and 50%. Neither of them do an optimal job at complete html minification (i.e. the font color #00000 can be reduced to #000), but it's a good start. I have a try/except block that runs htmlmin and then if that fails, html_slimmer because htmlmin seems to provide better compression, but it does not support non ascii characters.

Example Code:

import htmlmin
from slimmer import html_slimmer # or xhtml_slimmer, css_slimmer
try:
    html=htmlmin.minify(html, remove_comments=True, remove_empty_space=True)
except:
    html=html_slimmer( html.strip().replace('\n',' ').replace('\t',' ').replace('\r',' ')  )

Good Luck!

🌐
Gentoo
packages.gentoo.org › packages › dev-python › minify-html
dev-python/minify-html – Gentoo Packages
Extremely fast and smart HTML + JS + CSS minifier · https://github.com/wilsonzlin/minify-html/ Other homepage(s) https://pypi.org/project/minify-html/ Upstream · USE flags · Global Use Flags · debugpython_targets (Use Expand) pypy3_11 · python3_11 · python3_12 ·
🌐
GitHub
github.com › pelican-plugins › minify
GitHub - pelican-plugins/minify: Pelican plugin that minifies HTML, CSS, and JavaScript
Rust and Cargo can be installed ... manager or via: https://rustup.rs/ This plugin can be installed via: python -m pip install pelican-minify ·...
Starred by 10 users
Forked by 4 users
Languages   Python 92.1% | HTML 6.6%
Find elsewhere
🌐
GitHub
github.com › cobrateam › django-htmlmin
GitHub - cobrateam/django-htmlmin: HTML minifier for Python frameworks (not only Django, despite the name).
With minified HTML code, you reduce the size of the data transferred from the server to the client, which results in faster load times. To install django-htmlmin, run this on the terminal: : $ [sudo] pip install django-htmlmin ·
Starred by 544 users
Forked by 73 users
Languages   Python 55.4% | HTML 44.0% | Makefile 0.6%
🌐
GitHub
gist.github.com › waterrmalann › 7318e61de34341a3c3bf9964e144c547
Simple Python Utility to Minify HTML/CSS/JS! · GitHub
Simple Python Utility to Minify HTML/CSS/JS! GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com › juancarlospaco › css-html-js-minify
GitHub - juancarlospaco/css-html-js-minify: StandAlone Async cross-platform Minifier for the Web.
--zipy GZIP Minified files as '*.gz', CSS/JS only. --sort Alphabetically Sort CSS Properties, CSS only. --comments Keep comments, CSS/HTML only (Not Recommended) --overwrite Force overwrite all in-place (Not Recommended) --after AFTER Command to execute after run (Experimental).
Starred by 215 users
Forked by 20 users
Languages   Python
🌐
Libraries.io
libraries.io › pypi › minify-html
minify-html 0.18.1 on PyPI - Libraries.io - security & maintenance data for open source software
Add the PyPI project as a dependency and install it using pip or pipenv. import minify_html minified = minify_html.minify("<p> Hello, world!
🌐
Sm-26
sm-26.github.io › SWM-Wiki › plugins › minify-html
Minify HTML - Material for MkDocs
mkdocs-minify-plugin is an extension that minifies HTML by stripping all whitespace from the generated documentation. Install the plugin using pip with the following command:
🌐
GitHub
github.com › monosans › mkdocs-minify-html-plugin
GitHub - monosans/mkdocs-minify-html-plugin: MkDocs plugin for minification using minify-html, an extremely fast and smart HTML + JS + CSS minifier. · GitHub
MkDocs plugin for minification using minify-html, an extremely fast and smart HTML + JS + CSS minifier. Install: pip install -U mkdocs-minify-html-plugin · Activate in mkdocs.yml: plugins: - search - minify_html · A description of all options is available in the minify_html docs.
Author   monosans
🌐
PyPI
pypi.org › project › mkdocs-minify-plugin
mkdocs-minify-plugin · PyPI
HTML minification is done using htmlmin2. JS minification is done using jsmin. CSS minification is done using csscompressor. Install the plugin using pip: pip install mkdocs-minify-plugin ·
      » pip install mkdocs-minify-plugin
    
Published   Jan 29, 2024
Version   0.8.0
🌐
Educative
educative.io › answers › how-to-minify-html-in-flask-using-flask-minify
How to minify HTML in Flask using Flask-Minify
Flask-Minify library helps us to minify HTML, CSS, and JavaScript files. Install it with PIP: pip install Flask-Minify · There are two ways to set up: Minify every request. This will minify every request that returns from the application. from ...
🌐
GitHub
github.com › ciotto › css-html-js-minify
GitHub - ciotto/css-html-js-minify: StandAlone Async single-file cross-platform no-dependencies Unicode-ready Python3-ready Minifier for the Web.
css-html-js-minify.py file.htm css-html-js-minify.py file.css css-html-js-minify.py file.js css-html-js-minify.py /project/static/ ... sudo pip3 install git+https://raw.githubusercontent.com/juancarlospaco/css-html-js-minify/master/css-html-js-minify.py
Starred by 17 users
Forked by 41 users
Languages   Python 98.8% | Shell 1.2%
🌐
GitHub
github.com › hamidfzm › Flask-HTMLmin
GitHub - hamidfzm/Flask-HTMLmin: Flask HTML response minifier
Just add MINIFY_HTML = True to your deployment config to minify HTML and text responses of your flask application. To install Flask-HTMLmin, simply use pip: pip install Flask-HTMLmin · Or use pipenv: pipenv install Flask-HTMLmin ·
Starred by 101 users
Forked by 26 users
Languages   Python