We've been hosted on Digital Ocean since 2013 and highly recommend it for your hosting too. Try it now!

HTML Minifier

Online HTML Minifier/Compressor. Free! Provides an API. Simple Quick and Fast.

Written and hosted by Andrew Chilton (@andychilton) since 2015.

No ads in production.


Credits: Thanks to Cristian Tomatis for contributing this example.

import requests

url = 'https://html-minifier.com/raw'
data = {'input': open('index.html', 'rb').read()}
response = requests.post(url, data=data)

print response.text

Python - from the REPL

Credits: Thanks to Noam Yorav-Raphael for contributing this example.

>>> import requests
>>> requests.post('https://html-minifier.com/raw', data=dict(input=' ... ')).text

Python - a CLI tool

Credits: Thanks to Kyle S. for contributing this to the site.

# -*- coding: utf-8 -*-
import sys
import requests

    html_file = sys.argv[1]
    print("Missing input file")

# Grab the file contents
with open(html_file, 'r') as c:
    html = c.read()

# Pack it, ship it
payload = {'input': html}
url = 'https://html-minifier.com/raw'
print("Requesting mini-me of {}. . .".format(c.name))
r = requests.post(url, payload)

# Write out minified version
minified = html_file.rstrip('.html')+'.min.html'
with open(minified, 'w') as m:

print("Minification complete. See {}".format(m.name))


Many people have sent language examples over the years, but we want more! We'd love to add more examples in your favourite programming language, so please send them our way. Email andychilton at that gmail place in the sky, tweet me @andychilton, or open an issue or PR on webdev.sh/html-minifier.com.

Click on the language of your choice to see an example: