TIDY(1)
๐ TIDY(1) ๐ โ the manual, but make it bestie ๐
Version 5.8.0, manual section 1. Okay so, this is the whole vibe of tidy, and honestly? She ate. Let's go โจ
๐ NAME ๐
tidy โ check, correct, and pretty-print HTML(5) files. That's the whole job. Iconic, lowkey.
๐ฆ SYNOPSIS ๐ฆ
tidy [options] [file ...] [options] [file ...] ...
๐ธ DESCRIPTION ๐ธ
Bestie. Tidy reads HTML, XHTML, and XML files and writes out cleaned-up markup. For the HTML variants, she detects, reports, and corrects sooo many common coding errors, and she strives to produce visually equivalent markup that's both conformant to the HTML specifications and that actually works in most browsers. Queen behavior, fr fr ๐
A super common use of Tidy is converting plain HTML to XHTML. For generic XML files though, Tidy is limited โ she's just correcting basic well-formedness errors and pretty printing. That's it. No notes.
If you don't specify an input file, Tidy reads the standard input. If you don't specify an output file, Tidy writes the tidied markup to the standard output. And if you don't specify an error file, Tidy writes messages to the standard error. Simple as ๐
โจ OPTIONS โจ
Tidy supports two different kinds of options, and you need to know which is which:
- Purely command-line options start with a single dash
-. These can only be used on the command-line, NOT in configuration files. They're listed in the first part of this section. - Configuration options can either be passed on the command line starting with two dashes
--, OR specified in a configuration file using the option name, followed by a colon:, plus the value, without the starting dashes. They're listed in the second part of this section, with a sample config file.
For command-line options that expect a numerical argument, a default is assumed if no meaningful value can be found. On the other hand, configuration options cannot be used without a value โ a configuration option without a value is simply discarded and reported as an error. Bye ๐
Using a command-line option is sometimes equivalent to setting the value of a configuration option. The equivalent option and value are shown in parentheses in the list below, as they would appear in a configuration file. For example, -quiet, -q (quiet: yes) means that using the command-line option -quiet or -q is equivalent to setting the configuration option quiet to yes. Slay, consistent โจ
Single-letter command-line options without an associated value can be combined โ for example '-i', '-m' and '-u' may be combined as '-imu'. Efficiency ๐
๐ File manipulation ๐
-output <file>,-o <file>(output-file: <file>) โ write output to the specified<file>๐-config <file>โ set configuration options from the specified<file>โ๏ธ-file <file>,-f <file>(error-file: <file>) โ write errors and warnings to the specified<file>๐จ-modify,-m(write-back: yes) โ modify the original input files ๐ณ (yes, she edits in place, be brave)
๐ซ Processing directives ๐ซ
-indent,-i(indent: auto) โ indent element content ๐ธ-wrap <column>,-w <column>(wrap: <column>) โ wrap text at the specified<column>.0is assumed if<column>is missing. When this option is omitted, the default of the configuration option'wrap'applies.-upper,-u(uppercase-tags: yes) โ force tags to upper case ๐-clean,-c(clean: yes) โ replaceFONT,NOBRandCENTERtags with CSS โจ-bare,-b(bare: yes) โ strip out smart quotes and em dashes, etc. ๐งผ-gdoc,-g(gdoc: yes) โ produce clean version of html exported by Google Docs ๐-numeric,-n(numeric-entities: yes) โ output numeric rather than named entities ๐ข-errors,-e(markup: no) โ show only errors and warnings โ ๏ธ-quiet,-q(quiet: yes) โ suppress nonessential output ๐คซ-omit(omit-optional-tags: yes) โ omit optional start tags and end tags โ๏ธ-xml(input-xml: yes) โ specify the input is well formed XML ๐ง-asxml,-asxhtml(output-xhtml: yes) โ convert HTML to well formed XHTML ๐-ashtml(output-html: yes) โ force XHTML to well formed HTML ๐-access <level>(accessibility-check: <level>) โ do additional accessibility checks (<level>=0,1,2,3).0is assumed if<level>is missing. โฟ
๐ค Character encodings ๐ค
-rawโ output values above 127 without conversion to entities ๐ถ๏ธ-asciiโ use ISO-8859-1 for input, US-ASCII for output-latin0โ use ISO-8859-15 for input, US-ASCII for output-latin1โ use ISO-8859-1 for both input and output-iso2022โ use ISO-2022 for both input and output-utf8โ use UTF-8 for both input and output ๐-macโ use MacRoman for input, US-ASCII for output ๐-win1252โ use Windows-1252 for input, US-ASCII for output ๐ช-ibm858โ use IBM-858 (CP850+Euro) for input, US-ASCII for output-utf16leโ use UTF-16LE for both input and output-utf16beโ use UTF-16BE for both input and output-utf16โ use UTF-16 for both input and output-big5โ use Big5 for both input and output-shiftjisโ use Shift_JIS for both input and output ๐ฏ๐ต
๐ Miscellaneous ๐
-version,-vโ show the version of Tidy ๐ท๏ธ-help,-h,-?โ list the command line options โ-help-configโ list all configuration options โ๏ธ-help-envโ show information about the environment and runtime configuration ๐ฑ-show-configโ list the current configuration settings ๐-export-configโ list the current configuration settings, suitable for a config file ๐ค-export-default-configโ list the default configuration settings, suitable for a config file ๐ฆ-help-option <option>โ show a description of the<option>๐-language <lang>(language: <lang>) โ set Tidy's output language to<lang>. Specify'-language help'for more help. Use before output-causing arguments to ensure the language takes effect, e.g.,tidy -lang es -lang help. ๐ฃ๏ธ
๐ง XML ๐ง
-xml-helpโ list the command line options in XML format ๐-xml-configโ list all configuration options in XML format ๐-xml-stringsโ output all of Tidy's strings in XML format ๐-xml-error-stringsโ output error constants and strings in XML format ๐-xml-options-stringsโ output option descriptions in XML format ๐
๐ Configuration Options General ๐
Configuration options can be specified by preceding each option with -- at the command line, followed by its desired value, OR by placing the options and values in a configuration file, and telling tidy to read that file with the -config option:
tidy --option1 value1 --option2 value2 ...
tidy -config config-file ...
Configuration options can be conveniently grouped in a single config file. A Tidy configuration file is simply a text file, where each option is listed on a separate line in the form
option1: value1
option2: value2
etc.
The permissible values for a given option depend on the option's Type. There are five Types: Boolean, AutoBool, DocType, Enum, and String. Boolean Types allow any of yes/no, y/n, true/false, t/f, 1/0. AutoBools allow auto in addition to the values allowed by Booleans. Integer Types take non-negative integers. String Types generally have no defaults, and you should provide them in non-quoted form (unless you wish the output to contain the literal quotes). Careful with those quotes bestie ๐ญ
Enum, Encoding, and DocType Types have a fixed repertoire of items, which are listed in the Supported values sections below.
You only need to provide options and values for those whose defaults you wish to override, although you may wish to include some already-defaulted options and values for the sake of documentation and explicitness. Do it for the lore ๐
Here is a sample config file, with at least one example of each of the five Types:
// sample Tidy configuration options
output-xhtml: yes
add-xml-decl: no
doctype: strict
char-encoding: ascii
indent: auto
wrap: 76
repeated-attributes: keep-last
error-file: errs.txt
Below is a summary and brief description of each of the options. They are listed alphabetically within each category.
๐ซถ Document Display options ๐ซถ
--gnu-emacsBoolean (no if unset) โ This option specifies that Tidy should change the format for reporting errors and warnings to a format that is more easily parsed by GNU Emacs or some other program. It changes them from the default
line <line number> column <column number> - (Error|Warning): <message>
to a form which includes the input filename:
<filename>:<line number>:<column number>: (Error|Warning): <message>
See also: --show-filename
--markupBoolean (yes if unset) โ This option specifies if Tidy should generate a pretty printed version of the markup. Note that Tidy won't generate a pretty printed version if it finds significant errors (seeforce-output). โ ๏ธ--muteString โ Use this option to prevent Tidy from displaying certain types of report output, for example, for conditions that you wish to ignore. ๐ค
This option takes a list of one or more keys indicating the message type to mute. You can discover these message keys by using the mute-id configuration option and examining Tidy's output.
See also: --mute-id
--mute-idBoolean (no if unset) โ This option indicates whether or not Tidy should display message ID's with each of its error reports. This could be useful if you wanted to use themuteconfiguration option in order to filter out certain report messages. ๐
See also: --mute
--quietBoolean (no if unset) โ When enabled, this option limits Tidy's non-document output to report only document warnings and errors. ๐คซ--show-body-onlyEnum (no if unset) โ Supported values:no,yes,auto๐ฉป
This option specifies if Tidy should print only the contents of the body tag as an HTML fragment.
If set to auto, this is performed only if the body tag has been inferred.
Useful for incorporating existing whole pages as a portion of another page.
This option has no effect if XML output is requested. ๐ซ
--show-errorsInteger (6 if unset) โ This option specifies the number Tidy uses to determine if further errors should be shown. If set to0, then no errors are shown. 0๏ธโฃ--show-filenameBoolean (no if unset) โ This option specifies if Tidy should show the filename in messages. eg:
tidy -q -e --show-filename yes index.html
index.html: line 43 column 3 - Warning: replacing invalid UTF-8 bytes (char. code U+00A9)
See also: --gnu-emacs
--show-infoBoolean (yes if unset) โ This option specifies if Tidy should display info-level messages. โน๏ธ--show-warningsBoolean (yes if unset) โ bestie, this one's the mute button ๐ it controls whether Tidy is allowed to yell warnings at you. Handy when like, three real errors are drowning in a whole flurry of warnings and you just want the drama to stop.
๐ Document In and Out options ๐
--add-meta-charsetBoolean (no if unset) โ turn this on and Tidy drops a<meta>element into the doc and sets thecharsetattribute to whatever encoding the document is using. Set it toyesto make it happen. periodt.--add-xml-declBoolean (no if unset) โ says whether Tidy should add the XML declaration when it's outputting XML or XHTML.
heads up: if your input already has an <?xml ... ?> declaration, this option just gets ignored. no cap.
Also, if the output encoding is something other than ascii, one of the utf* encodings, or raw, then the declaration is always added, because the XML standard literally requires it. not negotiable, the standard said so ๐
See also: --char-encoding, --output-encoding
--add-xml-spaceBoolean (no if unset) โ when generating XML, this makes Tidy addxml:space="preserve"to elements like<pre>,<style>and<script>. You need this if you want the whitespace in those elements to be parsed correctly without having access to the DTD. iconic behavior tbh.--doctypeString (auto if unset) โ this is the one that decides which DOCTYPE declaration Tidy generates. so many moods, let's go:- set it to
omitand your output won't contain a DOCTYPE declaration at all. btw this also impliesnumeric-entitiesgets set toyes. sneaky. - set it to
html5and the DOCTYPE becomes<!DOCTYPE html>. - set it to
auto(the default) and Tidy makes an educated guess based on the contents of the document. note that picking this option will not change the current document's DOCTYPE on output. - set it to
strictand Tidy sets the DOCTYPE to the HTML4 or XHTML1 strict DTD. - set it to
looseand the DOCTYPE becomes the HTML4 or XHTML1 loose (transitional) DTD. - or you can hand it a string for the formal public identifier (FPI) ๐
- set it to
For example:
doctype: "-//ACME//DTD HTML 3.14159//EN"
If you specify the FPI for an XHTML document, Tidy sets the system identifier to an empty string. For an HTML document, Tidy only adds a system identifier if one was already there, so it can preserve the processing mode of some browsers. And for generic XML documents? Tidy leaves the DOCTYPE unchanged. respecting boundaries, we love to see it ๐ซถ
also lowkey important: this option does not offer validation of document conformance. it's not doing that job, bestie.
--input-xmlBoolean (no if unset) โ do you want Tidy to use the XML parser instead of the error-correcting HTML parser? that's the whole option. yes = XML parser, no = the chill HTML one that fixes ur mistakes.--output-htmlBoolean (no if unset) โ says whether Tidy should generate pretty printed output and write it as HTML. simple, clean, elegant ๐--output-xhtmlBoolean (no if unset) โ same deal but the pretty printed output gets written as extensible HTML. This option makes Tidy set the DOCTYPE and default namespace as appropriate to XHTML, and it uses the corrected value in the output no matter what other sources say. she's stubborn and she's right.
For XHTML, entities can be written as named or numeric entities depending on how numeric-entities is set.
And the original case of tags and attributes will be preserved, regardless of other options. the case stays. we don't touch the case. ๐
--output-xmlBoolean (no if unset) โ pretty prints the output and writes it as well-formed XML โจ Any entities that aren't defined in XML 1.0 get written as numeric entities so an XML parser can actually parse them.
Same as above: the original case of tags and attributes will be preserved, regardless of other options.
๐ธ File Input-Output options ๐ธ
--error-fileString โ tells Tidy which error file to use for errors and warnings. Normally errors and warnings go tostderr. now you can redirect the yelling.
See also: --output-file
--keep-timeBoolean (no if unset) โ set this and Tidy keeps the original modification time of files it modifies in place. Setting it toyesmeans you can tidy files without changing the file modification date, which is genuinely useful with certain tools that use the modification date for stuff like automatic server deployment. chef's kiss.
ngl, this feature is not supported on some platforms. so vibe check ur OS first.
--output-fileString โ picks the output file Tidy uses for markup. Normally markup is written tostdout.
See also: --error-file
--write-backBoolean (no if unset) โ this one makes Tidy write the tidied markup back into the same file it read from. in-place glow-up.
๐จ bestie PLEASE keep copies of important files before tidying them. on rare occasions the result may not be what you expect, and there's no undo button on that.
๐ฅ Diagnostics options ๐ฅ
--accessibility-checkEnum (0 (Tidy Classic)if unset) โ Supported values:0 (Tidy Classic),1 (Priority 1 Checks),2 (Priority 2 Checks),3 (Priority 3 Checks)
This specifies what level of accessibility checking, if any, Tidy should perform. let's break down the levels:
- Level
0(Tidy Classic) performs no additional accessibility checking. just vibes. - Level
1(Priority 1 Checks) performs the Priority Level 1 checks. - Level
2(Priority 2 Checks) performs the Priority Level 1 and 2 checks. - Level
3(Priority 3 Checks) performs the Priority Level 1, 2, and 3 checks.
For more info on Tidy's accessibility checking, including the specific checks made for each Priority Level, go visit Tidy's Accessibility Page at http://www.html-tidy.org/accessibility/. ๐ซถ
--force-outputBoolean (no if unset) โ makes Tidy produce output even if errors are encountered. sounds fun, is not always fun.
use this option with care!! if Tidy reports an error, that means Tidy was not able to fix it (or isn't sure how), so the resulting output may not reflect your intention at all. ๐ญ
--show-meta-changeBoolean (no if unset) โ enables a message whenever Tidy changes thecontentattribute of a meta charset declaration to match the encoding of the document. Set it toyesto switch it on. keeping receipts ๐--warn-proprietary-attributesBoolean (yes if unset) โ says whether Tidy should warn on proprietary attributes. on by default, she's watching ๐
๐ Encoding options ๐
--char-encodingEncoding (utf8if unset) โ Supported values:raw,ascii,latin0,latin1,utf8,iso2022,mac,win1252,ibm858,utf16le,utf16be,utf16,big5,shiftjis
This is the character encoding Tidy uses for input โ and when you set it, Tidy automatically picks an appropriate character encoding to use for output too. note that the output encoding it chooses may be different from the input encoding. she's making decisions.
- For
ascii,latin0,ibm858,mac, andwin1252input encodings, theoutput-encodingoption automatically gets set toascii. You can setoutput-encodingmanually to override that. - For other input encodings,
output-encodingautomatically gets set to the same value. - Regardless of the preset value, you can set
output-encodingmanually to override this.
Tidy is not an encoding converter. Although the Latin and UTF encodings can be mixed freely, it is not possible to convert Asian encodings to Latin encodings with Tidy. just so we're clear ๐
See also: --input-encoding, --output-encoding
--input-encodingEncoding (utf8if unset) โ Supported values:raw,ascii,latin0,latin1,utf8,iso2022,mac,win1252,ibm858,utf16le,utf16be,utf16,big5,shiftjis
The character encoding Tidy uses for input. Tidy makes certain assumptions about some of the input encodings, so here's the tea:
- For
ascii, Tidy will accept Latin-1 (ISO-8859-1) character values and convert them to entities as necessary. - For
raw, Tidy makes no assumptions about the character values and passes them unchanged to output. - For
macandwin1252, vendor specific character values will be accepted and converted to entities as necessary. - Asian encodings such as
iso2022will be handled appropriately, assuming the correspondingoutput-encodingis also specified.
same warning as above: Tidy is not an encoding converter. Latin and UTF can mix freely, but Asian encodings cannot be converted to Latin encodings with Tidy.
See also: --char-encoding
--newlineEnum (LFif unset) โ Supported values:LF,CRLF,CR
The default is appropriate to the current platform. Genrally that's CRLF on PC-DOS, Windows and OS/2; CR on Classic Mac OS; and LF everywhere else (Linux, macOS, and Unix). she adapts to her environment, main character energy ๐
--output-bomEnum (autoif unset) โ Supported values:no,yes,auto
Says whether Tidy should write a Unicode Byte Order Mark character (BOM; also known as Zero Width No-Break Space; has value of U+FEFF) to the beginning of the output. Only applies to UTF-8 and UTF-16 output encodings, btw.
- If set to
auto, Tidy only writes a BOM to the output if a BOM was present at the beginning of the input. matching energy โจ - A BOM is always written for XML/XHTML output using UTF-16 output encodings. no discussion.
--output-encodingEncoding (utf8if unset) โ Supported values:raw,ascii,latin0,latin1,utf8,iso2022,mac,win1252,ibm858,utf16le,utf16be,utf16,big5,shiftjis
The character encoding Tidy uses for output. Some of the output encodings affect whether or not certain characters get translated to entities, although in all cases some entities will be written according to other Tidy configuration options.
- For
ascii,mac, andwin1252output encodings, entities will be used for all characters with values over 127. - For
rawoutput, Tidy writes values above 127 without translating them to entities. - Output using
latin1causes Tidy to write character values higher than 255 as entities. - The UTF family such as
utf8writes output in the respective UTF encoding. - Asian output encodings such as
iso2022write output in the specified encoding, assuming a correspondinginput-encodingwas specified.
slay, that's the whole encoding buffet ๐
Tidy is not an encoding converter, bestie. Latin and UTF encodings can be mixed freely, sure, but it is not possible to convert Asian encodings to Latin encodings with Tidy. ๐
See also: --char-encoding
๐งผโจ Cleanup options โจ๐งผ
--bareBoolean (no if unset) โ this one says whether Tidy should swap smart quotes and em dashes for plain ASCII, and spit out spaces instead of non-breaking spaces, wherever those lil guys show up in the input.--cleanBoolean (no if unset) โ tells Tidy to clean up some legacy presentational tags (right now that's<i>,<b>,<center>when they're wrapped inside appropriate inline tags, plus<font>). Set it to yes and those legacy tags get replaced with CSS<style>tags and structural markup where that makes sense. ๐--drop-empty-elementsBoolean (yes if unset) โ should Tidy just yeet empty elements? That's the question this answers.--drop-empty-parasBoolean (yes if unset) โ same energy, but for empty paragraphs specifically.--drop-proprietary-attributesBoolean (no if unset) โ should Tidy strip out proprietary attributes, like those Microsoft data binding ones? Also: attributes that aren't allowed in the output version of HTML get dropped when this is used together withstrict-tags-attributes.--gdocBoolean (no if unset) โ turns on special behavior for cleaning up HTML that got exported from Google Docs. ๐ซถ--logical-emphasisBoolean (no if unset) โ Tidy replaces every<i>with<em>and every<b>with<strong>. Any attributes? Preserved unchanged, no cap. This one can be set independently of thecleanoption.--merge-divsEnum (auto if unset) โ Supported values:no,yes,auto. This one tweaks howcleanbehaves whencleanis set to yes. It says whether Tidy should merge nested<div>like<div><div>...</div></div>. If it'sauto, the attributes of the inner<div>get moved to the outer one, and nested<div>withidattributes are not merged. If it'syes, the inner<div>'s attributes get discarded โ except forclassandstyle. See also:--clean,--merge-spans--merge-spansEnum (auto if unset) โ Supported values:no,yes,auto. Also tweaksclean's behavior whencleanis yes. This one says whether Tidy should merge nested<span>like<span><span>...</span></span>. The algorithm is identical to the onemerge-divsuses. See also:--clean,--merge-divs--word-2000Boolean (no if unset) โ Tidy will go to great pains to strip out all the surplus junk Microsoft Word 2000 inserts when you save Word docs as "Web pages". It does not handle embedded images or VML. Honestly? Consider saving with Word'sSave As...and pickingWeb Page, Filteredinstead. ๐
๐ธ Entities options ๐ธ
--ascii-charsBoolean (no if unset) โ can modify how thecleanoption behaves whencleanis yes. When this is yes and you're usingclean, then&emdash;,”, and other named character entities get downgraded to their closest ASCII equivalents. See also:--clean--ncrBoolean (yes if unset) โ should Tidy allow numeric character references? Yes? No? This is the switch.--numeric-entitiesBoolean (no if unset) โ Tidy outputs entities other than the built-in HTML entities (&,<,>, and") in numeric form instead of named form. Only entities compatible with the generatedDOCTYPEdeclaration get used, and entities that can be represented in the output encoding get translated correspondingly. See also:--doctype,--preserve-entities--preserve-entitiesBoolean (no if unset) โ should Tidy preserve well-formed entities exactly as found in the input? That's the vibe. โจ--quote-ampersandBoolean (yes if unset) โ should Tidy output unadorned&characters as&? Note: in legacy doctypes only.--quote-marksBoolean (no if unset) โ Tidy outputs"characters as", which some editing environments prefer. And the apostrophe character'gets written out as', because lots of web browsers don't support'yet. ๐ญ--quote-nbspBoolean (yes if unset) โ should Tidy output non-breaking space characters as entities, rather than as the Unicode character value 160 (decimal)? ๐
๐ง๐ Repair options ๐๐ง
--alt-textString โ sets the defaultalt=text Tidy uses for<img>attributes when thealt=attribute is missing. โ ๏ธ Use with care, bestie โ it is your responsibility to make your documents accessible to people who cannot see the images.--anchor-as-nameBoolean (yes if unset) โ controls the deletion or addition of thenameattribute in elements where it can serve as an anchor. If yes: anameattribute, if one doesn't already exist, is added alongside an existingidattribute if the DTD allows it. If no: any existingnameattribute gets removed if anidattribute exists or has been added.--assume-xml-procinsBoolean (no if unset) โ changes how processing instructions get parsed, requiring?>as the terminator rather than>. This option is automatically set if the input is in XML.--coerce-endtagsBoolean (yes if unset) โ should Tidy coerce a start tag into an end tag when it looks like an end tag was probably intended? Like, given:
<span>foo <b>bar<b> baz</span>
Tidy will output:
<span>foo <b>bar</b> baz</span>
--css-prefixString (cif unset) โ the prefix Tidy uses for styles rules. By default,cis used. ๐--custom-tagsEnum (no if unset) โ Supported values:no,blocklevel,empty,inline,pre. This enables the use of tags for autonomous custom elements, e.g.<flag-icon>, with Tidy. Custom tags are disabled if this value isno. The other settings โblocklevel,empty,inline, andpreโ treat all detected custom tags accordingly. Heads up: usingnew-blocklevel-tags,new-empty-tags,new-inline-tags, ornew-pre-tagswill override the treatment of custom tags by this configuration option โ handy if you've got different types of custom tags. When enabled, these tags are determined during the processing of your document using opening tags; matching closing tags get recognized accordingly, and unknown closing tags get discarded. See also:--new-blocklevel-tags,--new-empty-tags,--new-inline-tags,--new-pre-tags--enclose-block-textBoolean (no if unset) โ should Tidy insert a<p>element to enclose any text it finds in any element that allows mixed content for HTML transitional but not HTML strict? ๐--enclose-textBoolean (no if unset) โ Tidy encloses any text it finds in thebodyelement within a<p>element. Super useful when you want to take existing HTML and use it with a style sheet. โจ--escape-scriptsBoolean (yes if unset) โ causes items that look like closing tags, like</g, to be escaped to<\/g. Set this option to no if you do not want that.--fix-backslashBoolean (yes if unset) โ should Tidy replace backslash characters\in URLs with forward slashes/? Fix it, bestie. ๐ฉน--fix-bad-commentsEnum (auto if unset) โ Supported values:no,yes,auto. This one says whether Tidy should replace unexpected hyphens with=characters when it comes across adjacent hyphens. The default,auto, will act asnofor HTML5 document types, andyesfor all other document types. Here's the lore: HTML has abandoned SGML comment syntax, and allows adjacent hyphens for all versions of HTML โ although XML and XHTML do not. If you plan to support older browsers that require SGML comment syntax, then consider setting this value toyes.--fix-style-tagsBoolean (yes if unset) โ should Tidy move all style tags to the head of the document? Yes. ๐--fix-uriBoolean (yes if unset) โ Tidy checks attribute values that carry URIs for illegal characters, and if any are found, escapes them as HTML4 recommends.--literal-attributesBoolean (no if unset) โ controls how Tidy deals with whitespace characters inside attribute values. If the value isno, Tidy normalizes attribute values by replacing any newline or tab with a single space, and then further by replacing any contiguous whitespace with a single space. To force Tidy to preserve the original, literal values of all attributes and ensure that whitespace within attribute values passes through unchanged, set this option toyes.--lower-literalsBoolean (yes if unset) โ should Tidy convert the value of an attribute that takes a list of predefined values to lower case? This is required for XHTML documents. periodt.--repeated-attributesEnum (keep-lastif unset) โ Supported values:keep-first,keep-last. Says whether Tidy should keep the first or the last attribute if an attribute is repeated โ like when something's got twoalignattributes. See also:--join-classes,--join-styles--skip-nestedBoolean (yes if unset) โ says Tidy should skip nested tags when parsing script and style data.--strict-tags-attributesBoolean (no if unset) โ ensures that tags and attributes are applicable for the version of HTML that Tidy outputs. When set toyesand the output document type is a strict doctype, then Tidy will report errors. If the output document type is a loose or transitional doctype, then Tidy will report warnings. ๐จ
Also โ and this is the fun part โ if drop-proprietary-attributes is switched on, then the attributes that don't apply to the element get dropped too ๐
. And when it's set to no, none of these checks are performed at all. Like, zero. Not one.
--uppercase-attributesโ Enum (noif unset). Supported values:no,yes,preserve. This one decides whether Tidy writes attribute names in ALL CAPS. Set it tonoand attribute names get written in lower case. Sayyesand they come out in upper case, andpreservecan be used to leave attribute names untouched, exactly as they were. BUT โ when you're using XML input, the original case is always preserved, no matter what you pick. ๐ฆ--uppercase-tagsโ Boolean (noif unset). Should Tidy output tag names in upper case? Default isno, which gets you lower case tag names โ except for XML input, where the original case is preserved. ๐
๐ฆ Transformation options ๐ฆ
--decorate-inferred-ulโ Boolean (noif unset). This one says whether Tidy should decorate inferred<ul>elements with some CSS markup, so they don't get indented to the right. Slay. โจ--escape-cdataโ Boolean (noif unset). Should Tidy convert<![CDATA[]]>sections into normal text? That's the whole vibe here.--hide-commentsโ Boolean (noif unset). Should Tidy not print out comments. Yes, the option name says hide and the description says not print, it's giving double negative, we move. ๐--join-classesโ Boolean (noif unset). If Tidy spots multiple class assignments on one element, should it combine those class names to generate a single, new class name? That's it, that's the option.--join-stylesโ Boolean (yesif unset โ yes bestie, this one's on by default). If Tidy detects multiple style values on an element, should it combine styles to generate a single, new style? ๐--merge-emphasisโ Boolean (yesif unset). Should Tidy merge nested<b>and<i>elements? For example, for the case<b class="rtop-2">foo <b class="r2-2">bar</b> baz</b>,Tidy will output<b class="rtop-2">foo bar baz</b>. Nested bold said goodbye, iconic behaviour, no cap. ๐ฅ--replace-colorโ Boolean (noif unset). Should Tidy replace numeric values in color attributes with HTML/XHTML color names where those names are defined? Like, replace#ffffffwithwhite. Little glow-up for your hex codes. ๐
๐ Teaching Tidy options ๐
Yes, this section is literally called "Teaching Tidy" and I'm obsessed. You're about to teach Tidy about tags it's never met before. ๐ง
--new-blocklevel-tagsโ Tag Names. Supported values:tagX,tagY, ... This option specifies new block-level tags, and it takes a space or comma separated list of tag names. Unless you declare new tags, Tidy will refuse to generate a tidied file if the input includes previously unknown tags โ like, it will simply not do it, bestie. Also note you can't change the content model for elements such as<table>,<ul>,<ol>and<dl>. This option is ignored in XML mode. See also:--new-empty-tags,--new-inline-tags,--new-pre-tags,--custom-tags.--new-empty-tagsโ Tag Names. Supported values:tagX,tagY, ... This option specifies new empty inline tags, and it takes a space or comma separated list of tag names. Same rule as above: unless you declare new tags, Tidy will refuse to generate a tidied file if the input includes previously unknown tags. And remember to also declare empty tags as either inline or blocklevel โ don't leave them hanging. This option is ignored in XML mode. See also:--new-blocklevel-tags,--new-inline-tags,--new-pre-tags,--custom-tags.--new-inline-tagsโ Tag Names. Supported values:tagX,tagY, ... This option specifies new non-empty inline tags, and it takes a space or comma separated list of tag names. And yep, unless you declare new tags, Tidy will refuse to generate a tidied file if the input includes previously unknown tags. This option is ignored in XML mode. See also:--new-blocklevel-tags,--new-empty-tags,--new-pre-tags,--custom-tags.--new-pre-tagsโ Tag Names. Supported values:tagX,tagY, ... This option specifies new tags that are to be processed in exactly the same way as HTML's<pre>element, and it takes a space or comma separated list of tag names. Same energy as the others: unless you declare new tags, Tidy will refuse to generate a tidied file if the input includes previously unknown tags. Note you cannot as yet add new CDATA elements. This option is ignored in XML mode. See also:--new-blocklevel-tags,--new-empty-tags,--new-inline-tags,--custom-tags.
โจ Pretty Print options โจ
--break-before-brโ Boolean (noif unset). Should Tidy output a line break before each<br>element? Simple as that.--indentโ Enum (noif unset). Supported values:no,yes,auto. Should Tidy indent block-level tags? If you set it toauto, Tidy will decide whether or not to indent the content of tags such as<title>,<h1>-<h6>,<li>,<td>, or<p>based on whether that content includes a block-level element. Settingindenttoyescan expose layout bugs in some browsers โ so, heads up. Use the optionindent-spacesto control the number of spaces or tabs output per level of indent, andindent-with-tabsto specify whether spaces or tabs are used. See also:--indent-spaces.--indent-attributesโ Boolean (noif unset). Should Tidy begin each attribute on a new line? One attribute per line, very demure, very mindful. ๐--indent-cdataโ Boolean (noif unset). Should Tidy indent<![CDATA[]]>sections? Yep, that's the whole thing.--indent-spacesโ Integer (2if unset). The number of spaces or tabs that Tidy uses to indent content whenindentis enabled. Note that the default value for this option is dependent upon the value ofindent-with-tabs(see also). See also:--indent.--indent-with-tabsโ Boolean (noif unset). Should Tidy indent with tabs instead of spaces, assumingindentisyes? Set it toyesto indent using tabs instead of the default spaces. Use the optionindent-spacesto control the number of tabs output per level of indent โ and note that whenindent-with-tabsis enabled, the default value ofindent-spacesis reset to1. Also notetab-sizecontrols converting input tabs to spaces; set it to zero to retain input tabs. ๐--keep-tabsโ Boolean (noif unset). With the defaultno, Tidy will replace all source tabs with spaces, controlled by the optiontab-size, and the current line offset. Of course, except in the special blocks/elements enumerated below, this will later be reduced to just one space. If you set it toyes, this option specifies that Tidy should keep certain tabs found in the source โ but only in preformatted blocks like<pre>, and other CDATA elements like<script>,<style>, and other pseudo elements like<?php ... ?>. As always, all other tabs, or sequences of tabs, in the source will continue to be replaced with a space.--omit-optional-tagsโ Boolean (noif unset). Should Tidy omit optional start tags and end tags when generating output? Setting this option causes all tags for the<html>,<head>, and<body>elements to be omitted from output, as well as such end tags as</p>,</li>,</dt>,</dd>,</option>,</tr>,</td>, and</th>. This option is ignored for XML output.--priority-attributesโ Attributes Names. Supported values:attributeX,attributeY, ... This option lets you prioritize the writing of attributes in tidied documents, so they get written before the other attributes of an element. For example, you might specify thatidandnameare written before every other attribute. It takes a space or comma separated list of attribute names. ๐--punctuation-wrapโ Boolean (noif unset). Should Tidy line wrap after some Unicode or Chinese punctuation characters? That's the vibe.--sort-attributesโ Enum (noneif unset). Supported values:none,alpha. This specifies that Tidy should sort attributes within an element using the specified sort algorithm. If set toalpha, the algorithm is an ascending alphabetic sort. When used while sorting withpriority-attributes, any attribute sorting will take place after the priority attributes have been output. See also:--priority-attributes.--tab-sizeโ Integer (8if unset). The number of columns that Tidy uses between successive tab stops. It's used to map tabs to spaces when reading the input.--tidy-markโ Boolean (yesif unset). Should Tidy add a meta element to the document head to indicate that the document has been tidied? And nope, Tidy won't add a meta element if one is already present โ it's not about to double up. โจ--vertical-spaceโ Enum (noif unset). Supported values:no,yes,auto. Should Tidy add some extra empty lines for readability? The default isno. If set toauto, Tidy will eliminate nearly all newline characters. ๐--wrapโ Integer (68if unset). The right margin Tidy uses for line wrapping. Tidy tries to wrap lines so that they do not exceed this length. Setwrapto0(zero) if you want to disable line wrapping entirely. Periodt.--wrap-aspโ Boolean (yesif unset). Should Tidy line wrap text contained within ASP pseudo elements, which look like:<% ... %>. Yes bestie, it's on by default.--wrap-attributesโ Boolean (noif unset). Should Tidy line-wrap attribute values? Meaning: if the value of an attribute causes a line to exceed the width specified bywrap, Tidy will add one or more line breaks to the value, causing it to be wrapped into multiple lines. Note that this option can be set independently ofwrap-script-literals. By default Tidy replaces any newline or tab with a single space and replaces any sequences of whitespace with a single space. To force Tidy to preserve the original, literal values of all attributes, and ensure that whitespace characters within attribute values are passed through unchanged, setliteral-attributestoyes. See also:--wrap-script-literals,--literal-attributes.
and bestie, the wrap girlies are literally not done yet ๐
--wrap-jsteโ Boolean, and it's yes if unset. This one decides whether Tidy line wraps the text sitting inside JSTE pseudo elements, which are the little guys that look like:<# ... #>.--wrap-phpโ Boolean, no if unset. Controls whether Tidy drops a new line after PHP pseudo elements, which look like:<?php ... ?>.--wrap-script-literalsโ Boolean, no if unset. Says whether Tidy should line wrap the string literals that get assigned to element event handler attributes, likeelement.onmouseover().
Also go look at: --wrap-attributes
--wrap-sectionsโ Boolean, yes if unset. Decides if Tidy line wraps the text hanging out inside<![ ... ]>section tags.
๐ธ ENVIRONMENT ๐ธ
HTML_TIDYโ the name of your default configuration file, bestie. ๐
Make it an absolute path, okay? Because fr fr you're probably gonna invoke tidy from a bunch of different directories and a relative path is gonna ghost you.
Timing matters here, so listen up: the value of HTML_TIDY gets parsed after the compiled-in default (the one defined with -DTIDY_CONFIG_FILE), but before any of the files you specify using -config. Order of operations, queen. ๐
๐ซถ RUNTIME CONFIGURATION FILES ๐ซถ
You can also point Tidy at runtime configuration files and it will try to load a configuration from them automatically. No cap.
- The system runtime configuration file,
/etc/tidy.conf, gets loaded and applied first โ but only if it exists. - Then comes the user runtime configuration file,
~/.tidyrc. - And if you use a specific option more than once? The later usage overrides any previous usage. Periodt.
Heads up ๐: if you use the HTML_TIDY environment variable, then the user runtime configuration file will not be used. And yes, that is a feature, not a bug. The manpage said it, not me.
โจ EXIT STATUS โจ
0โ all your input files were processed successfully. Slay. ๐1โ there were warnings. Not fatal, but the vibe check failed a little. ๐2โ there were errors. It's giving chaos. ๐ญ
๐ฅ SEE ALSO ๐ฅ
Want more info about HTML Tidy? Say less:
http://www.html-tidy.org/
Want more info on HTML itself? Here you go:
HTML: Edition for Web Authors (the latest HTML specification)
http://dev.w3.org/html5/spec-author-view
HTML: The Markup Language (an HTML language reference)
http://dev.w3.org/html5/markup/
Got bugs? Got thoughts? Got feelings?
https://github.com/htacg/tidy-html5/issues/
Or you can send questions and comments to public-htacg@w3.org. They're listening, bestie. ๐ซถ
And if you wanna validate your HTML documents, use the W3C Nu Markup Validator:
http://validator.w3.org/nu/
๐ AUTHOR ๐
Tidy was written by Dave Raggett <dsr@w3.org>, and then subsequently maintained by a team at http://tidy.sourceforge.net/, and now it's maintained by HTACG (http://www.htacg.org). A whole lineage. Iconic succession planning, honestly. ๐
The sources for HTML Tidy are available at https://github.com/htacg/tidy-html5/ under the MIT Licence. Go read them, go contribute, go be the main character.
And that's the whole page, babe. ๐ This was the HTML Tidy manual page, version 5.8.0, straight from the HTML Tidy source itself โ the date lives in that footer, and yes, this is the official TIDY(1) page you just read all the way through. Proud of you. Now go tidy some markup. โจ๐ฆ๐ธ
๐ฆ where this page comes from
- alpine 3.24: tidyhtml-doc 5.8.0-r5 ยท W3C
- arch rolling: tidy 5.8.0-4 ยท custom
- debian trixie: tidy 2:5.8.0-2 ยท tidy
- epel 10: tidy 5.8.0-9.el10_0 ยท W3C
- epel 9: tidy 5.8.0-2.el9 ยท W3C
- fedora 43: tidy 5.8.0-12.fc43 ยท W3C
- fedora 44: tidy 5.8.0-13.fc44 ยท W3C
- nixos 26.05: html-tidy 5.8.0
- nixpkgs unstable: html-tidy 5.8.0
- opensuse-leap 16.0: tidy 5.8.0-160000.2.2 ยท W3C
- opensuse-leap 16.0: tidy 5.8.0-160000.2.2 ยท W3C
- opensuse-leap 16.0: tidy 5.8.0-160000.2.2 ยท W3C
- opensuse-leap 16.0: tidy 5.8.0-160000.2.2 ยท W3C
- ubuntu questing: tidy 2:5.8.0-2
- ubuntu resolute: tidy 2:5.8.0-2.1 ยท tidy
- ubuntu stonking: tidy 2:5.8.0-2.1 ยท tidy
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms