<div> tag can not be used above <tr> tag. Instead you can use <tbody> tag to do your work. If you are planning to give id attribute to <div> tag and doing some processing, same purpose you can achieve through <tbody> tag. For further information visit this page

For example:

<table>
    <tbody class="green">
        <tr>
            <td>Data</td>
        </tr>
    </tbody>
    <tbody class="blue">
        <tr>
            <td>Data</td>
        </tr>
    </tbody>
</table>

secondly, you can put "div" tag inside "td" tag.

<table>
    <tr>
        <td>
            <div></div>
        </td>
    </tr>
</table>

Further questions are always welcome.

Answer from Aditya Ekbote on Stack Overflow
🌐
CSS-Tricks
css-tricks.com › using-divs-inside-tables
Using Divs Inside Tables | CSS-Tricks
July 2, 2015 - One important thing to remember when putting a div inside of a table is that the div needs to live inside of a particular table cell, meaning inside of a td or th element which is inside of a tr element.
Discussions

html - Why are people making tables with divs? - Software Engineering Stack Exchange
In fact, in practice modifying a layout is always hard, and it's almost never enough to just change the CSS, if you want to do something more serious than minor tweaks. You will need to understand and change HTML structure for serious design changes. And tables don't make the job any harder or easier than divs... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
March 30, 2015
How to put DIV between table rows? - HTML & CSS - SitePoint Forums | Web Development & Design Community
I have a table of a long list of information. If one row is clicked on I want to make that perticular one expand with extra stuff/elements without disrupting the display of the other elements: its hard to explain so I will try to explain it with the HTML below: EXPANDING UPON ROW 2 AT BLOCK LEVE... More on sitepoint.com
🌐 sitepoint.com
0
December 3, 2007
html - How create table only using <div> tag and CSS - Stack Overflow
Padding doesn't. And, while I haven't ... as Padding, in forcing and empty cell to be rendered properly. ... A bit OFF-TOPIC, but may help someone for a cleaner HTML... .common_table { display:table; border-collapse:collapse; border:1px solid grey; } .common_table DIV { display:table-row; ... More on stackoverflow.com
🌐 stackoverflow.com
How create table only using <div> tag and Css - HTML & CSS - SitePoint Forums | Web Development & Design Community
Tying to create a form without using tables for may layout I am using div’s & css’s I am uploading two files Line Up Page.html (5.7 KB) lineup2.php (4.5 KB) More on sitepoint.com
🌐 sitepoint.com
0
May 29, 2017
🌐
Divtable
divtable.com › generator
HTML Div Table Generator | 𝗗𝗜𝗩 𝗧𝗔𝗕𝗟𝗘.𝗖𝗢𝗠
Generate HTML Div table grids for websites in just a few easy steps. Set the options then select the desired size. Adjust the options in the interactive editors
🌐
Webmaster World
webmasterworld.com › html › 3867431.htm
Div inside table? - HTML forum at WebmasterWorld - WebmasterWorld
You can't put a div inside a table, but you can put a div inside a table td. I know that's what you meant.
🌐
Htmltable
htmltable.com › div-table
Div Table - Using Div Tags to Build HTML Tables
Besides the table styler CSS make sure to include the CSS code responsible for making the div tags behave like table elements, presented under a previous subheading. The tool below works similar to the original div table generator at DivTable.com. All you have to do is select the size of the table and grab the generated code. By default the generator works with table tags, you have to switch to <div> for to work with div tags. ... Loading sidebar... HTMLTable is using cookies to improve the user experience and to collect anonymous visitor analytics.
🌐
Dummies
dummies.com › article › technology › programming-web-design › css3 › using-the-div-tag-to-create-tables-142904
Using the Div Tag to Create Tables | dummies
July 3, 2025 - Here is the HTML for a table that contains a title, headings, and two rows of content. <div class="Table"> <div class="Title"> <p>This is a Table</p> </div> <div class="Heading"> <div class="Cell"> <p>Heading 1</p> </div> <div class="Cell"> <p>Heading 2</p> </div> <div class="Cell"> <p>Heading 3</p> </div> </div> <div class="Row"> <div class="Cell"> <p>Row 1 Column 1</p> </div> <div class="Cell"> <p>Row 1 Column 2</p> </div> <div class="Cell"> <p>Row 1 Column 3</p> </div> </div> <div class="Row"> <div class="Cell"> <p>Row 2 Column 1</p> </div> <div class="Cell"> <p>Row 2 Column 2</p> </div> <div class="Cell"> <p>Row 2 Column 3</p> </div> </div> </div>
Top answer
1 of 8
134

This is a common pattern for making responsive tables. Tabular data is tricky to display on mobiles since the page will either be zoomed in to read text, meaning tables go off the side of the page and the user has to scroll backwards and forwards to read the table, or the page will be zoomed out, usually meaning that the table is too small to be able to read.

Responsive tables change layout on smaller screens - sometimes some columns are hidden or columns are amalgamated, e.g. name and email address might be separate on large screens, but collapse down into one cell on small screens so the information is readable without having to scroll.

<div>s are used to create the tables instead of <table> tags for a couple of reasons. If <table> tags are used then you need to override the browser default styles and layout before adding your own code, so in this case <div> tags save on a lot of boilerplate CSS. Additionally, older versions of IE don't allow you to override default table styles, so using <div>s also smooths cross-browser development.

There's a pretty good overview of responsive tables on CSS-Tricks.

Edit: I should point out that I'm not advocating this pattern - it falls into the divitis trap and isn't semantic - but this is why you'll find tables made from divs.

2 of 8
160

The question is if the data is semantically a table (i.e. a set of data or units of information logically organized in two dimensions) or you just use the grid for visual layout, e.g. because you want a sidebar to expand or something like that.

If your information is semantically a table, you use a <table>-tag. If you just want a grid for layout purposes, you use some other appropriate html elements and use display:table in the style sheet.

When is data semantically a table? When the data is logically organized along two axes. If it makes sense with headers for the rows or columns, then you might have a semantic table. An example of something which is not semantically a table is presenting a text in columns like in a newspaper. This is not semantically a table, since you would still read it linearly, and no meaning would be lost if the presentation was removed.


OK, why not use <table> for everything rather than only for something that is semantically a table? Visually it is obviously the same (since the table element just have display:element in the default style sheet).

The difference is that the semantic information can help alternative user agents. For example a screen reader might allow you to navigate in two dimensions in the table, and read the headers for a cell for both axes if you forget where you are. This would just be confusing if the table was not semantically a table but just used for visual layout.

The <table> versus display:table discussion is just a case of the more general principle of using semantic markup. See for example: Why would one bother marking up properly and semantically? or Why is semantic markup given more weight for search engines?

In some places you might actually be legally required to use semantic markup for accessibility reasons, and in any case there is no reason to purposefully make your page less accessible.

Even if you don't care for disabled users, having presentation separate from content gives you benefits. E.g. your three column layout could be presented in a single columns on a mobile using an alternative stylesheet.

Find elsewhere
🌐
SitePoint
sitepoint.com › html & css
How to put DIV between table rows? - HTML & CSS - SitePoint Forums | Web Development & Design Community
December 3, 2007 - I have a table of a long list of information. If one row is clicked on I want to make that perticular one expand with extra stuff/elements without disrupting the display of the other elements: its hard to explain so I will try to explain it with the HTML below: EXPANDING UPON ROW 2 AT BLOCK LEVE...
Top answer
1 of 11
302
.div-table {
  display: table;         
  width: auto;         
  background-color: #eee;         
  border: 1px solid #666666;         
  border-spacing: 5px; /* cellspacing:poor IE support for  this */
}
.div-table-row {
  display: table-row;
  width: auto;
  clear: both;
}
.div-table-col {
  float: left; /* fix for  buggy browsers */
  display: table-column;         
  width: 200px;         
  background-color: #ccc;  
}

Runnable snippet:

.div-table {
  display: table;         
  width: auto;         
  background-color: #eee;         
  border: 1px solid #666666;         
  border-spacing: 5px; /* cellspacing:poor IE support for  this */
}
.div-table-row {
  display: table-row;
  width: auto;
  clear: both;
}
.div-table-col {
  float: left; /* fix for  buggy browsers */
  display: table-column;         
  width: 200px;         
  background-color: #ccc;  
}
<body>
  <form id="form1">
      <div class="div-table">
             <div class="div-table-row">
                <div class="div-table-col" align="center">Customer ID</div>
                <div  class="div-table-col">Customer Name</div>
                <div  class="div-table-col">Customer Address</div>
             </div>
            <div class="div-table-row">
                  <div class="div-table-col">001</div>
                <div class="div-table-col">002</div>
                <div class="div-table-col">003</div>
            </div>
            <div class="div-table-row">
                <div class="div-table-col">xxx</div>
                <div class="div-table-col">yyy</div>
                <div class="div-table-col">www</div>
           </div>
            <div class="div-table-row">
                <div class="div-table-col">ttt</div>
                <div class="div-table-col">uuu</div>
                <div class="div-table-col">Mkkk</div>
           </div>

      </div>
  </form>
</body>

2 of 11
93

divs shouldn't be used for tabular data. That is just as wrong as using tables for layout.
Use a <table>. Its easy, semantically correct, and you'll be done in 5 minutes.

🌐
HTML Cleaner
html-cleaner.com › features › replace-html-table-tags-with-divs
Replace HTML tables with divs - Html-cleaner.com
The old trend of building websites using HTML tables can't be used anymore. You have to use div tags and style them as required
🌐
WisdmLabs
wisdmlabs.com › home › wordpress tips & tricks › how to make responsive div tables using css without tag
How to Create Responsive Tables using CSS without 'table' Tag
December 31, 2025 - Styling the tables is a challenge too, and there isn’t much option. You might be thinking that we need a jQuery plugin or JavaScript plugin to solve this issue. But it is not so. You do not need to install any plugin or additional framework. You can simply do this using the HTML <div> tag and ...
🌐
Divtable
divtable.com
HTML Table Generators and Converters | Div Table
/* DivTable.com */ .divTable{ display: table; width: 100%; } .divTableRow { display: table-row; } .divTableHeading { background-color: #EEE; display: table-header-group; } .divTableCell, .divTableHead { border: 1px solid #999999; display: table-cell; padding: 3px 10px; } .divTableHeading { background-color: #EEE; display: table-header-group; font-weight: bold; } .divTableFoot { background-color: #EEE; display: table-footer-group; font-weight: bold; } .divTableBody { display: table-row-group; }
🌐
Medium
medium.com › geekculture › important-difference-between-standard-html-tables-and-div-tables-b6b094ec2c79
Important difference between standard HTML tables and div tables | by Marian C. | Geek Culture | Medium
September 23, 2021 - The table on the right has slightly longer HTML code because of additional class attributes on row divs. But classes on divs are not absolutely necessary. I could have styled all the divs using selectors based on the table root div. I assigned a specific class to the row divs mainly to simplify CSS selectors in the sample code.
🌐
SitePoint
sitepoint.com › html & css
How create table only using <div> tag and Css - HTML & CSS - SitePoint Forums | Web Development & Design Community
May 29, 2017 - Tying to create a form without using tables for may layout I am using div’s & css’s I am uploading two files Line Up Page.html (5.7 KB) lineup2.php (4.5 KB) <a class=“attachment” This is what I have so far I have upl…
🌐
Tutorial Republic
tutorialrepublic.com › html-tutorial › html-layout.php
HTML Table Vs Div Based Layouts - Tutorial Republic
Layouts created using tables often rendered very slowly. Tables should only be used to display tabular data. Using the <div> elements is the most common method of creating layouts in HTML.
🌐
Reddit
reddit.com › r/webdev › why do people say that div's > tables?
r/webdev on Reddit: Why do people say that div's > tables?
July 22, 2011 -

I know this may sound like a stupid question, but I am a self-taught developer that's kinda just learning as I go.
I've been building alot of my websites using tables instead of div's... It was mentioned to me that using tables instead of div's is just "stupid".... Wasn't really given an explanation as to why, so I am just curious... Why?

EDIT: I've received some just amazing information you guys, thanks a ton!

Top answer
1 of 5
41
Tables are slower to render. Modern HTML is not for appearance. It is for extensibility. Someone should be able to read your HTML and easily interpret what each section is. This isn't the case with tables, which are used for aesthetics not classification. You know what each is in this scenario.
sidebar
content
is a lot harder to grasp. Why is the table there? It is not necessary. The table has nothing to do with classifying the sidebar and content. It has everything to do with aligning them, which is aesthetics, which is for CSS, not HTML. Are you familiar with XML readers? HTML should be able to be read and interpreted by an XML reader. A table to an XML reader - or even the average person - does not mean "a way to align content." It means tabular data - think Excel spreadsheets. However, an XML reader reading "a division of the page, classified as sidebar" makes perfect sense, even to a human. The best way to determine whether or not you are using the correct element is to imagine an XML reader trying to interpret it. Don't use it for aesthetics. Use it for classification. Your sidebar is a division, not the table cell of a spreadsheet. EDIT: Forgot . I also didn't mention why it is important to be semantically labelled correctly, which is why I'm surprised this has as many upvotes as it does. All I did was describe how to be semantically correct, but OP - and anyone else - should know why, as that is the question that was asked. I elaborated in a few comments. For those interested here is one of them. In short, you are not only coding for the sake of rendering the content to the page correctly. You are coding so that robots/crawlers/spiders/whatever can read just your code and understand what everything is. It is important that they can.
2 of 5
13
This is one of the best examples to demonstrate why using divs is superior than tables for structural markup http://www.csszengarden.com/ Edit: Learn CSS. You are lost without having a thorough understanding.
🌐
Reddit
reddit.com › r/html › fitting a table inside a div
r/HTML on Reddit: Fitting a Table Inside a Div
August 23, 2022 -

I want to make sure my table fits cleanly inside a div that takes up 1/6 of my horizontal screen space.

My current table spills out of the div and I have tried using the table.style.width = "100%" in javascript to set my table back to my div dimensions, but I can't seem to get it to work.

I have a codepen here, https://codepen.io/retug/pen/wvmOKdg, note you must click on the tab "rebar" to make the table popup. You should see the table overflow into the adjacent div.

Any ideas on how to fix?

Code of interest:

function rebarSelection() {
  ...
  let table = document.getElementById("rebarData")
  table.innerHTML= ''
  let row = document.createElement('tr');
  let Xpnt = 2 
  let Ypnt = 1
  let Xdata = document.createElement('td')
  let Ydata = document.createElement('td')
  let rebarData = document.createElement('td')
  var Xinput = document.createElement("input");
  var Yinput = document.createElement("input");
  var rebarInput = document.createElement("input");
  Xinput.type = "Number";
  Yinput.type = "Number";
  rebarInput.type = "Number";
  Xinput.value = Xpnt
  Yinput.value = Ypnt
  rebarInput.value = 5
  Xdata.appendChild(Xinput)
  Ydata.appendChild(Yinput)
  rebarData.appendChild(rebarInput)
  row.appendChild(Xdata)
  row.appendChild(Ydata)
  row.appendChild(rebarData)
  table.appendChild(row)  
  table.style.width = "100%"
}

Thanks!

Top answer
1 of 2
1
Welcome to r/HTML . When asking a question, please ensure that you list what you've tried, and provide links to example code (e.g. JSFiddle/JSBin). If you're asking for help with an error, please include the full error message and any context around it. You're unlikely to get any meaningful responses if you do not provide enough information for other users to help. Your submission should contain the answers to the following questions, at a minimum: What is it you're trying to do? How far have you got? What are you stuck on? What have you already tried? I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2 of 2
1
Your number inputs that are inside the cells are too wide for the space, so they are pushing out the width of the cells and thus the table. This is also happening on the Points table for me, not sure if you see it too. You could do this which fixes the problem right away. Add this to your css: input[type="number"]{width: 100%;} This makes the width of the number dropdowns 100% of the width of the cell, and no more. You might want to instead add a class instead to your number dropdowns such as: And then add a corresponding class in your css: .numDropDown {width: 100%;} This way, if you use another input with type "number" somewhere else on the site, it won't default to the style set by using input[type="number"]. Using classes instead of styling whole elements gives you more granular control.
🌐
Smashing Magazine
smashingmagazine.com › 2009 › 04 › from-table-hell-to-div-hell
Table Layouts vs. Div Layouts: From Hell to… Hell? — Smashing Magazine
A block-level element is an HTML tag (such as p, table, h1 or div) that generates a break line. A block-level element has five spacing properties: height, width, margin, border and padding.
🌐
Sololearn
sololearn.com › en › Discuss › 347550 › what-are-the-advantages-using-div-rather-using-table-
What are the advantages using <div> rather using <table> ? | Sololearn: Learn to code for FREE!
The good practice rule is: - <table> when displaying "real" table formatted data - best suited semantical tag ( <div> is the most generic -- no particular semantical meaning ) styled with css display property using table family values when displaying table for layouts ( or other purposes non fiting in first case ) Benefit is mainly a best ranked page by search engines, after a better readability of code ^^ ... A long long time ago, people had to use table so they could position thing in an HTML page.