Getting started with XHTML programming

No Comments

This short guide is mainly for those who are interested in getting into XHTML programming, and/or improving the style in which it’s done from the beginning. That means that, at a minimum, you have to be able to edit your own HTML pages without having to use a visual object editor such as Design Mode in Dreamweaver. You have to know how to write some code, and understand how to edit and modify the source code of your document directly. Personally, I like using Dreamweaver in Code Mode, but there are many other good text editors out there.

For those who are already familiar with HTML, you might already know that XHTML is pretty well identical, except with a few extra rules that you need to follow, and a few extra lines added in.

Here is an example of a complete XHTML page that has all the necessary components in place for passing the XHTML validity test. It can be used for any site as a starting point, so it might be helpful to you to bookmark this page so you can come back and copy it whenever you need it. The code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

      <html xmlns=""
      xml:lang="en" lang="en">


            <title>Website title - the most important item for SEO</title>

            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <meta name="description" content="Description is still important to some
            search engines, and   should be different on every page, even if only
            slightly." />
            <meta name="keywords" content="enter, your, page, keywords, like, this" />

            <link rel="stylesheet" type="text/css" href="style.css" media="all" />



            <div id="centered-block">

                  <div id="header">
                        <img src="images/logo.gif" width="225" height="46"
                        alt="Your logo" />

                  <div id="content">
                        <h1>Your site content</h1>
                        <p>This is where you can place your content. Normally, you
                        will want to create your navigation above this section, or
                        have it in a left or right column here.</p>
                              <li>This is an unordered bullet list</li>
                              <li>You can modify the bullet by editing the
                              bullet-01.gif image</li>
                        <p>Good luck with building the rest of your site!</p>

                  <div id="footer">
                        Copyright &copy; 2009

            </div> <!-- centered-block div ends -->




There it is! That’s all you need to get started. Just remember to include all the above code, and you’re all set to begin your next great XHTML site. Actually, everything that was added between the <body> tags is not necessary, but it can really help get you started, especially if you are developing a typical centered site.

You can view the above code in your browser by clicking here. If you want to test it out to make sure it is a valid XHTML document, you can use the W3C Validation Service. Just copy and paste the complete URL from the above site, or from a site of your own, and click the Check button at the W3C site.

Also, remember that for an XHTML document, you must always use quotes around your tag attributes (actually, you should have always been doing this no matter what!), close all tags, and include alt text for every image. Another good practice is to use comments after some of your DIV tags, so you can keep track of where you are, like I did for the centered-block div. Once your code starts to get really long, you’ll sure be glad you did that.

If you don’t have your own basic XHTML and style files for when you want to begin a new project, I recommend using the code above. You will also need a CSS file for styling the above code to make it look the way you want it to look. To make things even easier for you, however, I have created your basic index.html, style.css, set up an images folder, and packaged it all up in a zip file for you. Just download it from here:

  • XHTML starter site (just unzip this and use it whenever you want to start an new XHTML site)

I recommend using the W3C validator periodically, as you are developing your site, to make sure it still passes as a valid XHTML document. It’s pretty easy to forget about closing a tag or breaking another rule that will cause your document to fail the test. Thankfully, the validator does a pretty good job of showing you where your problems are, and why you are getting errors. Good luck with developing your XHTML site!

Next Post
Adding Live Chat to your site

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed