Is it ok to have a tbody tag with no rows in it and do the browsers add it after if I add a row?

If I have a table with no content but just a header row, is it ok that I have a tbody tag? For example, if I have:

       <thead><tr><th>Heading</th><th>Heading 2</th></tr></thead>


       <thead><tr><th>Heading</th><th>Heading 2</th></tr></thead>

are either of these considered improper html?

I want to apply tbody formatting through CSS so in the second example above if I go add a new row, do I need to add "TBODY" or will the browser automatically add it in?


According to the W3C Validator both of your snippets are valid HTML.

I would argue that semantically it makes more sense to include a <tbody> element, regardless of whether it has content or not.

Regarding your assumption that browsers insert a <tbody> by default, you can't be certain that they all do and if they may or may not in the future. If you have logic depending on the <tbody> element you should definitely include it in your markup to eliminate a potential bug here.

Need Your Help

Tree with 2 parents: build a family tree HTML/javascript as familyecho do

html family-tree

I want to display a genealogy tree without flash. In HTML/javascript/css.