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
1512
votes
12 answers

Why don't self-closing script elements work?

What is the reason browsers do not correctly recognize: Does this break the concept of XHTML support? Note: This statement…
dimarzionist
  • 18,517
  • 4
  • 22
  • 23
964
votes
15 answers

When is a CDATA section necessary within a script tag?

Are CDATA tags ever necessary in script tags and if so when? In other words, when and where is this: preferable to this:
brad
  • 73,826
  • 21
  • 73
  • 85
919
votes
25 answers

What's the difference between and , and ?

What's the difference between and , and in HTML/XHTML? When should you use each?
Philip Morton
  • 129,733
  • 38
  • 88
  • 97
642
votes
7 answers

Can we have multiple in same ?
Can we have multiple
tags in same
? If yes then in what scenarios should we use multiple tags?
Jitendra Vyas
  • 148,487
  • 229
  • 573
  • 852
601
votes
31 answers

Make a div into a link

I have a
block with some fancy visual content that I don't want to change. I want to make it a clickable link. I'm looking for something like
, but that is valid XHTML 1.1.
EE.
  • 6,111
  • 3
  • 18
  • 5
511
votes
18 answers

Margin on child element moves parent element

I have a div (parent) that contains another div (child). Parent is the first element in body with no particular CSS style. When I set .child { margin-top: 10px; } The end result is that top of my child is still aligned with parent. Instead of…
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
489
votes
6 answers

Is there a tag to turn off caching in all browsers?

I read that when you don't have access to the web server's headers you can turn off the cache using: But I also read that this doesn't work in some versions of IE. Are there any set of
leeand00
  • 25,510
  • 39
  • 140
  • 297
367
votes
19 answers

Can an HTML element have multiple ids?

I understand that an id must be unique within an HTML/XHTML page. For a given element, can I assign multiple ids to it?
I realize I have an easy solution with simply using a class. I'm just curious about…
webmat
  • 58,466
  • 12
  • 54
  • 59
341
votes
6 answers

How do I properly escape quotes inside HTML attributes?

I have a drop down on a web page which is breaking when the value string contains a quote. The value is "asd, but in the DOM it always appears as an empty string. I have tried every way I know to escape the string properly, but to no avail.
Chris
  • 3,702
  • 3
  • 23
  • 15
295
votes
14 answers

Tick symbol in HTML/XHTML

We need to display a tick symbol (✓ or ✔) within an internal web app and would ideally like to avoid using an image. Has to work starting with IE 6.0.2900 on a XP box, ideally we need it be cross-browser (IE + recent versions of FF). The following…
Vlad Gudim
  • 23,397
  • 16
  • 69
  • 92
294
votes
33 answers

Add centered text to the middle of a horizontal rule

I'm wondering what options one has in xhtml 1.0 strict to create a line on both sides of text like-so: Section one ----------------------- Next section ----------------------- Section two I've thought of doing some fancy things like this:
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
272
votes
22 answers

HTML list-style-type dash

Is there a way to create a list-style in HTML with a dash (i.e. - or – – or — —) i.e.
  • abc
Outputting: - abc It's occurred to me to do this with something like li:before { content: "-" };, though I don't know the…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
266
votes
16 answers

Replacing H1 text with a logo image: best method for SEO and accessibility?

It seems like there are a few different techniques out there, so I was hoping to get a "definitive" answer on this... On a website, it's common practice to create a logo that links to the homepage. I want to do the same, while best optimizing for…
Andrew
  • 227,796
  • 193
  • 515
  • 708
1
2 3
99 100