Welcome To Keith Dsouza’s Online Home
In: Tutorials
21 May 2006
In normal html you may be very familiar with the <html> tags, well every start html tag has to be ended by </html> as you may know.
But if you want to adhere to XHTML standards you should close each and every tag, we in developers term called them open tags.
For eg. normal html will have a line break tag as <br> but in XHTML thiis will be <br />, notice the forward slash in the original <br> tag that's called a open tag with no end, but we forcefully close it using <br />, Similary all tags which have no end have to be closed with a forward slash.
Other examples of such tags are <img>, <input>
What I mean is that, most people start tags and in between put tags that end outside the parent tag.
Wrong Code
<form>
<table>
<tr>
<td>My text</td>
</tr>
</form>
</table>
Note the error in the top is tags did not start how it ended, XHTML standards say that all tags should close as they started, You can relate to a term called Last In First Out (LIFO) here.
What I mean is that the last tag that's started should be the first one that should be closed.
3. Start and Close all attributes with double quotes (")
XHTML standards follow the strict DOM (Document Object Rules) and have entities like elements and attributes.
An element is a tag like <img> and a attribute is a child tag of an element like <img xsrc="abcd.gif" />.
Each element that has an attribute should be started and closed with double quotes (").
Wrong code
<img xsrc=abcd.gif border=0>
Right code
<img xsrc="abcd.gif" border="0">
If you see this in browser it will work but if your view this as a regular text you will see that xsrc=abcd.gif border=0, with no differentiation between the src and border so it will look that the image source is abcd.gif border=0 to the reader so you need to start and the attributes with "
The image tags on your html page should specify a alt tag, which means alternate thing when the image is not avialable, this is necessary as you may have noticed a sign with a X in it when images cannot be renedered or shown, Using alt text will show a short description about what the image is all about.
Mind you this also very helpful for search engine crawlers as they are incapable of viewing images and these alt tags help them to know more about it.
Wrong Code
<img xsrc="xhtmltutorials.png" />
Right code
<img xsrc="xhtmltutorials.png" alt="a tutorial about xhtml" />
Your comments are always welcome, let me know how you like this article, also if you have any other pointers please post them in the comments, Any further assitance required can also be asked.
Hi there. I own several blogs on the Internet, however I still love writing here, because it's my rambling space, no fear, no restrtictions. I write anything and everything here, so keep coming back. Read more about me