How to Make an HTML Table With Rounded Corner Using CSS
- Understanding HTML Tables and CSS
- Method 1: Using CSS Border Radius
- Method 2: Styling Table Borders with CSS
- Method 3: Adding Background Color for Enhanced Visuals
- Conclusion
- FAQ

Creating visually appealing web content is essential for engaging users, and one of the simplest ways to enhance your website’s aesthetics is by styling HTML tables. If you’ve ever wondered how to make an HTML table with rounded corners using CSS, you’re in the right place. This guide will walk you through the steps to achieve that stylish look, ensuring your tables stand out while maintaining functionality. Rounded corners can add a touch of modernity to your designs, making them more inviting and user-friendly. Let’s dive into the world of CSS styling and transform your standard HTML tables into eye-catching elements.
Understanding HTML Tables and CSS
Before we start styling, it’s crucial to understand the structure of an HTML table. A basic table consists of elements like <table>
, <tr>
, <td>
, and <th>
. The <table>
tag defines the table, <tr>
represents table rows, and <td>
and <th>
denote table data cells and header cells, respectively.
Now, let’s explore how to apply CSS to give these tables rounded corners. CSS (Cascading Style Sheets) is a powerful tool for styling HTML elements, and it allows you to change the appearance of your tables seamlessly.
Method 1: Using CSS Border Radius
One of the easiest ways to create rounded corners for an HTML table is by using the border-radius
property in CSS. This property controls the curvature of the corners of an element.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rounded Corner Table</title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
border-radius: 15px;
overflow: hidden;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
th, td {
padding: 15px;
text-align: left;
border: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>30</td>
<td>New York</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>25</td>
<td>Los Angeles</td>
</tr>
</tbody>
</table>
</body>
</html>
The border-radius
property is set to 15px
, which gives the table its rounded corners. The overflow: hidden
rule ensures that the corners remain rounded when the table is rendered. Adding a box-shadow
enhances the table’s appearance, giving it a subtle lift off the page. The padding in the <th>
and <td>
elements ensures that the text within the cells is comfortably spaced.
Method 2: Styling Table Borders with CSS
Another approach to create rounded corners on an HTML table is to style the borders of the table and the cells. This method can be particularly useful if you want to maintain a more traditional look while still achieving a rounded effect.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rounded Table Borders</title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: separate;
border-spacing: 0;
border: 2px solid #ddd;
border-radius: 15px;
}
th, td {
padding: 15px;
text-align: left;
border: 1px solid #ddd;
border-radius: 15px;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>30</td>
<td>New York</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>25</td>
<td>Los Angeles</td>
</tr>
</tbody>
</table>
</body>
</html>
In this example, the border-collapse
property is set to separate
, allowing the individual cell borders to maintain their rounded corners. Each cell also has a border-radius
applied, which complements the overall table design. This method is particularly effective when you want each cell to have its own rounded appearance while still being part of the overall table structure.
Method 3: Adding Background Color for Enhanced Visuals
Sometimes, adding a background color to your table can enhance the visual appeal even further. This method combines rounded corners with a distinct background color, making your table pop on the page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Colored Rounded Table</title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: separate;
border-spacing: 0;
border-radius: 15px;
background-color: #f9f9f9;
}
th, td {
padding: 15px;
text-align: left;
border: 1px solid #ddd;
border-radius: 15px;
}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>30</td>
<td>New York</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>25</td>
<td>Los Angeles</td>
</tr>
</tbody>
</table>
</body>
</html>
In this example, the table has a light background color that contrasts with the header’s darker green. This not only makes the table more visually appealing but also enhances readability. The border-radius
property is applied to the table and cells, creating a cohesive look. This method is ideal for designs that require a bit more flair without compromising functionality.
Conclusion
Styling your HTML tables with rounded corners using CSS is a straightforward process that can dramatically improve the visual appeal of your web pages. Whether you choose to apply a simple border-radius
, style individual cell borders, or incorporate background colors, you can create tables that are not only functional but also aesthetically pleasing. By following the methods outlined in this guide, you can easily enhance your web design skills and create a more engaging user experience.
FAQ
-
How do I add rounded corners to my HTML table?
You can add rounded corners to your HTML table by using the CSSborder-radius
property. -
Can I apply different border-radius values to each corner?
Yes, you can use theborder-radius
property with four values to specify different radii for each corner. -
Will rounded corners work on all browsers?
Most modern browsers support theborder-radius
property, but it’s always good to check compatibility for older versions. -
How can I make my table responsive?
You can make your table responsive by using CSS properties likewidth: 100%
and utilizing media queries for better layout adjustments. -
Is it possible to style individual cells differently?
Yes, you can apply different styles to individual cells by using specific classes or inline styles.