Almost embarrassed to ask, because I have never had a need to use tables much before...
Now I have a project that will require massive organized tables, go figure.
Suppose I have a table like this:
<table border="1px" style="width:300px">
Your HTML markup is fine, except you should favor CSS classes rather than inline styles, and the
border attribute is usually better as a style.
If you are ever curious if you have valid markup, you can use a validator tool to check. There is one available here, provided by W3C: http://validator.w3.org/
HTML is a presentational markup. There is no data association implicit in any given element -- that is to say, the
td which you know contains the first name does not in any way associate itself with the heading which labels it visually. As far as HTML is concerned, you don't have data, just a bunch of words which it shapes and boxes and moves around on the screen.
That said, sorting tables are a very common UI pattern, and you can find a large number of examples as well as existing plugins. I highly recommend that you consider an established plugin if you are going to use this for anything other than a learning experience. The plugin author has, presumably, already considered all the many ins and outs, gotchyas, and cross-browser considerations that you would have to take in to account if you tried to craft your own.
<table>element - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table