Jump to content


Photo

HTML XHTML? Any difference?


  • Please log in to reply
151 replies to this topic

#1 cs.punk

cs.punk

    Advanced Member

  • Members
  • PipPipPip
  • 437 posts
  • LocationUK

Posted 06 March 2009 - 02:24 AM

Seriously this story has haunted me! I thought it was just a rename for the new HTML and that i's basically the same with new commands etc! And all the e-books I read all use the format I use (I THINK)... XHTML has <p>hello<p> commands while HTML has <p>hello</p> ?

Somebody please tell me the difference lol... And if I should worry?

Oh and can anyone tell me a good book for CSS? All I thought it was is for saving font, color, size in one shortcut but it seems to be much more :)
Life isn't just simply being alive... Or is it?

#2 Mchl

Mchl

    Advanced Member

  • Staff Alumni
  • 8,507 posts
  • LocationHigh Memory Area

Posted 06 March 2009 - 03:59 AM

http://en.wikipedia....ionship_to_HTML
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

#3 ejaboneta

ejaboneta

    Advanced Member

  • Members
  • PipPipPip
  • 168 posts

Posted 06 March 2009 - 05:18 PM

I understand the differences between how to write html and xhtml but what are the benefits to each?

#4 haku

haku

    Advanced Member

  • Staff Alumni
  • 6,177 posts

Posted 08 March 2009 - 07:46 AM

There really isn't any. It's personal choice. The idea behind XHTML was that it would be parsed using an XML mimetype (don't worry about what that is if you don't know), but IE doesn't support this, and since IE is the most used browser out there, it basically made XHTML pointless. Everyone just parses XHTML as HTML, and so they are eventually the same.

If you want to make a wise choice, parse using a strict version of either of them, and not the transitional version. Then make sure that your code is valid. This is much more important and will have more benefits for your code than the choice between HTML and XHTML.

#5 jackpf

jackpf

    Advanced Member

  • Members
  • PipPipPip
  • 1,410 posts
  • LocationUK

Posted 08 March 2009 - 10:57 AM

I think xhtml sounds cooler, so I stick with that :P

#6 Daniel0

Daniel0

    Advanced Member

  • Staff Alumni
  • 11,955 posts

Posted 08 March 2009 - 05:00 PM

http://www.phpfreaks...html#msg1128777

I think xhtml sounds cooler, so I stick with that :P

What separates pros from amateurs is that the former group knows why and when to use a specific tool. Just saying.

#7 jackpf

jackpf

    Advanced Member

  • Members
  • PipPipPip
  • 1,410 posts
  • LocationUK

Posted 08 March 2009 - 05:05 PM

No need to get personal; however, I'm fully aware that I'm not a pro. I'm a sixteen year old pubescent noob to be brutally honest.

But I try :)

#8 Daniel0

Daniel0

    Advanced Member

  • Staff Alumni
  • 11,955 posts

Posted 08 March 2009 - 05:16 PM

Don't take it as offense. I'm merely saying that one should have a broad knowledge of their entire tool set such that they can better make an educated estimation as to what would be better to choose in a given scenario. Part of what makes you a good programmer is that you are able to pick the right tool for the right job. If something for some reason is better than the latest cutting edge whiz-bang technology or whatever you perceive to be "cooler", then use that instead.

Considering that you're 16 years old, it wouldn't take long before to you an increasing extent will be required to argue for your opinions during your education.

Just because something is newer doesn't necessarily make it better. That fallacy is called argumentum ad novitatem.

XHTML does have some application, but for a regular website I do not think it's the right tool to use.

#9 Mchl

Mchl

    Advanced Member

  • Staff Alumni
  • 8,507 posts
  • LocationHigh Memory Area

Posted 08 March 2009 - 05:22 PM

That fallacy is called argumentum ad novitatem.


Oooh... a new one to my collection...:)
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

#10 jackpf

jackpf

    Advanced Member

  • Members
  • PipPipPip
  • 1,410 posts
  • LocationUK

Posted 08 March 2009 - 05:32 PM

I see your point...but from what you've taught me, they're both incredibly similiar.

So since XHTML is newer, and appears not to differ from HTML, why not use it? Tbh, I could actually just change my doctype and remove my xml declaration and it'd be html. It validates against all markups. So in my eyes, it makes little difference...

#11 svivian

svivian

    Advanced Member

  • Members
  • PipPipPip
  • 86 posts
  • LocationUK

Posted 08 March 2009 - 06:21 PM

In a nutshell, XHTML is the same as HTML but with a few differences that make it more "robust":
  • All tag names must be lowercase - i.e. <html> instead of <HTML>)
  • All elements must have corresponding closing tags - i.e. <p>paragraph</p> instead of <p>paragraph
  • Elements without closing tags should use /> - i.e. <br /> and <img src="..." /> instead of <br> and <img src="...">
  • All attributes must be in quotes - i.e. <span class="test">something</span> instead of <span class=test>something</span>
  • All attributes that are used must have values - i.e. <option selected="selected"> instead of <option selected>


