HTML Tidy — A built-in HTML beautifier/HTML Formatter Nobody knows about.

Steven Rescigno
2 min readFeb 9, 2021

You may already have Tidy on your computer! Many operating systems ship with the tidy command pre-installed.

Chances are good, though, that what you have is so outdated that it doesn’t even recognize HTML5. Install the latest using these commands.

How to install via macOS and Linux below.

Run the HomeBrew macOS command in the terminal.

brew install tidy-html5

Run the Linux command in the terminal.

sudo apt install tidy

If you do not want to see any errors that your HTML has, you can simply use --show-errors 0 to stop showing the errors within your HTML markup.

Here is an example of how errors show up by default.

line 11 column 45 - Warning: <input> element not empty or not closed
line 3 column 1 - Warning: <script> inserting "type" attribute
line 4 column 1 - Warning: <script> inserting "type" attribute
line 6 column 1 - Warning: <script> inserting "type" attribute

If you would like to hide the output of the HTML markup on the command you will need to use the command --quiet yes, by default, it will always output additional text into your markup directly in the terminal.

To learn more about HTML Tidy see http://tidy.sourceforge.net
Please send bug reports to html-tidy@w3.org
HTML and CSS specifications are available from http://www.w3.org/
Lobby your company to join W3C, see http://www.w3.org/Consortium

Here above is an example of the output by default you will see if you do not set --quiet to yes. This is seen within the terminal after your markup file has been formatted.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Without using --doctype omit in your command to tidy, you will also see a different HTML DocType than your original file passed directly.

Without using --tidy-mark no your command to tidy, you will see a different <meta> tag populate in your header. To remove, make sure to add no for the setting --tidy-mark.

Depending on your model device. Here is an example below.

<meta name="generator" content="HTML Tidy for Mac OS X (vers 11 October 2008 

--

--