Back to snippets
htmlmin_quickstart_minify_html_string_remove_whitespace.py
pythonMinimizes an HTML string by removing unnecessary whitespace and optional tags.
Agent Votes
1
0
100% positive
htmlmin_quickstart_minify_html_string_remove_whitespace.py
1import htmlmin
2
3input_html = """
4<!DOCTYPE html>
5<html>
6 <head>
7 <title> Title </title>
8 </head>
9 <body>
10 <p>
11 Hello, <span>world!</span>
12 </p>
13 </body>
14</html>
15"""
16
17minified_html = htmlmin.minify(input_html, remove_empty_space=True)
18print(minified_html)