th colspan fails w3c validations - html

what is wrong with the following?
<table>
<tr> <th> Blah </th> <th colspan="2"> Something </th> </tr>
<tr> <td> .. </td> <td colspan="2"> ... </td> </tr>
</table>
It says Table column 3established by element th has no cells beginning in it.

As the error message says, there is no cell that begins in the third column. It thus violates the HTML table model as defined in HTML5, rather technically in 4.9.12 Processing model. Basically, the point is that you cannot create a column that consists only of slots created by cells starting in earlier columns and extending to other columns with colspan.
When using earlier versions of HTML, the error won’t be caught, since for them, validation is DTD-driven, and a DTD (document type definition, a formalized set of syntax rules written in SGML or XML) can only describe relatively simple syntax rules.
The most common cause of this problem seems to be a misguided idea of just making cells wider by using colspan. Instead, use the width attribute or, usually more preferably, the width property in CSS.

I've validated your HTML code with two doctypes:
HTML5;
XHTML 1.0 Strict.
And your document was successfully checked as valid.
You should try to revalidate it.

Related

Is td allowed inside thead?

I have couple of <th> elements within a <thead> element. The first one or one of them is an empty th used as placeholder and does not contain any text.
Wave tool gives out an error that th cannot be empty and suggests I change to <td>.
Now if I have a <td> within a <thead> it solves the issue and passes html validation too.
Is there any reason, I should not be having a <td> within <thead>
From HTML view:
<td> is allowed inside a <thead>. Permitted content of a <thead> are zero or more <tr> elements. In a <tr> element you can put a <td> and/or <th> element. It doesn’t matter.
From WCAG view:
A table can not have any empty table headers. This can be really confusing for screen reader users. There is one special case: Layout tables. Tables which are only used for "layouting", can have empty <td>'s as "column header". But if i understand your case correctly, you have some other regular table content, so you must add a column header for every column.
So in your case it is not ok to have an empty <td> as column header.

How do I correct html4 4.01 in asp.net using vs2012

In vs 2012 asp.net empty site I am using html4.01 for table desgin
I have a <div> (a couple actually) and i keep getting a warning that reads:
</div>
<div style="text-align:center;">
<table style="text-align:left; border-color:aqua;background-color:gold;border-width:2px;"cellspacing ="0" cellpadding ="8" rules ="none" width ="540">
<tr>
<td valign ="top">
Me
</td>
</tr>
</table>
</div>
Warning 1 Validation (HTML 4.01): Element 'tr' cannot be nested within element 'div'.
what would cause this?
Looking at the code you've posted:
You have a table, and the nesting looks like you intended to put the <tr> inside it.
However, the table is closed on the same line as it is started, so the <tr> is actually outside the table, after it.
Find the closing </table> tag, and move it to where it should be, after the rest of the code that is meant to be inside the table.
[EDIT]
Okay, you've now fixed that in the code in the question.
The next problem I can see is that your table tag has the following:
border-width:2px;"cellspacing ="0"
^^^
missing space here
The missing space before the cellspacing attribute will cause the tag to be invalid, which could also be breaking it.
For further HTML validation, I recommend you put your HTML code through the W3C's validator, which will highlight any further issues you may have with your HTML.

<div> into a <tr>: is it correct?

