/    Sign up×
Community /Pin to ProfileBookmark

My question is simple
I’m about to start to develop a new web site.
Is it worth taking the time to make it validate against the W3C XHMTL validator or would HTML 4 be fine?
In doing so will my site be more user friendly with other browsers?

to post a comment
HTML

12 Comments(s)

Copy linkTweet thisAlerts:
@fredmvApr 25.2004 — You make it sound almost as if with HTML 4.01 you wouldn't have to — you still do. HTML 4.01 is perfectly acceptable but I prefer working with XHTML. If you're working with other XML applications (e.g., MathML or SVG) it would be ideal. I would also argue that XHTML 1.0 Strict specifically is nice because it gets rid of bad elements such as iframes.
Copy linkTweet thisAlerts:
@David_HarrisonApr 25.2004 — [url=http://www.hixie.ch/advocacy/xhtml]Here's[/url] a text-only article on the subject that I found at [url=http://www.accessifyforum.com/viewtopic.php?t=1114]this[/url] thread.

Personally I use XHTML 1.1 and a meta tag to specify application/xhtml+xml. I have recently found that it's a waste of time without a little snippet of server side code which I now use. Without the server-side stuff I may as well have just used text/html XHTML which is pretty much the same as HTML 4.01.

So I guess what I'm saying is, if you have a server-side language available use XHTML 1.1 but if not use HTML 4.01. Here's the code for PHP:

<i>
</i>&lt;?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))
{
header("Content-type: application/xhtml+xml");
}else {
header("Content-type: text/html");
}
?&gt;
and for ASP:

<i>
</i>if InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") &gt; 0 then
Response.ContentType = "application/xhtml+xml"
else
Response.ContentType = "text/html"
end if
In both cases the code must go at the very start of the document, b before any code has been sent to the browser (even if it's just a line break).
Copy linkTweet thisAlerts:
@johndoe190Apr 25.2004 — Just out of curiosity what does that snippet of code do. I too use xhtml and was wondering whats its meaning is.
Copy linkTweet thisAlerts:
@David_HarrisonApr 25.2004 — If you want to use application/xhtml+xml then you have to have this meta tag (but obviously have your own character encoding):

<i>
</i>&lt;meta http-equiv="content-type" content="application/xhtml+xml;charset=windows-1252" /&gt;
But then you also need some server side code that tells the browser to interpret what it's receiving is application/xhtml+xml (so long as the browser can handle it). The code detects whether the browser can handle application/xhtml+xml and if it can't it tells the browser that it's sending normal text/html.

Here is some simplified code from the include file that I use on Hackus (it's ASP):

<i>
</i>
&lt;%

if InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/xhtml+xml") &gt; 0 then
Response.ContentType = "application/xhtml+xml"
else
Response.ContentType = "text/html"
end if

Response.Charset="windows-1252"

sub top(title) %&gt;&lt;?xml version="1.0" encoding="windows-1252"?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;

&lt;head&gt;

&lt;title&gt;Hackus&lt;%= title %&gt;&lt;/title&gt;

&lt;meta http-equiv="content-type" content="application/xhtml+xml;charset=windows-1252" /&gt;

&lt;style type="text/css" media="all"&gt;
@import "styles.css";
&lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;% end sub %&gt;

Copy linkTweet thisAlerts:
@The_CheatApr 25.2004 — Personally i think its best to go with html 4.01 strict. You dont have to worry about mime type issues and browser support.

Currently, sending xhtml as text/html [URL=http://hixie.ch/advocacy/xhtml]is considered harmful[/URL], and sending xhtml as application/xhtml+xml is only supported by Mozilla and newer versions of opera. ([URL=http://www.w3.org/People/mimasa/test/xhtml/media-types/results]complete list[/URL]) Also, [URL=http://www.xml.com/pub/a/2003/03/19/dive-into-xml.html]you have to use a server-side language[/URL] to truly send it as application/xhtml+xml.. which can be a pain when just trying to output a simple static page...

as fredmv said [URL=http://forums.webdeveloper.com/showthread.php?s=&threadid=33146&perpage=15&pagenumber=2]here[/URL] , [i]"HTML 4.01 can be used to create perfectly semantic documents and you won't have to worry about MIME type problems and browser support."[/i]
Copy linkTweet thisAlerts:
@Paul_JrApr 26.2004 — [i]Originally posted by lavalamp [/i]

[B]Here's the code for PHP:



<i>
</i>&lt;?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") [color=blue]||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator"))[/color]
{
header("Content-type: application/xhtml+xml");
}else {
header("Content-type: text/html");
}
?&gt;
[/B][/QUOTE]

Is the part in blue really necessary? Unless there's some obfuscated reason, I can't see why it'd be necessary...
Copy linkTweet thisAlerts:
@David_HarrisonApr 26.2004 — [i]Originally posted by Paul Jr [/i]

[B]Is the part in blue really necessary? Unless there's some obfuscated reason, I can't see why it'd be necessary... [/B][/QUOTE]
Well the red part certainly is:<i>
</i>
&lt;?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") [color=blue]||
stristr($_SERVER["HTTP_USER_AGENT"],"W3C_Validator")[/color][color=red])[/color]
{
header("Content-type: application/xhtml+xml");
}else {
header("Content-type: text/html");
}
?&gt;

<i>
:p

But seriously, I don't know PHP very well, Robert Wellock pulled that code off a web-site, pm'ed the code to me and I don't use it. I'm an ASP guy. ;)
Copy linkTweet thisAlerts:
@SamApr 26.2004 — the section in blue tells the w3 validator to take the application/xhtml+xml rather than the text/html, I really don't think this has any effect on the validation other than it makes your doctype slightly more strict
Copy linkTweet thisAlerts:
@PeOfEoApr 26.2004 — I use html 4.01 transitional more often because it is less to worrie about when I have data driven sites and they users control the content and then I have tons of forms running around. But if you are not heavy on the forms and xhtml would be the way to go.
Copy linkTweet thisAlerts:
@Paul_JrApr 26.2004 — [i]Originally posted by samij586 [/i]

[B]the section in blue tells the w3 validator to take the application/xhtml+xml rather than the text/html, I really don't think this has any effect on the validation other than it makes your doctype slightly more strict [/B][/QUOTE]

The W3 validator seems to do just fine without that piece of code (minus the last bracket ? ); I was playing around last night and I validated one of the pages that used just
[code=php]
<?php
if(stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) {
header("content-type: application/xhtml+xml");
}
else {
header("content-type: text/html");
}
?>
[/code]

The validator was fine, and the content type was application/xhtml+xml.
Copy linkTweet thisAlerts:
@pyroApr 26.2004 — [i]Originally posted by Paul Jr [/i]

[B]The validator was fine, and the content type was application/xhtml+xml. [/B][/QUOTE]
Yes, but if you look at the content-type in the validation results, it will say text/html even though you are sending it as application/xhtml+xml. The only reason for doing it, really, is to have the content-type show up as application/xhtml+xml on the W3C's validator.
Copy linkTweet thisAlerts:
@Robert_WellockApr 26.2004 — They might have updated the Validator by now, but when sent as a referrer you had to explicitly set the MIME.

As for XHTML 1.0 yes you can use Transtional as text/html.
×

Success!

Help @Superfly1611 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...