5 Replies - 2200 Views - Last Post: 19 August 2012 - 10:30 PM

#1 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 928
  • View blog
  • Posts: 3,212
  • Joined: 19-January 10

HTML, XHTML, what?

Posted 19 August 2012 - 04:00 AM

So I've sorta just been wandering around HTML tutorials never really paying more attention than what's necessary to get the job done. One thing I've been wondering is what's the difference between HTML and XHTML? Which one should I use? Is there anything special I should know?
Is This A Good Question/Topic? 0
  • +

Replies To: HTML, XHTML, what?

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: HTML, XHTML, what?

Posted 19 August 2012 - 04:21 AM

HTML is based off SGML, something that allows for malformed tags, no casing rules and ridiculous semantics when writing HTML, a best placed example is this (I think):
<ul HEIGHT=30 width=45>
    <lI>List Item 1
    <Li>List Item 2
    <li>List Item 3
</UL>


XHTML, however, is "based off" XML, which means that you must use lowercase for everything, and your document must be well formed (meaning that every open tag must be subsequently closed!). When writing XHTML, you should treat it as an XML document and ensure everything parses with an XML parser. In fact, if you serve your site with the correct mime type (application/xhtml+xml), in good browsers you will get a parser error if the XML validation fails.

XHTML of the same above snippet would be like this:
<ul height="30" width="45">
    <li>List Item 1</li>
    <li>List Item 2</li>
    <li>List Item 3</li>
</ul>

(people don't shoot me for this, I know that height/width don't exist, give me a moment!)
.. this actually makes sense! You know when things stop and you know where you stand with it.

However as mentioned above that snippet is wrong, XHTML removed (like HTML 4.01 Strict) some style-related attributes from elements, such as height and width, to aid with the separation of markup from styling, where you should be using CSS. Note that style is not the correct place to be putting your CSS styling rules for an element, a separate stylesheet is, but that's for another post.

Now onto what you should be using, I don't think it specifically exists, but I'd recommend XHTML 5. What I mean by not existing is that XHTML5 was never specifically defined, like HTML 5 was, but I would use XHTML's XML rules, with HTML5's new elements. This is perfectly fine, since well formed tags aren't specifically ruled out by HTML5, they're just allowed (same with SHOUTY and non-shouty elements/attributes).

Edit: There will be some pedantic twits that could respond to this by saying something along the lines of

Quote

If you're not serving your XHTML as application/xhtml+xml then it's not XHTML

Now they would be correct with that statement, but it doesn't matter. Older versions of Internet Explorer do not render documents with that mime type, and cutting them out is not a good thing to do.

However, not sending your document with that mime type shouldn't stop you from writing with the XHTML syntax, it's just good sense.

EDIT #2: Some people could also come along and say that XHTML stopped you from using tables and forces divs into your layout which you should always be using over tables because divs are the best.

XHTML is nothing to do with this. Tables are not recommended for anything other than tabular data by definition, they never were, that didn't change with XHTML. The div element has always existed (always = HTML 3) and is just a generic block-level element (in the same way that span is a generic inline element).

Just getting that out there, because I've seen people say that XHTML is awesome because of divs in the past.

This post has been edited by RudiVisser: 19 August 2012 - 04:30 AM

Was This Post Helpful? 4
  • +
  • -

#3 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 928
  • View blog
  • Posts: 3,212
  • Joined: 19-January 10

Re: HTML, XHTML, what?

Posted 19 August 2012 - 04:54 AM

Wow, thanks! I wish I could give more than one reputation point for that post. One last question, XHTML is more of a style, correct? Does doctype have anything to do with this?
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: HTML, XHTML, what?

Posted 19 August 2012 - 05:09 AM

No XHTML is a real specification aside from HTML. What I'm referring to at the end is that there is no XHTML5, just HTML5, however it doesn't stop you from using XML-style-serialisation to write it.

The DOCTYPE does define whether it's XHTML or HTML yes of course, apart from, again, in HTML5.

HTML5's doctype is simply <!DOCTYPE html> in all cases.

HTML4 would be <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">.

Finally XHTML 1.0 would be <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">.

For your own reference, here is the XHTML 1.0 Specification, self-claimed to be "A Reformulation of HTML 4 in XML 1.0".

This post has been edited by RudiVisser: 19 August 2012 - 05:12 AM

Was This Post Helpful? 2
  • +
  • -

#5 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 928
  • View blog
  • Posts: 3,212
  • Joined: 19-January 10

Re: HTML, XHTML, what?

Posted 19 August 2012 - 02:33 PM

This makes sense, thank you :)
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: HTML, XHTML, what?

Posted 19 August 2012 - 10:30 PM

View PostRudiVisser, on 19 August 2012 - 02:09 PM, said:

No XHTML is a real specification aside from HTML. What I'm referring to at the end is that there is no XHTML5, just HTML5, however it doesn't stop you from using XML-style-serialisation to write it.

there are published some guidelines how to write HTML5 so that it is XHTML(/XML) compatible, though.

(http://www.w3.org/TR/2011/WD-html5-20110525/the-xhtml-syntax.html)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1