Is this code correct?
<table>
<tr>
<td>...</td>
</tr>
<tr>
<div>...</div>
</tr>
<tr>
<td>...</td>
</tr>
</table>
don't know for semantic (and W3C rules). What can you say about?
No it is not valid. tr elements can only contain th and td elements. From the HTML4 specification:
<!ELEMENT TR - O (TH|TD)+ -- table row -->
<!ATTLIST TR -- table row --
%attrs; -- %coreattrs, %i18n, %events --
%cellhalign; -- horizontal alignment in cells --
%cellvalign; -- vertical alignment in cells --
>
Not only is it not valid, but it doesn't work! This mark-up
<table>
<tr>
<td>The First Row</td>
</tr>
<tr>
<div>The Second Row</div>
</tr>
<tr>
<td>The Third Row</td>
</tr>
</table>
Produces this displayed
The Second Row
The First Row
The Third Row
The div is ejected entirely from the table and placed before it in the DOM
see http://jsfiddle.net/ELzs3/1/
No, you should not really use a div inside a table because it is a block level element. You can override the behaviour with CSS, but it will not validate with W3C if that is your goal.
No you should not use a <div> inside of a <tr>. You could use it inside <td> where as the table is a properly nested table, although this may not be best practice. You can actually override display setting of a div or any element. You could actually make a <div>(which defaults to block) display as a table-cell and vice versa.
Let's say your table row has 5 columns in general and you want your div to occupy the full width of the table. The following should do the trick.
<tr>
<td colspan=5>
<div class="some-class">
<p>Hey</p>
</div>
</td>
</tr>
This will work in quirks mode, but the browser which is compatible with standard mode will not work depend upon your doctype.
Avoiding quirks mode is one of the keys to successfully producing cross-browser compatible web content
Some modern browsers have two rendering modes. Quirk mode renders an HTML document like older browsers used to do it, e.g. Netscape 4, Internet Explorer 4 and 5. Standard mode renders a page according to W3C recommendations. Depending on the document type declaration present in the HTML document, the browser will switch into either quirk mode or standard mode. If there is no document type declaration present, the browser will switch into quirk mode.
http://www.w3.org/TR/REC-html32#dtd
JavaScript should not behave differently; however, the DOM objects that JavaScript operates on may have different behaviors.

Why doesn't Google close td and tr tags in tables?

Looking at HTML source code of
http://www.google.com/finance/historical?cid=983582&startdate=Nov+28,+2000&enddate=Nov+27,+2010&num=200
I see that Google never closes td and tr tags. There is no </tr> no </td> in the source.
Why?
<tr class=bb>
<th class="bb lm">Date
<th class="rgt bb">Open
<th class="rgt bb">High
<th class="rgt bb">Low
<th class="rgt bb">Close
<th class="rgt bb rm">Volume
<tr>
<td class="lm">Nov 26, 2010
<td class="rgt">11,183.50
<td class="rgt">11,183.50
<td class="rgt">11,067.17
<td class="rgt">11,092.00
<td class="rgt rm">68,396,121
<tr>
Is it to make it harder to parse it because XML parser won't be able to read it ? I have remarked that &output=csv is not available for indices (this url won't work: http://www.google.com/finance?q=INDEXDJX:.DJI&output=csv) whereas it is available for stock (http://www.google.com/finance/historical?q=NASDAQ:GOOG&output=csv will work) so that to get historical data in csv for indices you have to do the parsing job !
This is HTML4 (and not XML). As pointed out in the W3 specs:
11.2.6 Table cells: The TH and TD elements
…
Start tag: required, End tag: optional
Ditto for tr:
11.2.5 Table rows: The TR element
…
Start tag: required, End tag: optional
I believe the intent is to minimize page size by omitting the end tags. They do various additional optimizations which may actually result in invalid HTML, but are handled by browsers in tagsoup mode.
They do this to save bandwidth. Each byte that comes across the wire is thousands of dollars in Google's book, so why waste extra bytes of data on making readable code. However, they've become less concerned with bandwidth over the past couple years as they've increased their server capacity to God-like proportions, hence the larger logo files (for example, their old logo here is a roughly 8.5kb gif file that looks like crap, and their current one is a 25+kb PNG), so I suspect they'll eventually come up with a more standards compliant and cleaner home page.

Is it safe to omit </TD> and </TR> tags?

