Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Tables HTML Tables

Creating a <table> with a header tag...

Just wanting to know what I am missing with this code:

<table>
  <th>table heading</th>
</table>

I tried with and without the <tr></tr> but I am sure it's just vocabulary and I am missing something. Can you tell me what's wrong with this code?

3 Answers

christopher smith
christopher smith
5,831 Points

You're missing your tr tags :)

<table>
   <tr>
      <th>Table Head</th>
   </tr>
</table>
Saulius K
PLUS
Saulius K
Courses Plus Student 15,928 Points

It's not essential, but it's also good practice to add a thead to contain the tr and th tags.

So something like this:

        <table>
          <thead>
           <tr>
              <th>Column one head</th>
              <th>Column two head</th>
           </tr>
        </thead>
        </table>

And then use a tbody tag later, to keep the body rows and cells in.

So something like this:

        <table>
          <thead>
           <tr>
              <th>Column one head</th>
              <th>Column two head</th>
           </tr>
        </thead>
        <tbody>
           <tr>
              <td>Column one body cell</td>
              <td>Column two body cell</td>
           </tr>
        </tbody>
        </table>

It's not essential, but it's good practice, really simple and a great habit to get into.

Hope that helps.

Thank you, Christopher!