Click to See Complete Forum and Search --> : Necessary to close <li> tag after each element?
BrettNooyen
01-13-2006, 10:30 AM
For XHTML is it appropriate to close every single <li> tag, or just place a final one at the end.
<ul>
<li>a
<li>b
<li>c</li>
</ul>
vs
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
Its always better practice to close tags.
It also makes it easier to read.
BrettNooyen
01-13-2006, 10:48 AM
Better.. yes? But on this current site we are cutting corners wherever to decrease load time, and by losing the closing tags I was able to drop a couple K off the site size.
Is it still valid without the closing tags. Ever coder has a preference, but is it actually valid is what I'm looking for.
Charles
01-13-2006, 11:05 AM
It is perfectly valid and a fine practice to eliminate the end tags in LI elements in HTML. And there are lots of other tags that you can eliminate. HTML Tidy can rid those for you if you like.
chazzy
01-13-2006, 11:25 AM
for XHTML you are required to close every opened tag or use <li /> although i'm not sure how that will turn out.
try running the site through the validator without the </li> and see if it's valid.
Edit:
I just ran this page through the validator
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<ul>
<li>hi
<li>mom
<li>how are you?</li>
</ul>
</body>
</html>
and it returned 4 errors, 2 warnings.
View it here (http://validator.w3.org/check?uri=http%3A%2F%2Fwww.firesoft-dev.com%2Flis.html&charset=%28detect+automatically%29&doctype=Inline)
Charles
01-13-2006, 12:30 PM
for XHTML you are required to close every opened tagBut there's no good reason to be using XHTML in the first place. Stick with HTML 4.01 Strict and rid yourself of the shackles of unreasonable and unnecessary restrictions!
BrettNooyen
01-13-2006, 12:57 PM
Might as well stick with tables too.
lol. no thanks.
Charles
01-13-2006, 01:38 PM
Might as well stick with tables too.For layout? That would be Html 3.2 or XHTML 1.0 transitional and quite yucky.
felgall
01-13-2006, 03:15 PM
For CSS to be applied correctly in ALL browsers all tags need to be closed in HTML (except the singleton tags <br> <hr> and <img>). In XHTML even singleton tags need to be closed by adding a / before the >.
You might be lucky to be able to omit some closing tags and have most browsers work out where the missing tags go and insert them for you but some browsers are bound to insert the missing tags in the wrong place.
Charles
01-13-2006, 03:23 PM
For CSS to be applied correctly in ALL browsers all tags need to be closed in HTML.That is complete and utter nonsense. The rules for HTML are set out in the DTD and the DTD says that the LI element doesn't need a closing tag and it says that the LI element cannot contain other LI elements. All browsers know, therefore, to close one LI element when another LI element is encountered and the tree is built accordingly. CSS operates on the tree not on the original markup.
Mr Initial Man
01-13-2006, 07:00 PM
I find it easier just to close all non-empty elements than wondering which do or do not need a closing tag.
Charles
01-13-2006, 07:58 PM
I find it easier just to close all non-empty elements than wondering which do or do not need a closing tag.As do I, but I'm not going to think less of someone who doesn't.
pcthug
01-14-2006, 01:26 AM
Better.. yes? But on this current site we are cutting corners wherever to decrease load time, and by losing the closing tags I was able to drop a couple K off the site size.
Is it still valid without the closing tags. Ever coder has a preference, but is it actually valid is what I'm looking for.
Browsers still correctly render HTML pages without the </li> tag.
But as for XHTML the </li> tag is neccesary to correctly render the page in some Browsers.
And as for decreasing loading times, Try by cutting down on any Images, Streaming Media, Flash, or server-side language befor tuning your HTML. In total a few </li> tags are going to equate to around 3 or 4 bits, and this is really practically removing milliseconds of your loading times,.
ray326
01-14-2006, 01:30 AM
few </li> tags are going to equate to around 3 or 4 bitsA single "</li>" sequence will be either 40 or 80 bits depending on the charset.
NogDog
01-14-2006, 02:03 AM
A single "</li>" sequence will be either 40 or 80 bits depending on the charset.
So, even assuming a worst case of 80 bits over a 28.8kbs modem, we're talking 0.0028 seconds per </li>, or in other words 360 </li> tags per second. So, if you have 360 <li> elements on your page (!?!), you'll save a whole, entire second on a 28.8kbs modem connection by leaving off the </li> tags.
Markbad311
01-14-2006, 05:03 AM
I know only one thing in XHTML 1.0 if you don't use self closing or a closing tag it is not valid. If you want to build your page out of errors fine but don't expect it to display right every time and for every different browser. world is larger then IE
chazzy
01-14-2006, 10:55 AM
But there's no good reason to be using XHTML in the first place. Stick with HTML 4.01 Strict and rid yourself of the shackles of unreasonable and unnecessary restrictions!
I think you missed his first post
For XHTML is it appropriate to close every single <li> tag, or just place a final one at the end.
The rules of HTML are much different than the XHTML ones.
Charles
01-14-2006, 03:03 PM
True, but this is the HTML forum.
johneva
01-14-2006, 03:58 PM
There is no XHTML forum on here though so this is going to get used for XHTML questions though int it.
Mr Initial Man
01-15-2006, 04:46 PM
AND his question was about XHTML.
Charles
01-15-2006, 05:27 PM
AND his question was about XHTML.His question was about XHTML and omitting certain tags. There are two answers to that:
1) You can't in XHTML.
2) But you can in HTML.
Put another way, the enquirer wanted two things that cannot go together. 1 above had already been given but another, likely better, way is 2. I added 2 to the conversation.