According to w3c </TD> and </TR> tags are optional, so the following table is perfectly valid.
<table>
<tr>
<td>google
<td>chrome
</table>
And all browsers I've tested it with render the table fine. I just wanted to ask if this is generally considered safe to use, or if older browsers, which I don't have access to, cause problems. Thanks.
It reduces gzip html size on a page with many tables by a few percent.
This is valid HTML but invalid XHTML.
There's nothing intrinsically wrong with it.
If you look at the source for Google's privacy policy (or any of their other pages), you'll find some much terser HTML.
It does mean that your page will not be usable by an XML parser.
It is safe, since optionality in the standard means that all the browsers (at least the ones which even remotely matter) would have implemented this - and the browser standards compliance usually runs to the opposite side, into trying to work correctly with even invalid HTML as opposed to failing on missing optional tags.
Having said that, I find that omitting such tags makes things harder to read, which may or may not matter to you if the goal is size optimization.
P.S. Also, if you have very large tables, I wonder whether there's any overhead incurred by the browser's HTML parser when dealing with such constructs? I am not sure without benchmarking or really deep thinking about how HTML parser works in detail, but it is something that could possibly be a factor if it happens.
I strongly recommend against doing that, though it is valid in HTML4 (and 5). The bandwidth savings are miniscule when compared to the technical debt you are incurring. Also keep in mind it is not valid in XHTML, so be sure your doctype is set appropriately.
There have been optional tags in HTML since the very beginning — they are a feature inherited from SGML, and so the early browsers must have been able to deal with them. While XHTML moved away from this and required a much more uniform syntax, this doesn’t affect you unless you explicitly tell the browser to parse in XML mode. I’ve never seen a problem when using the standard parsers of HTML 4/5.
Since HTML5 so carefully describes when certain tags are optional, I would read that to imply that someone did lots of testing to make sure that in these cases, most browsers produce the same document tree.
And while the space savings are negligible, I find that leaving off the closing tags of <p>, <li>, <td>, and <tr> simply makes my life easier when I’m working in the markup, and makes me less likely to make an error.
Personally I don't consider it good practice. Looking at the spec it didn't give a whole lot of information. I know it's required for XHTML so I looked up the HTML 5 spec. HTML 5 seems to take the same take on it as HTML 4 which is what you've linked to, but gives a little more information:
A td element's end tag may be omitted if the td element is immediately followed by a td or th element, or if there is no more content in the parent element.
I advise always closing your tags. There's not really too good of a reason not to. Browsers can handle some improperly closed tags, but just to be on the safe side (and it's good programming practice!), close your tags!
Close all tags in HTML for a few reasons:
Not closing tags is tolerated, but it is not correct modern XHTML. It's deprecated much in the same way that HTML style attributes are in favor of CSS
It's more readable for the next guy if you close the tags
Browsers will actually have an easier time parsing your source if it more strictly adheres to the rules, even if that makes the source longer
Certainly if you are using only HTML there is absolutly no problem thats not the case with XHTML nevertheless i don't think you can get that much, also i suggest dont abuse tables remember div are better than tables
It’s Ok with Static Pages not for Dynamic Pages …to debug
You should close your <TR> and <TD>tags if possible, but NOT ALWAYS because in some scenarios it may disturb you. This is because the <TR> and <TD>tags could be styled to display:none while the </TR> tag couldn't. It means that a scenario in which you want to extend / limit your display with media queries, will fail if you use </TR>. Consider the following code:
<style>
#media (max-width : 480px) {
.hidden-class {display:none;}
}
</style>
<table>
<tr>
<td>cell 1</td>
</tr class="hidden-class"> <!-- this will fail! -->
<tr class="hidden-class">
<td>cell 2</td>
</tr> <!-- this could stay -->
</table>
It means that you would write it as:
<table>
<tr>
<td>cell 1</td>
</tr> <!-- this will now close the TR for every screen width, which will destroy your extenstion -->
<tr class="hidden-class">
<td>cell 2</td>
</tr> <!-- this could stay -->
</table>
Which means that the only way to do so is by OMITTING THE in the first place:
<table>
<tr>
<td>cell 1</td>
<tr class="hidden-class">
<td>cell 2</td>
</tr> <!-- this could stay -->
</table>