HTML
CSS
JS
Result
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Responsive table design using only HTML and CSS</title> </head> <body> <div class="table-main"> <div class="container-fluid p-0 table-responsive"> <table class="table-area"> <thead> <th>Heading 1</th> <th>Heading 2</th> <th>Heading 3</th> <th>Heading 4</th> <th>Heading 5</th> <th>Heading 6</th> </thead> <tbody> <tr> <td> Data 1 </td> <td> <div class="pay-list-text"> Data 2 </div> </td> <td> <div> Data 3 </div> </td> <td> Data 4 </td> <td> Data 5 </td> <td> Data 6 </td> </tr> <tr> <td> Data 1 </td> <td> <div class="pay-list-text"> Data 2 </div> </td> <td> <div> Data 3 </div> </td> <td> Data 4 </td> <td> Data 5 </td> <td> Data 6 </td> </tr> <tr> <td> Data 1 </td> <td> <div class="pay-list-text"> Data 2 </div> </td> <td> <div> Data 3 </div> </td> <td> Data 4 </td> <td> Data 5 </td> <td> Data 6 </td> </tr> <tr> <td> Data 1 </td> <td> <div class="pay-list-text"> Data 2 </div> </td> <td> <div> Data 3 </div> </td> <td> Data 4 </td> <td> Data 5 </td> <td> Data 6 </td> </tr> <tr> <td> Data 1 </td> <td> <div class="pay-list-text"> Data 2 </div> </td> <td> <div> Data 3 </div> </td> <td> Data 4 </td> <td> Data 5 </td> <td> Data 6 </td> </tr> </tbody> </table> </div> </div> </body> </html>
CSS
body { min-height: 100vh; display: grid; place-items: center; } .table-main { margin-top: 20px; width: 95%; } .table-main .table-responsive { overflow-y: auto; } .table-main table.table-area { width: 100%; border-spacing: 0; border-radius: 5px; overflow: hidden; } .table-main table.table-area thead { visibility: visible; position: relative; } .table-main table.table-area thead tr { border: none; border-bottom: 1px solid #a8a8a8; } .table-main table.table-area thead tr th { text-align: left; background: #d5fdd7; border: none; color: #000; font-size: 16px; font-weight: 600; padding: 15px; white-space: nowrap; } .table-main table.table-area thead tr th:nth-last-child(1) { text-align: left; } .table-main table.table-area tr { display: table-row; border: none; border-radius: 0; text-align: left; border: none; border-bottom: 1px solid #eee; } .table-main table.table-area tr:hover { background-color: #f2f9fc; } .table-main table.table-area tr td { display: table-cell; border: none; padding: 12px 15px; color: #212121; font-size: 16px; font-weight: 400; } .table-main table.table-area tr td:nth-last-child(1) { text-align: left; } .table-main table.table-area tr:nth-child(even) { background: #f0f0f0; }
JS
Responsive table design using only HTML and CSS