Copyright © 1999 W3C, see tidy.c for copyright notice.
With many thanks to Hewlett Packard for financial support during the development of this software!
This version 15th April 1999
See the release notes for information on recent changes.
To get the latest version of Tidy please visit the original version of this page at: http://www.w3.org/People/Raggett/tidy. Courtesy of Netmind, you can register for email reminders when new versions of tidy become available.
How to use Tidy | Downloading Tidy |
Release Notes
Integration with other Software | Acknowledgements
When editing HTML it's easy to make mistakes. Wouldn't it be nice if there was a simple way to fix these mistakes automatically and tidy up sloppy editing into nicely layed out markup? Well now there is! Dave Raggett's HTML TIDY is a free utility for doing just that. It also works great on the atrociously hard to read markup generated by specialized HTML editors and conversion tools, and can help you identify where you need to pay further attention on making your pages more accessible to people with disabilities.
Tidy is able to fix up a wide range of problems and to bring to your attention things that you need to work on yourself. Each item found is listed with the line number and column so that you can see where the problem lies in your markup. Tidy won't generate a cleaned up version when there are problems that it can't be sure of how to handle. These are logged as "errors" rather than "warnings".
Tidy corrects the markup in a way that matches where possible the observed rendering in popular browsers from Netscape and Microsoft. Here are just a few examples of how TIDY perfects your HTML for you:
<h1>heading <h2>subheading</h3>
is mapped to
<h1>heading</h1> <h2>subheading</h2>
<p>here is a para <b>bold <i>bold italic</b> bold?</i> normal?
is mapped to
<p>here is a para <b>bold <i>bold italic</i> bold?</b> normal?
<h1><i>italic heading</h1> <p>new paragraph
In Netscape and Internet Explorer this causes everything following the heading to be in the heading font size, not the desired effect at all!
Tidy maps the example to
<h1><i>italic heading</i></h1> <p>new paragraph
<i><h1>heading</h1></i> <p>new paragraph <b>bold text <p>some more bold text
Tidy maps this to
<h1><i>heading</i></h1> <p>new paragraph <b>bold text</b> <p><b>some more bold text</b>
<h1><hr>heading</h1> <h2>sub<hr>heading</h2>
Tidy maps this to
<hr> <h1>heading</h1> <h2>sub</h2> <hr> <h2>heading</h2>
<a href="#refs">References<a>
Tidy maps this to
<a href="#refs">References</a>
<body> <li>1st list item <li>2nd list item
is mapped to
<body> <ul> <li>1st list item</li> <li>2nd list item</li> </ul>
Tidy inserts quote marks around all attribute values for you. It can also detect when you have forgotten the closing quote mark, although this is something you will have to fix yourself.
Tidy has a comprehensive knowledge of the attributes defined in the HTML 4.0 recommendation from W3C. This often allows you to spot where you have mistyped an attribute or value.
Tidy will even work out which version of HTML you are using and insert the appropriate DOCTYPE element, as per the W3C recommendations.
This is something you then have to fix yourself as Tidy is unsure of where the > should be inserted.
You can choose which style you want Tidy to use when it generates the cleaned up markup: for instance whether you like elements to indent their contents or not.
Tidy offers you a choice of character encodings: US ASCII, ISO Latin-1, UTF-8 and the ISO 2022 family of 7 bit encodings. The full set of HTML 4.0 entities are defined. Cleaned up output uses HTML entity names for characters when appropriate. Otherwise characters outside the normal range are output as numeric character entities.
Tidy offers advice on accessibility problems for people using non-graphical browsers. The most common thing you will see is the suggestion you add a summary attribute to table elements. The idea is to provide a summary of the table's role and structure suitable for use with aural browsers.
Many tools generate HTML with an excess of FONT, NOBR and CENTER tags. Tidy's -clean option will replace them by style properties and rules using CSS. This makes the markup easier to read and maintain as well as reducing the file size! Tidy is expected to get smarter at this in the future.
XML processors compliant with W3C's XML 1.0 recommendation are very picky about which files they will accept. Tidy can help you to fix errors that cause your XML files to be rejected. Tidy doesn't yet recognize all XML features though, e.g. it doesn't yet understand CDATA sections or DTD subsets.
The -slides option allows you to burst a single HTML file into a number of linked slides. Each H2 element in the input file is treated as delimiting the start of the next slide. The slides are named slide1.html, slide2.html, slide3.html etc. This is a relatively new feature and ideas are welcomed as to how to improve it. In particular, I plan to add support to the configuration file for setting the style sheet for slides and for customizing the slides via a template.
I would be interested in hearing from anyone who can offer help with using Javascript for adding dynamic effects to slides, for instance similar to those available in Microsoft PowerPoint.
<html> <head> </head> <body> <p> para which has enough text to cause a line break, and so test the wrapping mechanism for long lines. </p> <pre>This is <em>genuine preformatted</em> text </pre> <ul> <li> 1st list item </li> <li> 2nd list item </li> </ul> <!-- end comment --> </body> </html>
and this is the default style:
<html> <head> </head> <body> <p>para which has enough text to cause a line break, and so test the wrapping mechanism for long lines.</p> <pre>This is <em>genuine preformatted</em> text </pre> <ul> <li>1st list item </li> <li>2nd list item</li> </ul> <!-- end comment --> </body> </html>
tidy [[options] filename]*
HTML tidy is not (yet) a windows program. If you run tidy without any arguments, it will just sit there waiting to read markup on the stdin stream. Tidy's input and output default to stdin and stdout respectively. Errors are written to stderr but can be redirected to a file with the -f filename option.
I generally use the -m option to get tidy to update the original file, and if the file is particularly bad I also use the -f option to write the errors to a file to make it easier to review them. Tidy supports a small set of character encoding options. The default is ASCII, which makes it easy to edit markup in regular text editors.
For instance:
tidy -f errs.txt -m index.html
which runs tidy on the file "index.html" updating it in place and writing the error messages to the file "errs.txt". Its a good idea to save your work before tidying it, as with all complex software, tidy may have bugs. If you find any please let me know!
Users running in Microsoft Windows should be aware that Dos doesn't expand wild cards in filenames. This means that if you have several html files in the same directory and want to tidy all of them:
tidy *.html
won't work. You will see an error message: "can't open file *.html". Instead you need to run tidy separately on each one. I will look into a fix for this for a future release. A work around is to use the DOS for command, as in:
for %i in (*.html) do tidy %i
Note: in a batch file that needs to be %%i instead of %i
To get a list of available options use:
tidy -help
You should see something like this:
options for tidy vers: 14th April 1999 -config file read config file -indent or -i indent element content -omit or -o omit optional endtags -wrap 72 wrap text at column 72 (default is 68) -upper or -u force tags to upper case -clean or -c replace font, nobr & center tags by CSS -raw don't o/p entities for chars 128 to 255 -ascii use ASCII for output, Latin-1 for input -latin1 use Latin-1 for both input and output -utf8 use UTF-8 for both input and output -iso2022 use ISO2022 for both input and output -numeric or -n output numeric rather than named entities -modify or -m to modify original files -errors or -e show only error messages -f file write errors to file -xml use this when input is in XML -asxml to convert HTML to XML -slides to burst into slides on h2 elements -help list command line options
Input and Output default to stdin/stdout respectively. Single letter options apart from -f may be combined as in: tidy -f errs.txt -imu foo.html
Tidy now supports a configuration file, and this is now much the most convenient way to configure Tidy. Assuming you have created a config file named "config.txt" (the name doesn't matter), you can instruct Tidy to use it via the command line option -config config.txt, e.g.
tidy -config config.txt file1.html file2.html
Alternatively, you can name the default config file via the environment variable named "HTML_TIDY". Note this should be the absolute path since you are likely to want to run Tidy in different directories.
The following options are supported:
<a href="somewhere.html" onmouseover="document.status = '...some \ really, really, really, really, really, really, really, really, \ really, really long string..';">test</a>
// sample config file for HTML tidy indent: auto indent-spaces: 2 wrap: 72 markup: yes clean: yes output-xml: no input-xml: no show-warnings: yes numeric-entities: yes quote-marks: yes quote-nbsp: yes quote-ampersand: no break-before-br: no uppercase-tags: no uppercase-attributes: no output-xhtml: yes char-encoding: latin1
If you are prepared to maintain a public URL for HTML Tidy compiled for a specific platform, please let me know so that I can add a link to your page. This will avoid the need for me to update this page whenever you recompile.
Linux users! A tidy compilation is available for Linux (ELF 32-bit LSB executable using 'libc.so.5' for Intel 80386): 'tidy'. Additional a man page can be downloaded: tidy.1.
AIX executable for Tidy! Compiled by Ciaran Deignan. The link is to a general download page. The executable is available for AIX 4.3.2 and later.
Windows users! A free graphical user interface (HTML-Kit) for HTML Tidy is now available for windows 95/98/NT. Alternatively, you can get tidy in its native form as a Windows console program: tidy.exe, with the command options as per above.
Mac users! You can now run HTML Tidy with FilterTop ( Screenshot), or as a command line interface application. My thanks to Terry Teague for this port.
Amiga users! Keith Blakemore-Noble has compiled Tidy for the Amiga.
You can also incorporate Tidy as part of a larger program, for instance in HTML editors or HTML transformation tools used for import filters, or for when you want to customize Web content to get the best out of different kinds of browsers. Imagine authoring clean HTML with CSS and at a touch of a button producing variants that look great and work reliably on a large variety of different browsers, taking into account the quirks of each. For instance, providing the ability to tune content for different versions of Netscape and Internet Explorer, and for browsers running on set-top boxes for televisions, handheld and palmtop devices, cellphones, and voice browsers. I am happy to quote for software development for such tools.
The code is in ANSI C and uses the C standard library for i/o. The parser is thread-safe although the code for pretty printing the parse tree is not (yet). The parser works top down, building a complete parse tree in memory. Document text is held as Unicode represented as UTF-8 in a character buffer that expands as needed. The code has so far been tested on Windows'95, Windows'98, Windows NT, Linux, FreeBSD, NetBSD, Ultrix, OSF, OS/MP, IRIX, NeXtStep, MacOS, BeOS, OS2, AIX, Amiga, SunOS, Solaris, IRIX and HP-UX, amongst others.
Conventions for whether lines end with CRLF, LF or CR vary from one system to another. I have included the C source for a utility tab2space which can be used to ensure that files use the line end convention of your choice, and to expand tabs to spaces.
tab2space -t4 -unix *.h *.c tab2space -tabs -unix Makefile
Note use of "-tabs" to ensure that tabs are preserved in the Makefile (it won't work without them!).
For those of you on Unix, here is a script you can use to strip carriage returns:
#!/bin/sh echo Stripping Carriage Returns from files... for i do # If a writable file if [ -f $i ] then if [ -w $i ] then echo $i # strip CRs from input and output to temp file tr -d '\015' < $i > toix.tmp mv toix.tmp $i else echo $i: write-protected fi else echo $i: not a file fi done
Save this script to a file, e.g. "scripcr" and use "chmod +x stripcr" to make it executable. You can then run it as "stripcr *.c *.h Overview.html Makefile"
I would like to thank the many people who have written to me with suggestions for improvements or reporting bugs. Your help has been invaluable.
Drew Adams, Jacob Sparre Andersen, Osma Ahvenlampi, Joe D'Andrea, Jerry Andrews, Chang Hyun Baek, Chuck Baslock, Christer Bernerus, Keith Blakemore-Noble, Eric Blossom, David Brooke, Andy Brown, Keith B. Brown, Andreas Buchholz, Maurice Buxton, Jelks Cabaniss, Trevor Carden, Terry Cassidy, Mathew Cepl, Kendall Clark, Jeremy Clulow, Dan Connolly, Keith Davies, Claus André Färber, Stephanie Foott, Rene Fritz, Francisco Guardiola David Getchell, Michael Giroux, Guus Goos, Léa Gris, Francisco Guardiola, Juha Häikiö, G. Ken Holman, Craig Horman, Jack Horsfield, Rick Jelliffe, Craig Johnson, Charles LaFountain, Steven Lobo, Zdenek Kabelac, Michael Kay, Johannes Koch, Rudy Kohut, Allan Kuchinsky, Nick Leverton, Dietmar Lippold, Gert-Jan C. Lokhorst, Anton Marsden, Shane McCarron, Ian McKellar, Chris Nappin, Ann Navarro, Allan Odgaard, Matt Oshry, Gerald Oskoboiny, Ernst Paalvast, Christian Pantel, Steven Pemberton, Xavier Plantefeve, Ross L. Richardson, Philip Riebold, Erik Rossen, Dan Rudman, Christian Ruetgers, Klaus Johannes Rusch, Eric Schindler, J. Schlauch, Christian Schüler, Jim Seymour, Kazuyoshi Shimizu, Geoff Sinclair, Jo Smith, Rafi Stern, Michael J. Suzio, Oren Tirosh, John Tobler, Stuart Updegrave, Charles A. Upsdell, Larry W. Virden, Daniel Vogelheim, Jez Wain, Paul Ward, Jeff Young
Dave Raggett <dsr@w3.org> is an engineer from Hewlett Packard's UK Laboratories, and works on assignment to the World Wide Web Consortium, where he is the W3C lead for HTML, Math and Voice Browsers.