Questions tagged [xhtml]

XHTML is the traditional name for what is now formally called the XML syntax of HTML, as opposed to the more commonly used HTML syntax, both of which are defined by the HTML5 standard. It is a markup language commonly used for HTML pages which are generated using a XML based tool chain. Do NOT use this tag for Facelets. Use [facelets] instead.

XHTML (eXtensible HyperText Markup Language) is an application of XML and a syntax of HTML. This syntax is available as an alternative to the more common HTML syntax, which was formerly based on SGML. It is a markup language commonly used for HTML pages which are used within an XML based tool as part of server-side specific (MVC) framework, such as Facelets and ASP.NET Web Forms.

Initially, XHTML 1.0 and XHTML 1.1 were defined in separate specifications from HTML 4.01, but now the HTML5 specification covers both syntaxes together.

The XML syntax has an orthogonal rule set which takes no account of the element types being used, whereas the HTML syntax has different rules for different types of elements. For example, void elements in HTML such as <link>, <meta>, <br> and <hr> are marked up using only start tags in the HTML syntax, while <div>, <span>, <a> etc. must always have separate start and end tags. Other tags, for example <p>, <li> <td> etc. have special rules about when start and end tags need to be used. In contrast, in the XHTML syntax all elements must be closed, either using separate start and end tags: e.g. <div> and </div> or, if they have no content, by using a shortened form e.g. <div /> The two syntaxes are mutually incompatible, and XML tools do not work directly on documents written in the HTML syntax.

XHTML was introduced to allow developers to exploit the simplification that this orthogonality brings.

XHTML is often used as the basis for server-side markup languages, so that the can be manipulated by XML-based tools. The final output of these tool chain might be generated documents in the regular HTML syntax or in the XHTML syntax prior to sending to the browser.

One common confusion with XHTML is over the use of doctypes and content types. Using one of the XHTML 1 doctypes (now all obsolete) caused HTML validators to check whether document were consistent with the XHTML syntax, while browsers treated the same documents as being in the regular HTML syntax. Browsers do not use the doctype to determine which syntax the document is in. Instead they use an HTTP header: content-type. An XHTML syntax document must be supplied to the browser with an XML content type, usually application/xhtml+xml or application/xml. Regular HTML syntax documents should be supplied with a content type of text/html. Modern validators now, like browsers, use the content type HTTP header to determine which syntax to check against, and for both syntaxes the doctype in the form <!DOCTYPE html> should be used.

The XML syntax of HTML requires the following which are optional in the regular HTML syntax:

  1. Root XML namespace attribute as in <html xmlns="http://www.w3.org/1999/xhtml">
  2. Elements must be nested. e.g. <b><i></b></i> is an error that will cause parsing to stop
  3. Start and end Tags must always be matched, or elements self-closed. (e.g. use <input></input> or <input /> but not <input>)
  4. Tag and attribute names must be all in lowercase (e.g. use 'onclick, notonClick`)
  5. Attribute values must be quoted with matching single or double quotes (e.g use class='foo', or class="foo", not class=foo)
  6. Attribute minimization is forbidden (e.g. use disabled="disabled" or disabled="", not disabled)

Resources:

6730 questions
260
votes
15 answers

Custom attributes - Yea or nay?

Recently I have been reading more and more about people using custom attributes in their HTML tags, mainly for the purpose of embedding some extra bits of data for use in javascript code. I was hoping to gather some feedback on whether or not using…
TM.
  • 108,298
  • 33
  • 122
  • 127
235
votes
2 answers

How to include another XHTML in XHTML using JSF 2.0 Facelets?

What is the most correct way to include another XHTML page in an XHTML page? I have been trying different ways, none of them are working.
Ikthiander
  • 3,917
  • 8
  • 37
  • 54
221
votes
12 answers

Making the main scrollbar always visible

What CSS is required to make the browser's vertical scrollbar remain visible when a user visits a web page (when the page hasn't enough content to trigger the scrollbar's activation)?
Deniz Dogan
  • 25,711
  • 35
  • 110
  • 162
195
votes
13 answers

What are all the valid self-closing elements in XHTML (as implemented by the major browsers)?

What are all the valid self-closing elements (e.g.
) in XHTML (as implemented by the major browsers)? I know that XHTML technically allows any element to be self-closed, but I'm looking for a list of those elements supported by all major…
kamens
  • 11,910
  • 6
  • 45
  • 46
194
votes
6 answers

Why can't the

tag contain a

As far as I know, this is right:

some words

But this is wrong:

some words

The first one can pass the W3C validator (XHTML 1.0), but the second can't. I know that nobody will write code like the second…
Henry H Miao
  • 3,420
  • 4
  • 20
  • 26
189
votes
6 answers

What is CDATA in HTML?

What is the use of CDATA inside JavaScript tags and HTML?
SexyMF
  • 10,657
  • 33
  • 102
  • 206
184
votes
14 answers

100% Min Height CSS layout

What's the best way to make an element of 100% minimum height across a wide range of browsers ? In particular if you have a layout with a header and footer of fixed height, how do you make the middle content part fill 100% of the space in…
Chris Porter
  • 2,449
  • 2
  • 24
  • 26
180
votes
8 answers

What is DOCTYPE?

What is DOCTYPE and why do I want to use it? What are the different DOCTYPEs I can use? What is the difference between standards and quirks mode, and what are some quirks I may run into with differently set DOCTYPEs? Lastly, what is the proper…
Bob
  • 97,670
  • 29
  • 122
  • 130
177
votes
3 answers

Do you need to close meta and link tags in HTML?

I was just reading somebody's HTML who never closed meta and link tags in the HTML head section. The code worked fine; is closing these tags optional? I thought it would be malformed if a tag was not closed.
bcollins
  • 3,379
  • 4
  • 19
  • 35
173
votes
1 answer

Valid content-type for XML, HTML and XHTML documents

What are the correct content-types for XML, HTML and XHTML documents? I need to write a simple crawler that only fetches these kinds of files. Nowadays http://example.net/index.html can serve for example a JPEG file due to mod_rewrite, so I need to…
astropanic
  • 10,800
  • 19
  • 72
  • 132
172
votes
8 answers

A space between inline-block list items

Possible Duplicate: Unwanted margin in inline-block list items How to remove “Invisible space” from HTML Why do the inline-block list items have a space in them? No matter how I make my list items into a menu, I always get spaces. li { border:…
Tyler Crompton
  • 12,284
  • 14
  • 65
  • 94
170
votes
5 answers

Is div inside list allowed?

I know that DIV inside LI isn't allowed, but I've seen it lately on many "big" websites like Smashing Magazine, Web Designer Wall... etc. I tried to validate sites, and they have errors, but nothing about DIV in LI?! So can I use it inside LI, and I…
Kenan
  • 1,725
  • 2
  • 10
  • 5
165
votes
17 answers

How to parse XML in Bash?

Ideally, what I would like to be able to do is: cat xhtmlfile.xhtml | getElementViaXPath --path='/html/head/title' | sed -e 's%(^|$)%%g' > titleOfXHTMLPage.txt
asdfasdfasdf
158
votes
3 answers

Are nested span tags OK in XHTML?

Will this validate in XHTML? helloworld
rick
  • 4,103
  • 9
  • 37
  • 41
155
votes
5 answers

Do we still need forward slashes when closing void elements in HTML5?

In HTML5, do we still need the end slash like in XHTML? validator.w3.org didn't complain if I dropped it, not even a warning. But some online documents seem to indicate the end slash is still required for tags such as…
CaptSaltyJack
  • 15,283
  • 17
  • 70
  • 99