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.

PHP

<?php
    // setup the URL, the CSS and the form data
    $url = 'https://html-minifier.com/raw';
    $html = file_get_contents('./index.html');
    $data = array(
        'input' => $html,
    );

    // init the request, set some info, send it and finally close it
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $minified = curl_exec($ch);

    curl_close($ch);

    // output the $minified
    echo $minified;
?>

Languages

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: