Sunday, November 18, 2012

Answers > How Can You Tell if Your Coding XHTML or HTML?

How Can You Tell if Your Coding XHTML or HTML?

by nForms on April 15, 2012

I mean I do know there are differences such as -

XHTML elements must be properly nested
XHTML elements must always be closed
XHTML elements must be in lowercase
XHTML documents must have one root element

but is this really it? Please serious answers only. I only recently started coding myself so would appreciate your help. Thanks.

Tags: , , , , , ,

Similar XForms | XML Posts

{ 6 comments… read them below or add one }

Michael April 25, 2011 at 9:34 am

I know if I’m coding in XHTML when I start my document with an XHTML doctype, such as:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
" DTD/xhtml1-transitional.dtd">

[space added before DTD to overcome Yahoo! Answers deficiencies]

To tell if a document you are looking at (that does not have a doctype) is HTML or XHTML look for tags for which closing tags are forbidden, such as <meta>, <hr>, <input>, <link>, <img> in HTML, or required to be self-closing such as <meta/>, <hr/>, <input/>, <link/>, <img/> in XHTML. If the tags end /> then you are looking at XHTML, if they end > you are looking at HTML. However a word of warning, some times people who don’t know better copy code that is written in XHTML and paste it into what is otherwise an HTML page.

Apart from that (and the differences you noted), there is very little difference between HTML and XHTML.

For more on doctypes see:

Furry April 25, 2011 at 9:34 am

i know this, in html tags are opened and closed like <font></font>
and xhtml its just <font/> to open and close it

legalpro April 25, 2011 at 9:34 am

go to and look it up

I think you have to specify a tag at the beginning of your code so that the browser knows what you are coding in. If you are using xhtml an don’t follow the rules stated above, then you’ll get an error when loading it or the browser won’t read your code.

If you look at a code, you know a person is following xhtml if they are following the above rules-you’ll notice, for example, that all the elements tags are always in lowercase and there’s always a start tag with an end tag.

w3schools gives a pretty good explanation of this topic

FruityCustard April 25, 2011 at 9:34 am
Chris B April 25, 2011 at 9:34 am

Well you NEED to state the Doc type in the beginning of the document. also XHTML is much more strict.

workerbee April 25, 2011 at 9:34 am

Chris is right, you start at the top of your page with what is called the DOC Declaration. When you establish that your page is following the standards set of either XHTML 1.0 transitional or strict or HTML 4.01. On these w3school XHTML DTD link gives more info on this.

Your coding will be cleaner and load quickly. You can use the link on the w3schools to validate your test pages for errors.

Previous post:

Next post: