Home

How to Use Tidy to Repair HTML5 Pages

|
Updated:  
2016-03-26 13:18:12
|
HTML5 and CSS3 All-in-One For Dummies
Explore Book
Buy On Amazon

A great resource — HTML Tidy — can be used to fix your pages. You can download Tidy or just use the online version. Here is the online version with oxWheels1.html being loaded.

image0.jpg

Unlike W3C's validator, Tidy actually attempts to fix your page. This is how Tidy suggests the oxWheels1.html page be fixed.

Tidy examines the page for a number of common errors and does its best to fix the errors. However, the result is not quite perfect:

image1.jpg
  • It outputs XHTML by default. XHTML is fine, but because we're doing HTML here, deselect the Output XHTML box. The only checkbox you need selected is Drop Empty Paras.

  • Tidy got confused by the headings. Tidy correctly fixed the level one heading, but it had trouble with the level two heading. It removed all the tags, so it's valid, but the text intended to be a level two heading is just sort of hanging there.

  • Sometimes, the indentation is off. If you set Tidy to indent every element, it is easy to see how tag pairs are matched up. If you don't set up the indentation explicitly, you will find Tidy code very difficult to read.

  • The changes aren't permanent. Anything Tidy does is just a suggestion. If you want to keep the changes, you need to save the results in your editor. Click the Download Tidied File button to do this easily.

Consider using Tidy when you're stumped because the error messages are easier to understand than the W3C validator. However, never trust it completely. Until it's updated to truly understand HTML5, it sometimes deletes perfectly valid HTML5 tags. There's really no substitute for good old detective skills and the official W3C validator.

Did you figure out that last error? The paragraph was closed with

rather than

. That sort of thing freaks out an XHTML validator, but HTML takes it in stride, so you might not even know there is a problem.

Tidy does notice the problem and repairs it. Remember this when you're working with a complex page and something doesn't seem right. It's possible there's a mistake you can't even see, and it's messing you up. In that case, consider using a validator and Tidy to figure out what's going wrong and fix it.

About This Article

This article is from the book: 

About the book author:

Andy Harris earned a degree in Special Education from Indiana University/Purdue University–Indianapolis (IUPUI). He taught young adults with severe disabilities for several years. He also taught himself enough computer programming to support his teaching habit with freelance programming.
Those were the exciting days when computers started to have hard drives, and some computers connected to each other with arcane protocols. He taught programming in those days because it was fun.
Eventually, Andy decided to teach computer science full time, and he still teaches at IUPUI. He lectures in the applied computing program and runs the streaming media lab. He also teaches classes in whatever programming language is in demand at the time. He has developed a large number of online video-based courses and international distance education projects.
Andy has written several books on various computing topics and languages including Java, C#, mobile computing, JavaScript, and PHP/MySQL.
Andy welcomes comments and suggestions about his books. He can be reached at [email protected].