How to Create a Full-Width Table using CSS? Last Updated : 28 May, 2024 Comments Improve Suggest changes Like Article Like Report Creating a full-width table using CSS involves setting the table's width to 100% and adjusting other relevant properties to ensure that it stretches across the entire width of its parent container. In this article, we will explain the approach to creating a full-width table using CSS. ApproachCreate a container using <div> to hold a table.Inside the container, add a <table> element with appropriate <thead>, <tbody>, <tr>, <th>, and <td> elements for table headers and data.Reset the default margin and padding of the body and HTML elements to zero.Set the width of the body and html elements to 100% to ensure they take the full width of the viewport.Set the width of the table element to 100% to ensure it spans the full width of its container.Example: The below code demonstrates the implementation to create a full-width table. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Full Width Table</title> <style> body, html { margin: 0; padding: 0; width: 100%; } .container { width: 100%; } table { width: 100%; border-collapse: collapse; } th, td { border: 1px solid #000; padding: 8px; text-align: left; } th { background-color: #f2f2f2; } </style> </head> <body> <div class="container"> <table> <thead> <tr> <th>Header 1</th> <th>Header 2</th> <th>Header 3</th> </tr> </thead> <tbody> <tr> <td>Data</td> <td>Data</td> <td>Data</td> </tr> <tr> <td>Data</td> <td>Data</td> <td>Data</td> </tr> <tr> <td>Data</td> <td>Data</td> <td>Data</td> </tr> </tbody> </table> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to Create a Full-Width Table using CSS? yuvrajghule281 Follow Improve Article Tags : Web Technologies CSS Similar Reads How to Create Equal Width Table Cell Using CSS ? Creating equal-width table cells using CSS refers to adjusting the table's layout so that all columns maintain the same width. This technique ensures a consistent and organized appearance, making the table content easier to read and visually balanced.Here we are following some common approaches:Tabl 3 min read How to Center a Table with CSS ? Here are different ways to center table in CSS.1. Center a Table using margin auto propertyThe CSS margin is used to set the space around the element. The margin auto enables dynamic and equal margins from both sides and center the element. Syntaxtable { margin: auto;}By setting the margin auto the 2 min read How to style block buttons (full-width) using CSS ? In this article, we will explore how to style block buttons with full width using CSS. Making buttons stand out on a website is crucial. Such types of buttons provide responsiveness to the web page that works well on various devices. Styling buttons with clear words, appealing colors, and effects, c 3 min read How to create a table row using HTML? Define a row in a table by using a <tr> tag in a document. This tag is used to define a row in an HTML table. The tr element contains multiple th or td elements. Syntax:<tr> ... </tr>Example: In this example, a table row in HTML5, utilizes the <tr> tag within the <tbody 1 min read How to create a Full-Page Background with CSS ? To create a full-page background with CSS, set the body's height to `100vh` to cover the viewport, and add a background image using `background-image`. Ensure the image fills the entire viewport without distortion by setting 'background-size: cover'. Optionally, adjust 'background-position' and 'bac 2 min read How to create full width container using bootstrap? Bootstrap offers two types of containers: fixed-width containers and full-width, fluid containers. The container-fluid class is used to create a full-width container that spans the entire width of the viewport, adjusting dynamically as the viewport size changes.Container Types in BootstrapFixed-Widt 3 min read How to create a zebra stripped table with CSS ? Creating a zebra-striped table with CSS makes your table easier to read by adding alternating background colors to the rows. This design helps to visually separate the rows, making it simpler for users to follow the data.These are the following methods to create a zebra-stripped table with CSS Table 2 min read How to Define a Minimum Width for HTML Table Cell using CSS ? To set a minimum width for an HTML table cell using CSS, apply the min-width property directly to the <td> element, ensuring it does not shrink below the specified size. This ensures a minimum width for the cell content, maintaining layout integrity. Table of Content Using the min-width Proper 2 min read How create table without using <table> tag ? HyperText Markup Language (HTML) is the standard markup language used to create web pages. HTML allows table creation using the <table> tag. However, tables can also be created in HTML without using <table> tag with the help of Cascading Style Sheet (CSS). CSS is a mechanism for adding s 3 min read Like