views:

317

answers:

5

How do i take a HTML site that currently has no doctype declaration and make it W3C compliant?

+3  A: 

First of all: think about why you need to make it W3C compliant. If it's just for the little badge, then it's not worth it.

If you do have a good reason (and there are plenty), then this is what I'd do:

Start by choosing a doctype. From the sound of it, HTML 4.0 might be the way to go. Run your page through a validator and then look at the error report it gives you. Go through it one by one, fixing each error. Usually the error report will tell you a good deal of information about how to solve each problem and give you the relevant links to the specification.

nickf
+1  A: 

You're going to need to determine the document type to which you'd like to adhere, and then begin working on making the site validate against it. I'd suggest picking something like XHTML Transitional to start with.

This may very well shape up to be a significant amount of effort, possibly for no real gain, and it may involve refactoring a lot of content, or making software changes, so be sure you're willing to accept that before you start. If the site is particularly egregious (e.g. font tags all over the place, no use of CSS), then you may very well find it's more trouble than it's worth.

Rob
A: 

I trash my previous answer, based on misunderstanding of the question...

The base answer would be to use HTML Tidy, it should help a lot to make it compliant.

PhiLho
That might have been a bit of ambiguity added by my edit. the files *currently* don't have a doctype, and he wants to make them compliant.
nickf
+1  A: 

Note: Without the DOCTYPE, IE WILL NOT render your page in Standards Mode.

scunliffe
A: 

I'd be inclined to leave-alone any pages which work satisfactorily. If it's not broken, don't fix it. However any pages which require redesign or troublesome modifications I would re-write using modern techniques.

The main problem is that when you add a doctype to the page IE 6 and up starts rendering the page significantly differently: it uses Standards mode instead of Quirks mode and the box model is different. So even if the page is well-coded, adding this doctype can totally change the rendering in a very popular browser. This means spending time fixing things, at minimum.

As for which doctype you should use, I recommend HTML 4.01 transitional. XHTML isn't worth the effort; real XHTML isn't well understood by most developers and if your code has a single error in it the whole page may not display; if you're serving XHTML as HTML then you may as well just serve HTML. There's not many good reasons why HTML isn't good enough.

Once you've selected a doctype, you can fix the HTML and CSS so that the page is smaller and cleaner and easier to maintain. This is a complex issue that can't be fully explained in a quick post, but it boils down to making sure your layouts are done using DIVS instead of TABLES, etc. Consider putting all the CSS in a <style> tag or external CSS file; personally I view any HTML attributes like height, width, or the inline style attribute to be bugs. For example:

<div height="100" width="100" style="border: 1px solid red"></div>

Should really be:

<head>
  <style> .adbox { height: 100px; width: 100px; border: 1px solid red; } </style>
</head>
<body>
 <div class="adbox"></div>
</body>

The main key to my recommendation is to spend your energy constructively; if something works fine you may not need to change it. The changes bring benefits but they also have a high cost, so don't blindly try to achieve something unless you're willing to pay for it. Simply saying "W3C Validation" isn't really a good goal; instead focus on easy maintenance, good content, small file sizes, accessibility for screen readers, etc.

Mr. Shiny and New