Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I start with HTML or XHTML? [closed]

Tags:

html

xhtml

So which one to start with, HTML or XHTML? I am a beginner and wants to have solid foundations of markup language but as I started learning I found some people use HTML and some XHTML.

like image 381
Jasmine Appelblad Avatar asked Jan 01 '10 20:01

Jasmine Appelblad


People also ask

Should I use XHTML or HTML?

XHTML was developed to make HTML more extensible and flexible to work with other data formats (such as XML). In addition, browsers ignore errors in HTML pages, and try to display the website even if it has some errors in the markup. So XHTML comes with a much stricter error handling.

Which is better HTML or XHTML and why?

HTML is the standard markup language for creating web pages, while XHTML is a stricter and more standardized version of HTML. Both HTML and XHTML include a wide range of features, such as support for multimedia, styling, and scripting.

Should I learn HTML5 or XHTML?

If you are a beginner at web design, we do not recommend HTML4 and XHTML, and it would make sense to learn HTML5 first because of it's enhanced compatibility and widespread usage.

Will XHTML replace HTML?

DEFINITION Extensible Hypertext Markup Language (XHTML) is a transition language that combines HTML and XML. Designed to replace HTML Version 4.0, XHTML is recommended by the World Wide Web Consortium. XHTML Version 1.0, also known as HTML 4.01, is a reformulation of HTML 4.0 as an XML 1.0 application.


2 Answers

Conventional wisdom has come sort of full circle on this point. Back in like 2002 everyone was gung-ho for XHTML but many people (including myself) didn't have good reasons why. It was just the cool new thing and everyone jumped on the bandwagon, started putting XHTML in their resume skills instead of just HTML which looked so plain and unimpressive.

What's happening now is, with HTML5 finished, people are starting to realize that there's nothing wrong with good old fashioned HTML. It's the language of the web. Here's the pros and cons of XHTML as I see them:

Pro

  • Allows you to embed non-xhtml XML into your web page, such as an SVG element. This isn't possible with plain HTML.
  • Allows you to easily parse your documents with an XML parser, which could obviate the need for hpricot or BeautifulSoup if say, you wanted to replace all H1 tags with H2 tags in your website templates.

Con

  • IE doesn't understand the 'application/xhtml+xml' mime type, so as far as it's concerned you're sending malformed HTML.
  • It's a little more verbose. <br> and <table cellspacing=0 cellpadding=0> is neater looking, in my opinion, than <br /> and <table cellspacing="0" cellpadding="0">.

There must be some advantages to XHTML that I'm missing, but I myself use HTML for everything these days.

like image 186
jpsimons Avatar answered Sep 26 '22 16:09

jpsimons


XHTML is only useful if you want to autogenerate/manage/validate/etc the HTML code with help of a XML based tool, such as a component based MVC framework (e.g. Sun JSF, Apache Struts, Microsoft ASP.NET, etc) or with XSLT. Parsing/formatting HTML programmatically is trickier than XML, because HTML allows here and there non-closing tags, e.g. <br>. XML is much easier to parse/format programmatically because it is required to be well-formed.

If you're just starting and/or hand-writing "plain vanilla" HTML, I would recommend to use HTML 4.01 elements with a HTML5 doctype. There's really no need to massage the HTML code into a XML format.

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Page title</title>
    </head>
    <body>
        <h1>Heading</h1>
        <p>Paragraph</p>
    </body>
</html>

The HTML 5 elements aren't widely supported yet, hence the recommendation to stick with HTML 4.01 elements. The HTML 5 doctype triggers the standards mode in most of the browsers, including IE6. The other benefit of HTML5 is that it allows closing shorttags like in XHTML. Also see HTML5 spec chapter 3.2.2:

Authors may optionally choose to use this same syntax for void elements in the HTML syntax as well. Some authors also choose to include whitespace before the slash, however this is not necessary. (Using whitespace in that fashion is a convention inherited from the compatibility guidelines in XHTML 1.0, Appendix C.)

Basically, even if you write pure XHTML, using <!DOCTYPE html> would still make it valid (and trigger webbrowsers in the correct standards mode).

like image 44
BalusC Avatar answered Sep 22 '22 16:09

BalusC