#12 Mchl

Mchl

    Advanced Member

  • Staff Alumni
  • 8,507 posts
  • LocationHigh Memory Area

Posted 08 March 2009 - 06:23 PM

This still doesn't answer the question: 'why use XHTML over HTML?'
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

#13 haku

haku

    Advanced Member

  • Staff Alumni
  • 6,177 posts

Posted 08 March 2009 - 10:18 PM

I think I answered that in my post - it's just personal preference. I really don't think that there is any reason to use XHTML over HTML, and I also don't think that there is any reason to use HTML over XHTML.

Although if someone has one, I'm interested in hearing it.

#14 jackpf

jackpf

    Advanced Member

  • Members
  • PipPipPip
  • 1,410 posts
  • LocationUK

Posted 09 March 2009 - 03:52 AM

Well...it does look a lot neater when you've closed all tags in the right order..idk, i just prefer it...

#15 Daniel0

Daniel0

    Advanced Member

  • Staff Alumni
  • 11,955 posts

Posted 09 March 2009 - 06:58 AM

There are certainly a lot of differences between XHTML and HTML.

First of all, HTML is based on SGML whereas XHTML is based on XML. The X is short or extensible, i.e. Extensible Hypertext Markup Language.

Unless XHTML is served as application/xhtml+xml then it won't (and should not) be treated as XML by the UAs. If it's served as text/html then it will be treated as HTML. Some people think that it is the DTD that determines whether it is XHTML or HTML, but that is wrong. The DTD is merely a document containing grammar constraints. Of course if you serve XHTML as text/html then you miss out on the "extensible" part of XHTML, but if you serve it as application/xhtml+xml then you won't have any IE users for sure.

XHTML, when served as such, can be extended by any other XML based technology using XML namespaces. An example of that could be MathML. Inserting the following in an XHTML document:
<math xmlns="http://www.w3.org/1998/Math/MathML">
	<mrow>
		<mi>y</mi>
		<mo>=</mo>
		<mfrac>
			<mn>1</mn>
			<msqrt>
				<mrow>
					<msup>
						<mi>x</mi>
						<mn>2</mn>
					</msup>
					<mo>+</mo>
					<mn>1</mn>
				</mrow>
			</msqrt>
		</mfrac>
    </mrow>
</math>
Would produce something like [tex]y=\frac{1}{\sqrt{x^2}+1}[/tex] when served as application/xhtml+xml, but if you serve it as text/html then it'll look like y = 1 x 2 + 1 because all those elements are invalid in HTML and as such ignored. Another example is SVG for embedding vector graphics.

Here is another difference:

HTML-style
<style type="text/css">
<!--
h1 {
	font-size: 1em;
}
</style>

XHTML-style
<style type="text/css">
<![CDATA[
h1 {
	font-size: 1em;
}
]]>
</code>

If the former snippet is (wrongly) served as application/xhtml+xml then it won't work, and similarly, if the latter snippet is (wrongly) served as text/html then it will not work either.

Furthermore, the default character set for HTML is latin-1 (ISO-8859-1), but the default character set for XHTML is UTF-8. Indeed the only character sets an XML parser is required to support is UTF-8 and UTF-16. This can result in an odd output littered with strange symbols if you do it wrongly.

