In the realm of web development, HTML and CSS are like the peanut butter and jelly of the internet, working together to create visually appealing and functional web pages. One of the most common elements that these two technologies collaborate on is the humble HTML table. In this article, we will delve into the world of CSS and HTML tables, exploring how to create, style, and manipulate them.
Understanding HTML Tables
Before we dive into the styling aspect, let's ensure we have a solid grasp of HTML tables. Tables in HTML are defined with the <table> tag and consist of <tr> (table row), <th> (table header), and <td> (table data) tags. Here's a simple example:
| Header 1 | Header 2 |
|---|---|
| Data 1 | Data 2 |
Basic CSS Styling for Tables
Now that we have our table structure in place, let's start styling it with CSS. We can target the table, rows, headers, and data cells to apply styles. Here's a basic example:

```css table { width: 100%; border-collapse: collapse; } th, td { padding: 15px; text-align: left; border-bottom: 1px solid #ddd; } tr:hover {background-color: #f5f5f5;} ```
Styling Table Headers
To make table headers stand out, we can apply different styles to them. We can use the <th> tag to define headers and target them with CSS:
```css th { background-color: #f2f2f2; font-weight: bold; } ```
Responsive Tables
With the increasing number of users browsing on mobile devices, it's crucial to make our tables responsive. We can achieve this by using CSS media queries and adjusting the table layout:
```css @media screen and (max-width: 600px) { table, thead, tbody, th, td, tr { display: block; } thead tr { position: absolute; top: -9999px; left: -9999px; } tr { margin: 0 0 1rem 0; } tr:nth-child(odd) { background: #ccc; } td { border-bottom: 1px solid #eee; position: relative; padding-left: 50%; } td:before { position: absolute; left: 6px; width: 45%; padding-right: 10px; white-space: nowrap; content: attr(data-column); font-weight: bold; } } ```
Manipulating Tables with CSS
CSS isn't just about styling; it also allows us to manipulate the layout and behavior of tables. We can use CSS to hide or show table rows, columns, or even entire tables based on user interactions or other conditions.

Hiding and Showing Table Rows
Using CSS, we can hide table rows and show them when needed. We can achieve this by toggling the <tr> visibility with JavaScript or CSS itself using the :checked selector and the :target pseudo-class.
Flipping Table Rows
Another interesting manipulation is flipping table rows, i.e., reversing their order. We can achieve this by using CSS transforms and transitions:
```css tr { transform: rotateX(180deg); transition: transform 0.5s ease; } tr:hover { transform: rotateX(0deg); } ```
In conclusion, CSS and HTML tables are a powerful combination that enables us to create engaging, responsive, and functional data displays on the web. By mastering the techniques discussed in this article, you'll be well on your way to becoming a table styling and manipulation expert.






















