Author Topic: HTML XHTML? Any difference?  (Read 28093 times)

0 Members and 2 Guests are viewing this topic.

Offline cs.punkTopic starter

  • Enthusiast
  • Posts: 409
  • Gender: Male
  • Uhm er well...
    • View Profile
HTML XHTML? Any difference?
« on: March 06, 2009, 02:24:21 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 :)
« Last Edit: January 09, 2010, 12:32:48 AM by Zanus »
Life isn't just simply being alive... Or is it?

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
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

Offline ejaboneta

  • Enthusiast
  • Posts: 163
    • View Profile
Re: HTML XHTML? Any difference lol?
« Reply #2 on: March 06, 2009, 05:18:00 PM »
I understand the differences between how to write html and xhtml but what are the benefits to each?

Offline haku

  • Guru
  • Freak!
  • *
  • Posts: 5,778
  • Old Man
    • View Profile
Re: HTML XHTML? Any difference lol?
« Reply #3 on: March 08, 2009, 08:46:55 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.

Offline jackpf

  • Devotee
  • Posts: 1,406
  • Gender: Male
    • View Profile
    • Jack's Website
Re: HTML XHTML? Any difference lol?
« Reply #4 on: March 08, 2009, 11:57:23 AM »
I think xhtml sounds cooler, so I stick with that :P

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Posts: 11,817
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
Re: HTML XHTML? Any difference lol?
« Reply #5 on: March 08, 2009, 06:00:12 PM »
http://www.phpfreaks.com/forums/index.php/topic,241905.msg1128777.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.
« Last Edit: March 08, 2009, 06:02:17 PM by Daniel0 »

Offline jackpf

  • Devotee
  • Posts: 1,406
  • Gender: Male
    • View Profile
    • Jack's Website
Re: HTML XHTML? Any difference lol?
« Reply #6 on: March 08, 2009, 06:05:15 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 :)

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Posts: 11,817
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
Re: HTML XHTML? Any difference lol?
« Reply #7 on: March 08, 2009, 06:16:48 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.
« Last Edit: March 08, 2009, 06:17:20 PM by Daniel0 »

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: HTML XHTML? Any difference lol?
« Reply #8 on: March 08, 2009, 06:22:24 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

Offline jackpf

  • Devotee
  • Posts: 1,406
  • Gender: Male
    • View Profile
    • Jack's Website
Re: HTML XHTML? Any difference lol?
« Reply #9 on: March 08, 2009, 06:32:06 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...

Offline svivian

  • Enthusiast
  • Posts: 86
  • Gender: Male
  • needs more cowbell
    • View Profile
    • Pokemon Database
Re: HTML XHTML? Any difference lol?
« Reply #10 on: March 08, 2009, 07:21:36 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>

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: HTML XHTML? Any difference lol?
« Reply #11 on: March 08, 2009, 07:23:59 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

Offline haku

  • Guru
  • Freak!
  • *
  • Posts: 5,778
  • Old Man
    • View Profile
Re: HTML XHTML? Any difference lol?
« Reply #12 on: March 08, 2009, 11:18:15 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.

Offline jackpf

  • Devotee
  • Posts: 1,406
  • Gender: Male
    • View Profile
    • Jack's Website
Re: HTML XHTML? Any difference lol?
« Reply #13 on: March 09, 2009, 04:52:56 AM »
Well...it does look a lot neater when you've closed all tags in the right order..idk, i just prefer it...

Offline Daniel0

  • Administrator
  • 'Insane!'
  • *
  • Posts: 11,817
  • Gender: Male
  • ^bb|[^b]{2}$
    • View Profile
Re: HTML XHTML? Any difference lol?
« Reply #14 on: March 09, 2009, 07:58:57 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:
Code: [Select]
<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
Code: [Select]
<style type="text/css">
<!--
h1 {
font-size: 1em;
}
</style>

XHTML-style
Code: [Select]
<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.
« Last Edit: March 09, 2009, 08:00:08 AM by Daniel0 »