Forum Moderators: open

Message Too Old, No Replies

Question about the validator

Am I doing it right?

         

Adam5000

1:23 pm on Mar 18, 2009 (gmt 0)

10+ Year Member



I ran this code through the validator and I'm wondering why it validated. Notice two opening <td> tags and only one closing </td> tag. Did I use the wrong settings?

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
</head>

<body>

<table>
<tr>

<td>
<td>
<p>
Test
</p>
</td>

</tr>
</table>

</body>
</html>

mattur

1:53 pm on Mar 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The closing tags on <td> elements are optional in HTML [w3.org].

This also applies to some other elements like <p>, <li> etc. Some elements' closing and opening tags are optional in HTML eg <head>, <html>, <body>.

XML requires well-formed markup, so end tags are not optional in XHTML.

swa66

2:14 pm on Mar 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HTML doctypes just aren't "strict" enough to demand well formed input. A pity if you ask me, and the main reason one should learn xhtml IMHO, although I'm sure some out here will disagree and state you don't want to use xhtml cause it would mean you always need to serve valid code only. I can live with the latter.

My pet peve in HTML:


...
<p>first paragraph text
<ul>
<li>first
<li>second
</ul>
"I don't obey any style"

<p>second paragraph text
...

The browser has to close the first paragraph before the <ul> as a <ul> inside a <p> isn't valid, resulting in that problem part not being in any <p> ... and hence not obeying styling for <p>'s ...

If you create well formed input the error would get spotted immediately as there simply are no assumed close tags (at least not when validating, browsers unfortunately still will insert them)

lavazza

7:07 pm on Mar 18, 2009 (gmt 0)

10+ Year Member



@swa66
My pet peve in HTML:

...
<p>first paragraph text
<ul>
<li>first
<li>second
</ul>
"I don't obey any style"

<p>second paragraph text
...

The 'tagless' "I don't obey any style" will FAIL (under HTML 4.01 Strict)

swa66

7:48 pm on Mar 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The 'tagless' "I don't obey any style" will FAIL (under HTML 4.01 Strict)

Actually:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
</head>
<body>
<div>
<p>first paragraph text
<ul>
<li>first
<li>second
</ul>
"I don't obey any style"

<p>second paragraph text
</div>
</body>
</html>

Validates at [validator.w3.org...] without as much as a single warning.

phranque

12:03 am on Mar 19, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I'm sure some out here will disagree and state you don't want to use xhtml

some previous WebmasterWorld discussion here:
Why most of us should NOT use XHTML [webmasterworld.com]

g1smd

7:00 pm on Mar 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I find HTML 4.01 Strict to be enough for my needs, often HTML 4.01 Transitional will do.