Table vs Tableless
To table or not to table? That’s the Question.
Whether or not to use tables on a web page depends on your goal when representing certain data.
Once upon a time the tag <table>
As has already been mentioned in other responses, there was a time when most layouts websites were made using tables.
For example, they were common in the most commonly used IDE’s, like Dreamweaver, to have a Wizard to create website layouts. See the example below:
So it was common to start a site thinking about how many rows or columns it would be divided so that we could fit all the elements together. The great advantage of doing layouts like this is that it is logical and intuitive.
However, there are many limitations in table layouts.
- Headache when an element needs to override the layout, such as a list submenu.
- Adapt the layout to mobile devices.
- Time-consuming rendering as the browser needs to read the table to the end to show it correctly.
- Messy code, usually with tables inside tables inside tables inside tables inside tables...
And so on and so on...
Then appeared div
s and span
s
To remedy these limitations, many webdesigners have started to implement layouts with generic blocks div
and span
combined with CSS style manipulation techniques to generate more flexible and responsive layouts.
With the advent of HTML5, new tags were added to make coding even easier by adding semantics to certain page elements. Some are: header
, footer
, section
and aside
. They are exemplified in the example below.
Unlike a normal table, where each cell must obey the patterns of table positioning the blocks are more independent. Each block can be positioned independently, but relative to the other blocks.
See the example below:
That looks like the same thing as a table, but ends with the limitations mentioned above.
In HTML code, the layout might look something like this:
<body>
<header>
Meu cabeçalho
</header>
<aside class="esquerda">
Menu à esquerda
</aside>
<aside class="direita">
Menu à direita
</aside>
<section id="content">
Conteúdo da página.
</section>
<footer>
Meu rodapé
</footer>
</body>
So the advantages:
- More freedom when positioning elements, because it is not necessary to follow exactly the grid of a table.
- On small screens, for example on mobile phones, the elements can be arranged a completely different positions of a large screen using media queries of the CSS.
- The browser can require each tag as soon as it receives the content from the browser, so if your page is composed of lots of data they will be displayed slowly and not all at once after a long initial delay.
- You can split the code into different sections and not all within a single table. Using dynamic languages such as PHP, JSP, ASP allows you to split the code into several files more efficiently and avoid breaking the layout if some content larger than expected is written on the page.
Of course, not everything is flowers. At first, create a layout 100% tableless was a big headache. The most complicated was creating a code that worked the same in all browsers.
However, with the advancement of CSS standardization, the evolution of the various browsers and the consolidation of HTML and CSS coding standards, today it is much easier to do this if you don’t want to reinvent the wheel.
Thousands and thousands of websites on the internet provide an example of how to do this and there are libraries like Foundation and Bootstrap that allow you to reuse styles already ready to create your site.
When to use tables or not
If you have data that is actually tabular, as in the case of representing data from a database, where it is important that columns need to always be aligned, then tables are the most ideal solution.
On the other hand, imagine a photo gallery. On a larger monitor you may want to display 4 photos per line, but when decreasing the table size, you can display 3, 2 or even 1 photos, for example on smartphones. Tables just don’t work here.
Don’t stop here
A tip to better understand how this works is to go to the Bootstrap page and see how it works Grid System. On the same page, there is a example of table usage.
Understanding how the two systems work will be easier to decide when to use one and the other.
The issue of tableless is more in relation to layout page. If you are going to look at the source code of websites that use
table
, you will see that the site is a great table, where the header, body and footer aretr
and each column is onetd
. Now, for data display, I see no problem– Lucas
@Lucas actually created tables to be used in tabular data, so it is not the case of "no problem" but rather that the correct is to be used.
– Marciano.Andrade
The only problem with tables are mobile devices. If the site is not responsive, it’s okay to use tables. Even so, there are ways to make tables responsive. http://bootsnipp.com/snippets/featured/no-more-tables-respsonsive-table http://getbootstrap.com/css/#tables
– Thiago Custodio
The question is nothing subjective. Whether or not to use tables depends on the problem. For tabular data, tables are better. For responsive lists, tableless is the only option. And although both are used for website layout, the tables present a serious disadvantage. It’s not because you can do more in a way that’s based on opinions.
– utluiz