Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is it more appropriate to use DIV instead of TABLE, and vice-versa?

I've noticed a variation of convention when it comes to using DIV tags instead of TABLE to separate/organize content on a web-page. In what situation is one more appropriate to use than the other?

Clarification: This question is both general, and specific in that I'm mainly looking for which would be more ideal for page layout.

like image 621
Jengerer Avatar asked Oct 20 '10 20:10

Jengerer


People also ask

Why should we use div instead of table?

Using div is better than using table because of easy control of the in the design and it can be container for controls than table and the table is mainlt used to group data with simillar structure so it's design is for this task but div is considered as container mainly than table.

Should I use div or table?

Tables should only be used to display data in a tabular way. For layout and design it is best practise to use divs and stylesheets. Controlling the divs using stylesheets can take a while if you're not used to it, but it's quite easy to pick up.

Why do we use div tag instead of table tag in HTML?

The Div is the most usable tag in web development because it helps us to separate out data in the web page and we can create a particular section for particular data or function in the web pages. It is used to the group of various tags of HTML so that sections can be created and style can be applied to them.

Which is better div or table by Performance?

Tables make layout possible, divs make it impossible. Tables make for readable, easy to understand code. Divs require loads of hackery and tricks not so easy to understand and even then the results are so so and full of unwanted behaviour.


2 Answers

As a rule of thumb — if every cell in a row has something in common, and every cell in a column has something in common, then you should use a table. If you don't have a thead with some th elements providing column headings, then there is a good chance you are doing something wrong. If you don't have multiple data rows and multiple data columns, then … ditto.

The choice is, however, not between a div and a table. Use the markup that has the semantics that best describes the content. There are plenty of elements in HTML: http://www.w3.org/TR/html4/index/elements.html

like image 148
Quentin Avatar answered Sep 27 '22 21:09

Quentin


Use tables only with semantically tabular data. Is each row other than the header representing the same "type" of "thing"? Does each column header have below it a set of items that are described accurately by the column header? If yes to both, then use a table. Avoid tables for styling whenever possible.

like image 37
bblack Avatar answered Sep 27 '22 19:09

bblack