Slow transition to XHTML (part 3)

This is part 3 and the final part of these ‘Slow transition to XHTML’ articles.

In this part are some things that are not required to be in your XHTML files or need to be done, but are generally seen as good coding, so I suggest you do it too.

Layout-tags

Some tags like <font> describe the layout of your content and are depreciated in XHTML and the favor is given to using CSS.
There are however other tags that describe layout, but aren’t depreciated. Those should be avoided as well, but aren’t invalid.

The following tags should be replaced: <b><big><center><font><i><s><small><strike><u>.
Replace them by the following respectively: <strong>, CSS, CSS, CSS, <em>, CSS, CSS, CSS and CSS, although that using underlined text for anything else but links isn’t a good idea, because it confuses the visitor.

Specify your language

When you specify the language of your site, search engines will be able to translate your pages better, and your site might be found easier on the web.
It is also handy for people with a reading disability, who use web-readers who read pages out loud. These readers know, how to pronounce the words then.

Specifying the language can be done in each tag, but, you can also do it for your entire page in the <html> tag like this:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

XHTML is XML

XHTML uses XML to structure its pages. To specify that your XHTML page is XML you can add this

<?xml version="1.0" encoding="iso-8859-1"?>

at the top of your page, above the doctype.

There is however a small problem with this. Older versions of browsers when your page isn’t valid, will display your page as an XML file instead of an XHTML page.

Using external files

It is also recommended to use external stylesheets and scripts instead of embedding them (putting them at the top of your page, inline is a definite no-go).
Using external files is quite simple. For CSS, you just put all the CSS rules in a file and use the .css extention. Don’t put any HTML tags like <style> in this file, only what is in between the <style> tags.

For script, the same applies, only give the file a .js extention and it’s everything in between the <script> tags.

Now that you have the files, you need to call them from your XHTML file. Do this in your <head> like this:

<link href="style.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript" src="script.js">

That’s it for part 3. Your pages should now be about 2/3 to 1/3 of the original size and much cleaner.

No Responses to “Slow transition to XHTML (part 3)”.

Comments are closed.