Click to See Complete Forum and Search --> : Using HTML or XHTML?
NotionCommotion
01-27-2007, 11:04 AM
I get mixed messages whether I should be using XHTML or HTML. Presumably expert sources such the “worldwide bestseller Visual Quickstart Guide” book I bought state that I should use XHTML because it is more standard and consistent, and likely more portable in the future. I also like the idea of learning how to do it right so if I ever learn XML, I will at least be a little further along. I also hear conflicting advise from another book I purchased.
How does one determine which one should be used? Thanks
drhowarddrfine
01-27-2007, 11:34 AM
Right now, most servers are set to serve pages as HTML and not XHTML. And some browsers, such as IE, do not work with Xhtml at all when it is served as xhtml. So it's better right now to just use html.
But if this is just a learning experience, doing xhtml for yourself is just fine. You might even consider starting off with XML since Xhtml is XML anyway.
Charles
01-27-2007, 01:29 PM
Right now, most servers are set to serve pages as HTML and not XHTML. And some browsers, such as IE, do not work with Xhtml at all when it is served as xhtml. So it's better right now to just use html.
But if this is just a learning experience, doing xhtml for yourself is just fine. You might even consider starting off with XML since Xhtml is XML anyway.Not again!
MSIE is the one browser that gets XHTML correct. And XHTML has so many pitfalls and incompatibilities with HTML and HTML browsers that you shouldn't even try to use it unless you really know what you are doing. Much has been written about this subject on these boards so do a search.
mrhoo
01-27-2007, 07:09 PM
Like a lot of others in these forums, I've written sites that had to validate in 'xhtml' but are served as text/html. Honestly, I'd rather work on a site with any doctype policy than none at all.
The client differences in rendering the same pages in xhtml1.0 Strict or html4.01 Strict (with the only differences those that are required for valid code) are minor, compared with having no doctype.
For my own site, I figure I'll stick with html4.01 until I name my home page 'index.xhtml' . Unless html 5 gets off the ground....
Charles
01-27-2007, 07:17 PM
The client differences in rendering the same pages with xhtml1.0 Strict or html4.01 Strict are minor....That can be true but one can make a completely valid XHTML document that completely fails on an HTML browser.
drhowarddrfine
01-27-2007, 10:02 PM
MSIE is the one browser that gets XHTML correct. I know, Charles. You've corrected me on this in the past but I don't recall why I always read that IE doesn't work with xhtml at all. There must be a situation that exists that causes people to say this. I'm sure you know what it is.
Charles
01-28-2007, 04:30 AM
The situation is that people have little understanding of XHTML.
The problem is that MSIE doesn't understand that application/xhtml+xml mime type. But application/xml & text/xml are both suitable for XHTML ( http://www.w3.org/TR/xhtml-media-types/ ).
Stephen Philbin
01-28-2007, 06:40 AM
This is the most recent "HTML or XHTML?" thread we've had here. Should save everyone repeating themselves and give you some answers a bit faster.
http://www.webdeveloper.com/forum/showthread.php?t=135029
NotionCommotion
01-28-2007, 11:44 AM
Thanks for the good information here and good thread.
My page currently validates using xhmtl strict. I then changed to html, and received several errors:
character data is not allowed here.
document type does not allow element "SELECT" here; missing one of "P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS" start-tag.
I expect the first is due to using " />" instead of ">" for single tags. I haven't yet figured out the second.
I have gathered from this post that for most applications, there is no benefit of using xhtml, so why bother. That being said, if one doesn't mind "bothering", is there any reason not to?
Thanks
Charles
01-28-2007, 12:25 PM
Both of those errors are from using a Strict rather than the now obsolete transitional DTD.
And there is one very compelling reason not to use XHTML. It is perfectly possible to make a completely valid XHTML document that fails on an HTML browser. If you do want it to actually work on the web you have to use XHTML 1.0 served as text/html and you must read, mark, learn and inwardly digest Appendix C to the XHTML 1.0 specification.
mrhoo
01-28-2007, 03:11 PM
I have also noticed that a select has to have a parent besides form or body to validate in html strict.
The error tells you some of the parent nodes that can contain the select-
they are all block level elements- headings, div, p and so on.
If you wrap a div or a p around everything in the form it should validate strict html.
I have been using at least one fieldset element for forms,
and containing all the controls in fieldsets.
Kind of like tbodies containing their rows.
This example validates with the fieldset, or with a p or div in its place, but returns the same error that you got if the select is directly decended from the body or a form.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
<title>Valid select</title>
</head>
<body>
<p id="p_opts"><a href="../webshop.html">Home</a></p>
<h1>HTML Form Elements</h1>
<h2>Select</h2>
<form action=''>
<fieldset>
<legend>A single select in a form</legend>
<select name="select_1">
<optgroup label="First optgroup">
<option selected="selected" value="option">Select element</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</optgroup>
<optgroup label="Second optgroup">
<option value="3">Option 5</option>
<option value="2">Option 6</option>
</optgroup>
</select>
</fieldset>
</form>
</body>
</html>
I don't find documentation for this, and I don't know if the validator is actually correct for html or xhtml in this case. But if you need it validated,
give the select a parent.
Charles
01-28-2007, 03:37 PM
I don't find documentation for this...Here's your documentation. From the HTML 4.01 DTD (http://www.w3.org/TR/html401/sgml/dtd.html):<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->That means that the FORM element requires both a start and an end tag, can contain one or more block level element or SCRIPT element but cannot contain another FORM element. <!ENTITY % formctrl "INPUT | SELECT | TEXTAREA | LABEL | BUTTON">
<!ENTITY % inline "#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;">
<!ENTITY % block
"P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">That means that SELECT elements are inline and not block level elements. You need a block level element between the FORM and the SELECT.
Read, mark, learn and inwardly digest http://www.w3.org/TR/html401/ .
I'm wondering, Have any of you regulars figured out yet where I get the phrase "Read, mark, learn and inwardly digest"?
NotionCommotion
01-28-2007, 03:59 PM
Thanks Mr Hoo and Charles,
I was actually getting the same error with br and input elements. I rapped everything with a div, and no longer get them. I finally have validated html!
Thanks
mrhoo
01-28-2007, 04:03 PM
Thank you Charles. I admit I never digested the bit about a form not containing inline elements.
NotionCommotion
01-28-2007, 04:09 PM
I just noticed my styling is no longer the same when I changed from xhtml strict to html strict. Is it typical for things like that to happen?
Charles
01-28-2007, 04:19 PM
Well, yes. Because XHTML DOESN'T WORK IN HTML BROWSERS, anything can happen.
drhowarddrfine
01-28-2007, 04:45 PM
The problem is that MSIE doesn't understand that application/xhtml+xml mime type.That's what I was saying. I used to say "native Xhtml" so I didn't have to explain all that.
NotionCommotion
01-28-2007, 05:06 PM
When using xhtml, I used the following hack that "Web Designers Reference" said to use to allow ie5 and earlier to work, and it had no adverse effects on ie6 and newer when using xhtml. It did have adverse effects on html ie 6 and 7, and when removed, my strict html displays as desired.
body {
font-size: x-small;
/* voice-family: "\"}\""; */
voice-family: inherit;
font-size: small;
}