I can make the make the th the width of a set number of td with colspan, but how do I make it the full width os the table if I don’t know how many td there will be. The content will be dynamically generatored.
So spell out what SamA74 says, if it is going to be dynamically generated, then it should be created by JavaScript and not hard-coded into HTML. So the JS to create the th will be dependent on the JS used to create the td. Have a counter for the td and apply it to the th. You can learn to use document.createElement for td as part of your dynamic generation, unless you already have another way figured out.
Remember that a table represents tabular data, and tabuar data is relational, that is any given cell relates to other cells , in its row or column. If your table heading encompasses ALL individual columns , it most logically refers to the table as a whole and not any ONE column. For that reason you would be better served by an Hx tag (or a caption , as Sam74 suggested)
After that, You can use CSS to style the element to look however you want.
Then as others have suggested you should dynamically generate the colspan server-side at the same time as you add the cells.
It is quite common to span a header across cells when the data rows have their own th at the left side so a caption is not always the right option. There are examples of that approach here and colspans will be necessary.
My take on this was that the OP wanted the TH to span ALL columns( e.g.: a 5 column table with a TH with colspan=5 )
Essentially it’s saying ALL cells in the table can be categorized under that “heading”, which to me seems like redundant.
Let’s say you have a table denoting cars by make and model:
the “brand” is a common denominator to all cells.I would figure that while it can remain as a TH, it would make even more sense as heading to the table itself . I mean you wont ad another TH above the “brand” saying “cars”. So it doesn’t seem too far fetched to take that info out of the table and placing it into a header <h4>Cars by Make</h4>
IMHO, of course