Cleaning Up HTML (and XHTML)

You’ve been reading about what great HTML Dreamweaver writes, and how, no matter what doctype you pick (XHTML 1, HTML 4.01, or HTML5, for example), Dreamweaver adds the correct tags in the correct order. But there are exceptions to every rule. In the process of formatting text, deleting elements, and—in general—building a web page, it’s quite possible to end up with less-than-optimal HTML. While Dreamweaver usually catches potentially sloppy code, you may nonetheless run across instances of empty tags, redundant tags, and nested tags in your Dreamweaver pages.

For example, in the normal course of adding, editing, and deleting content on a page (either by hand or even in Dreamweaver’s Design view), you can occasionally end up with code like this:

<div> </div>

This empty tag doesn’t serve any purpose, and only adds unnecessary HTML to your page. Remember, the less code your page uses, the faster it loads. Eliminating redundant tags can improve your site’s download speed.

Another possible source of errors is you. When you type HTML in Code view or open pages created by another program, you may introduce errors that you need to clean up later.

Aware of its own limitations (and yours), Dreamweaver provides a command designed to streamline the code in your pages: Clean Up HTML (if you’re using Dreamweaver’s XHTML mode, the command is called Clean Up XHTML). This command not only improves the HTML in your page, it can strip out other nonessential code, such as comments ...

Get Dreamweaver CS6: The Missing Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.