<tr> and <td> closing tags supposed to be optional, but can cause error? in XHTML?

sometimes I don’t add </tr> or </td> in table formatting, and most of the time it is no problem. (HTML 4.01 spec says both of them are optional).

But I remember in some situation, they gave some problem with the table formatting until i added the </td> and </tr> back and the problem went away.

could it be that because the page was in XHTML 1.0 instead and that mandates a closing tag? although, modern browsers should be smart enough to understand <td>1<td>2 and not mess up even when it is XHTML 1.0. Does someone know, if an actually browser will choke if </td> or </tr> is not used? thanks.

In XHTML it is required to end all tags where it is due. For more information read the stickied thread about XHTML. FF may be smart enough to know when to not choke, but what about IE? How would you fix that? Also your way wouldn’t validate and it is poor coding practice to not end all tags properly:sick:

In XHTML no closing tag is optional!
That also means <br> becomes <br/>, <hr> becomes <hr/> etc
Just like XML, all tags have to be closed

A good way to fix errors is by using W3’s validation services. It is a great trip there because you get another site dissing your own ;). Oh and you can fix markup :D.

[ot]Is that better way to tell them?

Post 600! I’m a guru now :D. Paul move over.[/ot]

you mean it “is” required? my main concern is, where can it actually mess up a modern browser? i remember seeing it happen before, but usually i work with HTML but not XHTML.

I had it as “is” but my post got edited by a certain someone (BBoardx…)

.

Yes it can mess up a browser. It is required to conform to the rules.

Any missing close tags in XHTML will stop most browsers from being able to display the page at all. The only browser that doesn’t care about whether you close your tags in XHTML or not is Internet Explorer because it only offers the file for download as it cannot display XHTML at all.

I am reading the FAQ’s on HTML since I have W3schools certification tomorrow (hope I pass).

IE just plain doesn’t support XHTML. They won’t display it: they have no idea what the f*ck it is.

OK I had to go look it up now, I’d never heard of such a certification… that’s some sort of really bad joke, right? :confused:

http://www.w3schools.com/cert/pic_html_certif.jpg

that’s interesting… the exam doesn’t say whether it is open book or not (like you can read any book or check on the internet provided that you finish the exam in 70 minutes). why i think it might be more relevant when it is open book? because when we work in real life, we actually can use any reference book or look up any info on the internet.

by the way, Boltz already became a “Sitepoint Guru” by posting more than 600 posts… hm… it sounds better than Sitepoint Mentor or Sitepoint Advisor, just that there is no badge… only if he can use CSS to overlay a badge under his name using negative margins or position: relative.

If the page displayed at all without those end tags, you weren’t using XHTML. My guess is that you were using pretend-XHTML (XHTML markup served as text/html). That is just HTML with syntax errors in it, it’s not XHTML.

No, they shouldn’t. In fact, they mustn’t. The XML specification mandates that an XML parser abort as soon as it encounters a well-formedness error. And since XHTML is an application of XML, a compliant parser must stop if a </td>, </th> or </tr> tag is missing.

You can also write <br></br> and <hr></hr>, although that may cause problems if you use pretend-XHTML.

That’s because XHTML is an application of XML. :slight_smile:

I see. thanks. so if i am for sure using HTML 4.01, then no need to serve the </td> and </tr> closing tags…

if using XHTML 1.0, then must use </td> and </tr>…

i think i saw a doc saying when a tag is empty, then no need closing tag, but that means it is one of those <br> or <hr> where you can either close it by </br> or </hr> or you still have to close it by <br /> and <hr /> huh? in other words, you always have to close it, just that for those, you don’t have to use a closing tag but use a self-closing one.

i wonder if i am serving a large table of numeric data, such as … 1.2MB, and let’s say each row has 8 cells, then how much faster it is if the doc has no </td> and </tr> versus if there are, assuming the data is passed using “gzip, deflate” and the transfer rate is 300kb/s. will do some experiment later… right now… working on a project using greasemonkey…

Not syntactically, no. But those end tags tend to make the markup much more easy to read for human beings.

Yes, there must be a matching end tag for every start tag in X(HT)ML.

The element types declared as EMPTY in the HTML DTDs must not have an end tag. There are no </br>, </hr>, </img>, </meta> tags etc in HTML.

For element types that can have content, the end tag is required even if the element is empty (except for those element types that have an optional end tag).

In XHTML it’s different, since it must be well-formed. Even empty elements need a closing tag. Instead of <br></br> etc XML offers a shorter notation, <br/>. It’s called a null end tag (NET), and it’s a feature that is theoretically available even in HTML (albeit with a different syntax), but no browsers support it in HTML.

Using <br/> in HTML actually means something different than in XHTML (it means <br>>). But all browsers have buggy parsers that interpret it as <br>, which is why pretend-XHTML works.

In real XHTML you can use NET syntax for any empty element, even if it’s not declared as EMPTY. For instance, the following is perfectly valid XHTML:

<script type="application/javascript" src="script.js"/>

You can’t use this in pretend-XHTML, though. NET syntax can only be used with EMPTY elements in pretend-XHTML.

In HTML you just use <br> and <hr>. In XHTML you’d normally use <br/> and <hr/>. In real XHTML you could also use <br></br> and <hr></hr>, but there’s no reason to. In pretend-XHTML it’s customary to leave a space before the NESTC delimiter (<br /> etc) to cater for extra-buggy HTML parsers.

Here is an example of someone really putting HTML4’s “optional” tags to the test. This page is actually valid, though (deliberately) sloppy.

It would not be as XHTML but he’s smart enough to know that XHTML gives no benefits if served the way he’s serving it so he stayed with HTML4.

no <head>, no <body>, no </li>, yet it is valid 4.01 strict code. He is my new hero. (just kidding).

I wouldn’t call it sloppy. Impractical and perhaps a bit provocative, yes, but not sloppy.

Hmmm, okay, not sloppy, but definitely provocative : ) He told me “don’t believe everything they tell you” and maybe wants his site to be as lean as possible.

I styled the page originally and rewrote the HTML from what is was originally, but he removed my “looks nice at 600x800” setup and then removed all the “superfluous” tags lawlz. So I didn’t want my name on the page.

When using FF Ctrl+A will upload the current page to the W3’s validation service.

also, if you install Wed Developer’s Tool on FF, at the top right corner of the window at the toolbar, you will see the checkmark for HTML and CSS as well.

PS. I just found that a green checkmark for HTML doesn’t mean anything… it merely indicates it is Compliance mode but doesn’t validate the HTML. The CSS checkmark does say there is no CSS error… but supposedly the w3c.org one is more authoritative.