HTML tables have already come since long at the time of web. It may be surprising that some web designers have never worked with this element. In this article, our best graphics designers will discuss what you need to know about tables. We’ll start with basic syntax and semantics. Then, we will attempt to respond to our tables. So, let’s begin with this article in points of interest.
Basic HTML Table
Which are the essential elements in each HTML table? You need a table, i.e. tr and td elements. Well, these are the elements that define the table. Next, tr allows you to define a row within a table. Finally, td defines a cell in the row, so the table element at the top level will be inside. There will be one or more tries and, within it, there will be one or more tds. Simply, you need at least markup to create this a substantial table.
Tables and Semantics
We all know that the web is increasingly turning into meaningful, not only about what you say but also how you can say. In other words, td is not the only one for the browser. Make sure, you can use some CSS to keep these two elements in style so that they look similar. However, the browser still realizes that these two elements are distinctive, semantic. It resembles h1 and p.
You can think about th as a similar for h1 or other heading and tr as a similar for p. Just like th, h1 adds more significance and weight, if you want, to the text. td is mainly a plain data for the table. This is why it is bold by default – it is more important You should always fill the rows (tr) with the same number of cells (td) or use colspan attribute with a specific number. Otherwise, the layout of the table won’t seem as though you need.
Grouping Table
You can divide the table in thead, tbody and tfoot. These are only “tools” you can use to aggregate the content of the table in the more meaningful way and reduce potential mess. You can keep these table elements as head, body and footer. If you have decided to use these elements, there are things you ought to remember.
All above three elements have two things in common. First is, they can not be vacant. If you decide to use any of these elements, must have at least one row (tr). Otherwise, the table will not be valid. In addition, in these components, the same number of the header (th) or data (td) table should be part of the table of cells. Or, you can already use the colspan feature from the above.
The second thing is that these elements are normal, none of them will affect the layout of the table. As we have discussed, when you use td the browser will render the text as bold. As long as you do not reset CSS stylesheet or other custom styles to override the default style or normalize, the reset stylesheet will look like td. Generic CSS will keep th bold. The same thing is true for thead, tbody and tfoot. None of them will change in the table in the browser.
The Head, Body and Foot
It’s more plausible that you’ll use thead and tbody, let’s talk about this first. The tbody element is the choice of grouping the “standard” content of the table, Meaning, you can take all the rows (tr) with tds and put them inside the tbody. If you don’t do anything, it will, however, be a substantial table. Like some text, HTML tables don’t need to be either heading or thead / th. It can be just the metaphorical pile of rows (tr) and cells (td).
Coming on the next list it is thead. Likewise to its kin, it’s also composed of one or more rows (tr). And, these rows can also contain standard table cells (td), with table headings (th). You can use both types of cells, th, and td, and your table will be perfectly valid. You want to use thead to add headings to columns. In that case, th makes more sense.
Otherwise, you could as well ditch the thead completely and put everything in the tbody. Or, you can ditch both, thead and tbody. If you want you can put td elements inside thead. One thing to remember is that the thead element should be prior to any tbody or thead element.
The last element you can use in HTML tables is tfoot. It should have at least one table row (tr) with at least one table cell (td). No, unfortunately, there is no special table cell, such as “tf”, dedicated only to tfoot. The question is when to use this element? It is a good option if you need to demonstrate some synopsis for every section of the table.
Responsive HTML Table
The fastest and most commonly used solution is manageable. Instead of breaking the table with dozens of CSS lines somehow, you can wrap it inside a div. Then, you add two lines of CSS, set the “auto” to overflow-x (horizontal) on the first line and set the maximum width to “100%” on the second line. Table Wrapper will never overlap. At any time it will be narrower than the table, the horizontal scrollbar will appear. It will not let it overlap the table.
Let’s go through another possible solution for creating HTML table responsive. You can use CSS to hide specific columns to ensure that it matches the table layout. Here are some “unnecessary” columns in your table that you can hide. You have two options. First, you can use the previous scroll-based solution.
The second option is first you will wrap the table inside a div with a small CSS twitch. Next, you’ll hide some columns. Finally, you can add some buttons so that the user can “toggle” those columns. As a result, when the screen becomes too narrow, the table becomes smaller by hiding some columns. The scrollbar will not appear, as long as the user does not click the button. From that point forward, the columns will appear and the table will scroll. Responsive website designers offer services to make your website compatible in such a way that they respond to the users devices, platforms and screen size.
Think Closed On HTML Tables
For this article, we have discussed essential things that are related to HTML tables, which are mythological stories from basic syntax, semantics and responsive design. However, hope that this article gives you content that you need to start creating legitimate tables. Last words? Well, two. First, the tables are valid. Secondly, do not use HTML tables for layout, it’s only utilized for data.