Should I start with HTML or XHTML? [closed]

2019-01-15 12:15发布

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.

标签: html xhtml
8条回答
闹够了就滚
2楼-- · 2019-01-15 13:07

Start with HTML, but use a validator. In HTML5, everyone seems to be focusing on the HTML, rather than the XHTML serialisation.

  • As I explain in my answer here, the designers of XML wanted to enforce higher coding standards and making parsing easier, but that only works if almost everybody switches. Instead of relying on your browser to enforce code quality, rely on validation.
  • Due to limited XHTML support in Internet Explorer <=8, pretty much everybody serves XHTML as text/html. This effectively restricts you to a subset of HTML and XHTM and requires you to follow compatibility guidelines. You could choose what format to serve based on user agent instead, but this is messy.

Given the limited advantages, I strongly recommend HTML, especially if you are a beginner.

查看更多
Explosion°爆炸
3楼-- · 2019-01-15 13:17

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.

查看更多
登录 后发表回答