A quick pointer in the direction of valid HTML

Associate
Joined
28 Jun 2005
Posts
895
I have just started fiddling around with HTML and PHP this summer after not touching it seriously for a couple of years.
I never produced "valid" html by a long way when I used to do it.
If I use w3 to validate the code what doctype should I use for standard code? HTML 4.01 strict or maybe Transistional or should I aim to validate it to XHTML 1.0 (either strict or transistional)?

Does it particularly make a difference who I am aiming it at as to what I choose? Is there always one that 99% of the time I should use?

Thanks for any input
Ric.
 
Permabanned
Joined
21 Apr 2004
Posts
13,312
Location
Wolverhampton
Aim for XHTML Transitional. Sometimes it can be more hassle than it's worth to get a large, complicated site working in Strict, so start with Trans for now. :)
 
Soldato
Joined
18 Oct 2002
Posts
5,464
Location
London Town
|Ric| said:
Does it particularly make a difference who I am aiming it at as to what I choose?
Yes.

Is there always one that 99% of the time I should use?
No.

Doctypes provide information about [what describes] how each element in the markup language you're using should be interpreted. However, in reality this is not how they're used. For XHTML/HTML, browsers use these doctypes to switch rendering modes; between quirks, standards and almost-standards. You want to be aiming for a doctype that triggers standards mode in all the browsers you're aiming to support, as this means the browsers will render pages according to the W3C recommendations and you won't have to deal with any peculiarities. Strict doctypes trigger standards mode in most browsers, and so a strict doctype is what I recommend. There's no reason to be using a transitional doctype on a new site, since you're not transitioning any old code and thus have no need for backwards support.

For a list of doctypes and the rendering modes they trigger : http://hsivonen.iki.fi/doctype/

With regards to which standard you should be using - XHTML or HTML - well there's no right or wrong answer. One is not better than the other, they just serve different purposes, but it would be too lengthy a post to get into the details. It's probably best to point you in the direction of comparison articles so you can make your own mind up, and then come back with any specific queries you have :).

http://www.robertnyman.com/2005/11/02/html-or-xhtml/
http://24ways.org/advent/transitional-vs-strict-markup
 
Soldato
Joined
18 Oct 2002
Posts
5,464
Location
London Town
Sure is extensible (not that anyone is actually doing that), but being futureproof applies in only some respects. Going by Microsoft's current timescale, we're unlikely to be able to use XHTML without crufty browser-sniffing or workarounds until about 2015. And who knows what we'll be using then.

iCraig said:
XHTML is a tighter version of HTML [..] It's easier to write and to understand
It's XML that is tighter than the SGML-ness of HTML. XHTML can be more verbose than HTML. It's only because the syntax of XHTML is more restrictive by the nature of the XML that it appears tighter than HTML. The DTDs are identical, bar the syntax requirements. There's no reason the author can't apply the same restrictions when writing HTML 4.01, negating the 'tightness' of XHTML syntax. Unless writing an 'EMPTY' element as <br /> instead of <br> is easier to write and understand?

There's nothing wrong with XHTML, but I think it's better for an author make an informed choice about the different standards on the basis of the one that's right for the application in today's climate :).

For clarity, when I say XHTML, I mean XHTML 1.0
 
Last edited:

Sic

Sic

Soldato
Joined
9 Nov 2004
Posts
15,365
Location
SO16
i'd be inclined to agree with Augmented there...i don't think it's easier to write or understand. they're both logical in their own ways, and you can see valid reasons for doing it both ways, especially taking the <br>/<br /> or <img>/<img /> tags as examples; they're single entities with nothing enclosed...it's logical that you shouldn't HAVE to close them, but it's also logical in XHTML that you do have to...swings and roundabouts really.

i use XHTML because the X makes it sound cool.



i wish i was joking
 

Sic

Sic

Soldato
Joined
9 Nov 2004
Posts
15,365
Location
SO16
iCraig said:
True, they're logically just as simple as each other.

Sic, I share your feelings with the X.

I want CSS4 to be called XCSS. :D

CSSX is easier to say, and sounds awesome. but people might think it's CSS10. how about CSS-xtreme?

Mr_L...i always do that!!

mate: did you do your site in html?
me: no mate, Xhtml
mate: what's the difference
me: Xhtml sounds cooler
mate: *pause*

i feel like we need a William-Cartoon!
 
Associate
OP
Joined
28 Jun 2005
Posts
895
Right I still don't understand particuarly why I would validate code for XHTML opposed to HTML. I've read those various links and a little puzzled about all this "serving XHTML as text/html" or not business.

If I am just writing run of the mill webpages I am not as such using any extra functionailty of XHTML right? So all that happens if I want to validate for XHTML (so far in a very short and brief page) is I have to close some extra tags.

Going back to the serving XHTML as text/html, here seems to frown upon authours using XHTML without really knowing why they are using it (ME!).
At the end of the day if my code validates do I need to worry about this?

Ric.
 

Sic

Sic

Soldato
Joined
9 Nov 2004
Posts
15,365
Location
SO16
if you're using html 4.01 and it's working (across all browsers you use), and it validates, don't update for the sake of it. but i'd read up on what you'd need to do to make your code XHTML valid as well, because it doesn't hurt to have the extra skillset under your belt :)
 
Permabanned
Joined
21 Apr 2004
Posts
13,312
Location
Wolverhampton
If your site isn't XHTML valid, you'll be removed from this sub-forum. :)

But yeah, Sic's correct. It isn't obligatory that all sites should be XHTML. Just bear it in mind the next time you do a big update on the site, or if you do a new site from scratch. :)
 
Associate
OP
Joined
28 Jun 2005
Posts
895
thats the thing, im just fiddling at the moment - half creating a new site. Should I make it XHTML compliant over HTML is what I really want to know :p
I want it to be valid to one standard but I have no idea which
 
Soldato
Joined
18 Oct 2002
Posts
5,464
Location
London Town
|Ric| said:
thats the thing, im just fiddling at the moment - half creating a new site. Should I make it XHTML compliant over HTML is what I really want to know :p
I want it to be valid to one standard but I have no idea which
Just pick one, it doesn't matter which. As long as you use a doctype that causes browsers to use standards-mode (i.e. Strict), it won't make the tiniest bit of difference whether you use XHTML or HTML. They will both be rendered and interpreted in exactly the same way when sent as text/html. The difference is that a browser receiving a valid XHTML document as text/html has to run error correction on the markup, whereas it won't have to for a valid HTML document. XHTML as text/html is technically invalid HTML, but it's part of the recommendation that browsers should be able support XHTML 1.0 as text/html, so it's not a big issue.

If you can't make a choice, just go with XHTML. Because everyone's using it and abusing it, but nobody's making use of it :D.
 
Permabanned
Joined
21 Apr 2004
Posts
13,312
Location
Wolverhampton
Plus you can stick one of those little badges on your site that everyone seems to do. :rolleyes:

Whilst you have your head buried in the site, you may aswell do it in XHTML. That way, you'll learn about it and be ready for when it starts to kick in.
 

Sic

Sic

Soldato
Joined
9 Nov 2004
Posts
15,365
Location
SO16
i'll make use of it one day...i just need to get some proper tutorials on XHTML as its own language, rather than a different way of writing html. when i first heard what it was capable of, i thought "awesome, i can write my own html tags", but i've not gotten round to implementing it yet. i'm rewriting my site at the moment, so i might try it then.
 
Back
Top Bottom