From Dave Raggett:
HTML Tidy fixes HTML-tagging mistakes automatically and tidies up sloppy editing into nicely layed-out markup. 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. HTML Tidy is able to fix up a wide range of problems and brings to your attention things that you need to work on. Each item found is listed with the line number and column, so that you can see where the problem lies in your markup. HTML 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".