<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="https://stackoverflow.com/questions/83073/why-not-use-tables-for-layout-in-html">Why not use tables for layout in HTML?</a>  </p>
</blockquote>



<p>Under what conditions should you choose tables instead of DIVs in HTML coding?</p>

[{'answer_id': 30255, 'author': 'Thomas Owens', 'author_id': 572, 'author_profile': 'https://Stackoverflow.com/users/572', 'pm_score': 1, 'selected': False, 'text': '<p>I believe just tabular content. For example, if you printed out a database table or spreadsheet-like data to HTML.</p>\n'}, {'answer_id': 30259, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>I will usually opt for tables to display form-type information (First Name, Last Name, Address, etc.) where lining labels and fields across multiple rows is important. DIVs I use for layout.</p>\n\n<p>Of course the table is wrapped in a DIV :)</p>\n'}, {'answer_id': 30262, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 6, 'selected': False, 'text': "<p>When the data I am presenting is, indeed, tabular. </p>\n\n<p>I find it ridiculous that some web designers used divs on tabular data on some sites.</p>\n\n<p>One other use I would have for it would be forms, particularly label : textbox pairs. This could technically be done in div boxes, but it's much, much easier to do this in tables, and one can argue that label:textbox pairs are in fact tabular in nature.</p>\n"}, {'answer_id': 30263, 'author': 'Jorge Córdoba', 'author_id': 2695, 'author_profile': 'https://Stackoverflow.com/users/2695', 'pm_score': 4, 'selected': False, 'text': "<p>Usually whenever you're not using the table to provide a layout.</p>\n\n<p>Tables -> data</p>\n\n<p>Divs -> layout</p>\n\n<p>(mainly)</p>\n"}, {'answer_id': 30264, 'author': 'Peter Stuifzand', 'author_id': 1633, 'author_profile': 'https://Stackoverflow.com/users/1633', 'pm_score': 1, 'selected': False, 'text': '<p>If you would like to have semantically correct HTML, then you should use tables only for tabular data. </p>\n\n<p>Otherwise you use tables for everything you want, but there probably is a way to do the same thing using <code>div</code>s and CSS.</p>\n'}, {'answer_id': 30265, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 2, 'selected': False, 'text': "<p>Tables were designed for tabular content, not for layout.</p>\n\n<p>So, don't ever feel bad if you use them to display data.</p>\n"}, {'answer_id': 30266, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 2, 'selected': False, 'text': "<p>1) For displaying tabular data.  A calendar is one example of tabular data that isn't always obvious at first.</p>\n\n<p>2) I work for a medical billing company, and nearly all of the layout for our internal work is done using CSS.  However, from time to time we get paper forms from insurance companies that our billers have to use, and a program will convert them to an html format that they can fill out and print via the intranet.  To make sure the forms are accepted they need to match the original paper version very closely.  For these it's just simple to fall back to tables.</p>\n"}, {'answer_id': 30269, 'author': 'PJ.', 'author_id': 3230, 'author_profile': 'https://Stackoverflow.com/users/3230', 'pm_score': 3, 'selected': False, 'text': "<p>Agree with Thomas -- the general rule of thumb is if it makes sense on a spreedsheet, you can use a table.  Otherwise not.  </p>\n\n<p>Just don't use tables as your layout for the page, that's the main problem people have with them.</p>\n"}, {'answer_id': 30271, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 9, 'selected': True, 'text': '<p>The whole "Tables vs Divs" thing just barely misses the mark.  It\'s not "table" or "div".  It\'s about using semantic html.</p>\n\n<p>Even the div tag plays only a small part in a well laid out page.  Don\'t overuse it.  You shouldn\'t need that many if you put your html together correctly.  Things like lists, field sets, legends, labels, paragraphs, etc can replace much of what a div or span is often used to accomplish.  Div should be used primarily when it makes sense to indicate a logical <b>div</b>ision, and only appropriated for extra layout when absolutely necessary.  The same is true for table; use it when you have tabular data, but not otherwise.</p>\n\n<p>Then you have a more semantic page and you don\'t need quite as many classes defined in your CSS; you can target the tags directly instead.  Possibly most importantly, you have a page that will score much better with Google (anecdotally) than the equivalent table or div-heavy page. Most of all it will help you better connect with a portion of your audience.</p>\n\n<p>So if we go back and look at it in terms of table vs div, it\'s my opinion that we\'ve actually come to the point where div is over-used and table is under-used.  Why? Because when you really think about it, there are a lot of things out there that fall into the category of "tabular data" that tend to be overlooked.  Answers and comments on this very web page, for example.  They consist of multiple records, each with the same set of fields. They\'re even stored in a sql server table, for crying out loud. This is the exact definition of tabular data. This means an html table tag would absolutely be a good semantic choice to layout something like the posts here on Stack Overflow. The same principle applies to many other things as well. It may not be a good idea to use a table tag to set up a three column layout, but it\'s certainly just fine to use it for grids and lists... except, of course, when you can actually use the ol or ul (list) tags.</p>\n'}, {'answer_id': 30274, 'author': 'Pat', 'author_id': 238, 'author_profile': 'https://Stackoverflow.com/users/238', 'pm_score': 4, 'selected': False, 'text': '<p>As many posters have already mentioned, you should use tables to display for tabular data.</p>\n\n<p>Tables were introduced in <a href="http://www.w3.org/TR/REC-html32.html#body" rel="noreferrer">HTML 3.2</a> here is the relevant paragraph from the spec on their usage:</p>\n\n<blockquote>\n  <p>[tables] can be used to markup tabular material or for layout purposes...</p>\n</blockquote>\n'}, {'answer_id': 30317, 'author': '17 of 26', 'author_id': 2284, 'author_profile': 'https://Stackoverflow.com/users/2284', 'pm_score': 2, 'selected': False, 'text': '<p>I use tables in two cases:</p>\n\n<p>1) Tabular data</p>\n\n<p>2) Any time I want my layout to dynamically size itself to its contents</p>\n'}, {'answer_id': 30595, 'author': 'Sören Kuklau', 'author_id': 1600, 'author_profile': 'https://Stackoverflow.com/users/1600', 'pm_score': 2, 'selected': False, 'text': "<p>If your data can be laid out in a two-dimensional grid, use <code>&lt;table&gt;</code>. If it can't, don't. Using <code>&lt;table&gt;</code> for anything else is a hack (though frequently not one with proper alternatives, especially when it comes to compatibility with older browsers). <em>Not</em> using <code>&lt;table&gt;</code> <em>for</em> something that clearly should be one is equally bad. <code>&lt;div&gt;</code> and <code>&lt;span&gt;</code> aren't for everything; in fact, being completely meaningless on a semantic level, they are to be avoided at all costs in favor of more semantic alternatives.</p>\n"}, {'answer_id': 42275, 'author': 'CarmineSantini', 'author_id': 2166, 'author_profile': 'https://Stackoverflow.com/users/2166', 'pm_score': 0, 'selected': False, 'text': "<blockquote>\n  <p>One other use I would have for it\n  would be forms, particularly label :\n  textbox pairs. This could technically\n  be done in div boxes, but it's much,\n  much easier to do this in tables, and\n  one can argue that label:textbox pairs\n  are in fact tabular in nature.</p>\n</blockquote>\n\n<p>I see that  a fair amount, especially among MS developers.  And I've done it a fair amount in the past.  It works, but it ignores some accessibility and best-practice factors.  You should use labels, inputs, fieldsets, legends, and CSS to layout your forms.  Why?  Because that's what they are for, it's more efficient, and I think accessibility is important.  But that's just my personal preference.  I think everyone should try it that way first before condemning it.  It's quick, easy, and clean.  </p>\n"}, {'answer_id': 42329, 'author': 'Ross', 'author_id': 2025, 'author_profile': 'https://Stackoverflow.com/users/2025', 'pm_score': 1, 'selected': False, 'text': "<p>@Marius:</p>\n\n<p>Is the layout tabular data? No, while it was standard a few years ago it's not now :-)</p>\n\n<blockquote>\n  <p>One other use I would have for it would be forms, particularly label : textbox pairs. This could technically be done in div boxes, but it's much, much easier to do this in tables, and one can argue that label:textbox pairs are in fact tabular in nature.</p>\n</blockquote>\n\n<p>I tend to give the label a fixed width, or display it on the line above.</p>\n"}, {'answer_id': 42374, 'author': 'Radu094', 'author_id': 3263, 'author_profile': 'https://Stackoverflow.com/users/3263', 'pm_score': 4, 'selected': False, 'text': '<p>I would make a distinction between HTML for public websites (tables no-no-no, divs yes-yes-yes) and HTML for semi-public or private web applications, where I tend to prefer tables even for page layout.</p>\n\n<p>Most of the respectable reasons why "Tables are bad" are usually an issue only for public websites, but not so much of a problem with webapps. If I can get the same layout and have a more consistent look across browsers by using a TABLE than a complicated CSS+DIV, then I usually go ahead and aprove the TABLE.</p>\n'}, {'answer_id': 46289, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 3, 'selected': False, 'text': '<p>I can see the argument for tables for forms, but there is a nicer alternative... you just have to roll up your sleeves and learn CSS.</p>\n\n<p>for example:</p>\n\n<pre class="lang-html prettyprint-override"><code>&lt;fieldset&gt;\n  &lt;legend&gt;New Blog Post&lt;/legend&gt;\n\n  &lt;label for="title"&gt;Title:&lt;/label&gt;\n  &lt;input type="text" name="title" /&gt;\n\n  &lt;label for="body"&gt;Body:&lt;/label&gt;\n  &lt;textarea name="body" rows="6" cols="40"&gt;\n  &lt;/textarea&gt;\n&lt;/fieldset&gt;\n</code></pre>\n\n<p>You can take that html and layout the form either side-by-side labels, or labels on top of the textboxes (which is easier).  Having the flexibility really helps.  It\'s also less HTML than the table equivalent of either.</p>\n\n<p>For some excellent examples of CSS forms, check out these excellent examples:</p>\n\n<p><a href="http://jeffhowden.com/code/css/forms/" rel="nofollow noreferrer">http://jeffhowden.com/code/css/forms/</a></p>\n\n<p><a href="http://www.sitepoint.com/article/fancy-form-design-css/" rel="nofollow noreferrer">http://www.sitepoint.com/article/fancy-form-design-css/</a></p>\n\n<p><a href="http://www.smashingmagazine.com/2006/11/11/css-based-forms-modern-solutions/" rel="nofollow noreferrer">http://www.smashingmagazine.com/2006/11/11/css-based-forms-modern-solutions/</a></p>\n'}, {'answer_id': 46307, 'author': 'Slartibartfast', 'author_id': 4433, 'author_profile': 'https://Stackoverflow.com/users/4433', 'pm_score': 1, 'selected': False, 'text': '<p>@Jon Limjap</p>\n\n<p>For  label : textbox, neither divs nor tables are appropriate: <code>&lt;dl&gt;</code>s are </p>\n'}, {'answer_id': 51237, 'author': 'Matthew M. Osborn', 'author_id': 5235, 'author_profile': 'https://Stackoverflow.com/users/5235', 'pm_score': 2, 'selected': False, 'text': '<p>Tables are used for tabular data. If it makes sense to put it in a spreadsheet then use a table.  Otherwise there is a better tag for you to be using such as div, span, ul, etc.</p>\n'}, {'answer_id': 67249, 'author': 'JacquesB', 'author_id': 7488, 'author_profile': 'https://Stackoverflow.com/users/7488', 'pm_score': 4, 'selected': False, 'text': '<p><em>Note: At the time the question was asked, there were practical reasons for using tables for some layout purposes. This is not necessary anymore due to browser improvements, so I have updated the answer.</em> </p>\n\n<p>HTML <code>&lt;table&gt;</code>-elements should be used when the data logically has a two dimensional structure. If the data can be structured in rows and columns and you can meaningfully apply headers to both rows and columns, then you probably have tabular data. </p>\n\n<p>I you only have a single row or single column of data, then it is not tabular data - it is just linear content. You need at least two rows and two columns before it can be considered tabular data.</p>\n\n<p>Some examples:</p>\n\n<p>Using tables for placing sidebars and page headers/footers. This is not tabular data but page layout. Something like css grid or flexbox is more appropriate.</p>\n\n<p>Using tables for newspaper-style columns. This is not tabular data - you would still read it linearly. Something like css columns is more appropriate. </p>\n'}, {'answer_id': 492938, 'author': 'netrox', 'author_id': 47301, 'author_profile': 'https://Stackoverflow.com/users/47301', 'pm_score': 5, 'selected': False, 'text': '<p>I used to do pure CSS but I abandoned that pursuit in favor of hybrid table/css approach as the most pragmatic approach. Ironically, it\'s also because of accessibility. Ever try doing CSS on Sidekick? What a nightmare! Ever seen how CSS-based websites are rendered on new browsers? Elements would overlap or just don\'t display correctly that I had to turn off the CSS. Ever try resizing CSS-based websites? They look awful and often detrimental to the blind if they use zooming features in the browser! If you do that with tables, they scale much better. When people talk about accessibility, I find that many have no clue and it annoys me because I am disabled and they aren\'t. Have they really worked with the blind? The deaf? If accessibility is a main concern, why the hell are 99% of videos not closed captioned? Many CSS purists use AJAX but fail to realize that AJAX often makes content inaccessible. </p>\n\n<p>Pragmatically, it\'s ok to use a single table as a main layout as LONG as you provide the information in a logical flow if the cells are stacked (something you\'d see on mobiles). The CSS theory sounds great but <em>partially</em> workable in real life with too many hacks, something that is against the ideals of "purity." </p>\n\n<p>Since using the CSS with tables approach, I\'ve saved so much time designing a website and maintanance is much easier. Fewer hacks, more intuitive. I get fewer calls from people saying "I inserted a DIV and now it looks all screwed up!" And even more importantly, absolutely NO accessibility issues. </p>\n'}, {'answer_id': 493648, 'author': 'codemonkey', 'author_id': 56800, 'author_profile': 'https://Stackoverflow.com/users/56800', 'pm_score': 2, 'selected': False, 'text': '<p>On this subject, I thought <a href="http://shouldiusetablesforlayout.com/" rel="nofollow noreferrer">this</a> site was pretty funny.</p>\n'}, {'answer_id': 975878, 'author': 'Biranchi', 'author_id': 97651, 'author_profile': 'https://Stackoverflow.com/users/97651', 'pm_score': 0, 'selected': False, 'text': '<p>When ever a page containg tables is loaded by any browser it takes more time for the browser to render properly the  tag. Where as if the div is used ,the browser takes less time as it is lighter. And more over we can apply the css to make the divs appear as table,</p>\n\n<p>The tables are normally heavy wieght and div are light weight.</p>\n'}, {'answer_id': 2801955, 'author': 'Guy W', 'author_id': 337157, 'author_profile': 'https://Stackoverflow.com/users/337157', 'pm_score': 0, 'selected': False, 'text': "<p>Divs are simple <code>divisions</code>, they are mean't to be used to group sections of the page that are in a semantic sense linked. They carry no implicit meaning other than that.</p>\n\n<p>Tables were originally intended to display scientific data, such as lab results on screen. Dave Raggett certainly didn't intend them to become used to implement layout.</p>\n\n<p>I find it keeps it fairly clear in your mind if you remember the above, if its something you would normally expect to read in a table, then that's the appropriate tag, if its pure layout, then use something else to accomplish your needs.</p>\n"}, {'answer_id': 3153153, 'author': 'Amirouche Douda', 'author_id': 321714, 'author_profile': 'https://Stackoverflow.com/users/321714', 'pm_score': 0, 'selected': False, 'text': '<p>It is clear that the DIV are used for Layout but It happened to me to being "forced" to use spreadsheets to do a grid layout within a div structure for this reasons:</p>\n\n<blockquote>\n  <p>the addition of percentage values did not allow a proper alignment with the div, while the same values expressed on cells of tables gave the expected result.</p>\n</blockquote>\n\n<p>So I think that tables are still useful not only for data, but also for the situation above, on top of that, tables are still W3C compliant browser and alternative browsers (for the disabled for example) interpret theirs correctly.</p>\n'}]
['https://Stackoverflow.com/questions/30251', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2141/']