The thing is, you cannot use XHTML for Internet Explorer. It simply does not support it (the user will be prompted to download the page because IE doesn't know what to do with it). Some people have proposed to use content negotiation to serve different content to different UAs, but the problem is that a lot of the UAs lie about what they do accept. You will for instance find */* in IE's Accept header, but this is quite obviously untrue. That would constitute supporting literally every thinkable MIME type, including those which have not yet been invented. This would mean that it claims to support application/xhtml+xml as well, but it is fairly easy to verify that it does in fact not.

Moreover, the working draft of XHTML 2 is not backwards compatible with XHTML 1.x or HTML 4.x. HTML 5 will be backwards compatible. It doesn't look like XHTML 2 is going very strong whereas HTML 5 is well on its way.

There are a number of subtle syntactical differences between XHTML and HTML. Most notably the XML self closing tag. HTML does not support this. If you have <img src="foo.jpg" /> in HTML (or indeed XHTML served as text/html which then de jure is HTML) then it will technically speaking be invalid. The / is regarded as an invalid attribute and discarded. So a lot of those websites featuring "Valid XHTML 1.0" should say "Invalid HTML 4.01".

All of those are just some of the differences between XHTML and XML.

In 2007, Håkon Wium Lie (CTO of Opera and W3C member) said "So, I don't think XHTML is a realistic option for the masses. HTML5 is it." (source). Microsoft has also expressed that XHTML will not be supported in IE in the near future. Numerous other notable people in the industry have also stated that HTML is the way to go.

Well...it does look a lot neater when you've closed all tags in the right order..idk, i just prefer it...

There is no reason why you cannot do that in HTML as well.

By the way, I'm going to sticky this topic.

#16 WolfRage

WolfRage

    Advanced Member

  • Members
  • PipPipPip
  • 652 posts

Posted 13 March 2009 - 02:23 PM

After reading both replies (Articles) I have been thoroughly educated. In the beginning when I was learning web development I was digging deep into understanding DTD and the differences between HTML and XHTML, but I have obviously overlooked it since due to my IDE defaulting to XHTML. I will now have to go back and apply what I have learned about HTML and stop using XHTML, because as stated I really am not being compliant with XHTML any ways. Plus it is easy enough to change the settings on my IDE.

Thank you for the enlightening responses Daniel0.
-- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
Please be forewarned; rather than giving you exactly what you want I prefer to teach you how to get what you want. Knowledge is power, so take the time to learn PHP and you will be able to wield it's power.
If I just gave you the code to solve your problem then you will be back again tomorrow asking for more of the same code. So please take the time to learn. Thanks.

#17 jackpf

jackpf

    Advanced Member

  • Members
  • PipPipPip
  • 1,410 posts
  • LocationUK

Posted 13 March 2009 - 02:41 PM

Yeah...good advice. You seem like a knowledgeable chap, Daniel0.

Btw, I tried serving my entire sit as application/xhtml+xml

It actually worked, minus a few bugs which I've now resolved. Yeah...javascript didn't work too well in firefox though, but fine in opera. IE completely bodged it lol.

#18 dbrimlow

dbrimlow

    Advanced Member

  • Members
  • PipPipPip
  • 712 posts

Posted 15 March 2009 - 01:22 PM

It is a matter of starting properly and not getting into bad habits early. XHTML is basically a stricter version of  HTML 4.01 (only tags must be lower case and all the end tags are not optional and self-closing tags are requires for single tags like br, img, meta)

Since you are young, you may as well learn the proper way to markup HTML code. Using HTML vs XHTML is Less important than using a "strict" dtd instead of "transitional". You can get a head start on coding the right way instead of having to break yourself of bad habits later (like most of us who have been doing this since the '90s).

I personally use and validate to html 4.01 strict, but I use the rules of xhtml. By that I mean I code in all lower-case, and if you took my html 4.01 page and simply added the closing slash to self-closing tags it would be xhtml 1 strict.

The funny thing is that job recruiters have absolutely no clue, either, and think that XHTML is some cutting edge proof of skill and is what professionals use. Actually the opposite is true. Amateurs use xhtml much more than pros - only they mess it all up and don't follow the rules.

I have kept one or two of my sites in xhtml simply for clueless job recruiters or potential employers.

Learn VALID strict markup - html 4.01 or xhtml1. People who actually know better will be most impressed if you use html 4.01, though, instead of xhtml.
Dave

I am always amazed by no matter how much I know, I know I don't know as much as I thought I knew.  - D. Brimlow.

#19 Daniel0

Daniel0

    Advanced Member

  • Staff Alumni
  • 11,955 posts

Posted 15 March 2009 - 01:58 PM

XHTML is basically a stricter version of  HTML 4.01 (only tags must be lower case and all the end tags are not optional and self-closing tags are requires for single tags like br, img, meta)


It's not stricter. Although they look similar they're not based on the same language. HTML uses another syntax so it's rubbish saying that XHTML is stricter for those reasons.

[...] if you took my html 4.01 page and simply added the closing slash to self-closing tags it would be xhtml 1 strict.


No it would not. Read back in this topic.

The funny thing is that job recruiters have absolutely no clue, either, and think that XHTML is some cutting edge proof of skill and is what professionals use. Actually the opposite is true. Amateurs use xhtml much more than pros - only they mess it all up and don't follow the rules.


Agreed.

#20 jackpf

jackpf

    Advanced Member

  • Members
  • PipPipPip
  • 1,410 posts
  • LocationUK

Posted 15 March 2009 - 03:29 PM

Yeah...I agree with most of that.

But since xhtml 1.1 basic is actually stricter than xhtml 1.0 strict (there isn't a 1.1 strict, it's just 1.1 basic) and my site is pretty much valid, I reckon that's ok tbh.

Plus, the fact that it actually worked almost flawlessly (void the javascript for some reason) when I changed my content type to application/xhtml+xml. Considering my code is actually valid xml, I don't see any problem with it.

I don't think it really makes a difference whether my site is xml or html, as long as it's valid either way.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com