171

I have searched and searched, but haven't been able to find a solution for my requirement.

I have a plain ol' HTML table. I want round corners for it, without using images or JS, i.e. pure CSS only. Like this:

Table layout sketch

Rounded corners for corner cells, and 1px thick border for the cells.

So far I have this:

table {
  -moz-border-radius: 5px !important;
  border-collapse: collapse !important;
  border: none !important;
}
table th,
table td {
  border: none !important
}
table th:first-child {
  -moz-border-radius: 5px 0 0 0 !important;
}
table th:last-child {
  -moz-border-radius: 0 5px 0 0 !important;
}
table tr:last-child td:first-child {
  -moz-border-radius: 0 0 0 5px !important;
}
table tr:last-child td:last-child {
  -moz-border-radius: 0 0 5px 0 !important;
}
table tr:hover td {
  background-color: #ddd !important
}

But that leaves me without any borders for the cells. If I add borders, they aren't rounded!

Any solutions?

4
  • 1
    Have you tried adding border to the TD elements using moz-border-radius? Also, be aware that this won't work in IE, IE will still show straight edges. Commented Feb 8, 2011 at 11:00
  • Looking at the answers and your comments, it's not clear what your want: Where do you want rounded corners ? table, table cells, only cells on the corners of your table ? Commented Feb 8, 2011 at 11:36
  • 7
    I guess it's quite obvious from the question title, table corners Commented Feb 8, 2011 at 11:54
  • @VishalShah +1 for a really useful question. I was blindly using a jQuery UI rounded corner class designed for the UI widgets, but I applied it to table elements and everything went square. So now I can still use my jQuery UI theme with a table-based widget. Commented Sep 30, 2012 at 13:11

21 Answers 21

129

Seems to work fine in FF and Chrome (haven't tested any others) with separate borders: http://jsfiddle.net/7veZQ/3/

Edit: Here's a relatively clean implementation of your sketch:

table {
    border-collapse:separate;
    border:solid black 1px;
    border-radius:6px;
}

td, th {
    border-left:solid black 1px;
    border-top:solid black 1px;
}

th {
    background-color: blue;
    border-top: none;
}

td:first-child, th:first-child {
     border-left: none;
}
<table>
    <thead>
    <tr>
        <th>blah</th>
        <th>fwee</th>
        <th>spoon</th>
    </tr>
    </thead>
    <tr>
        <td>blah</td>
        <td>fwee</td>
        <td>spoon</td>
    </tr>
    <tr>
        <td>blah</td>
        <td>fwee</td>
        <td>spoon</td>
    </tr>
</table>

http://jsfiddle.net/MuZzz/3577/

Sign up to request clarification or add additional context in comments.

12 Comments

Not exactly what i'm looking for. If you remove the table padding & apply border-radius to the corner cells only, you get 2px thick borders, which is ugly. Rather have no borders at all.
Close. The corner cells needed border radius too. jsfiddle.net/JWb4T/1 Though now you see a slight gap between edge of the corner cells & the edge of the table. Can be fixed by reducing the border radius for the corner cells. Thanks :D
maybe this looked good 7 years ago, but today the cell borders do not connect using this solution so it looks awful.
Did anyone notice that the table row is peeking out from corner?
In order for this to look better, you should also apply border-spacing: 0; to the <table> element
|
106

The selected answer is terrible. I would implement this by targeting the corner table cells and applying the corresponding border radius.

To get the top corners, set the border radius on the first and last of type of the th elements, then finish by setting the border radius on the last and first of td type on the last of type tr to get the bottom corners.

th:first-of-type {
  border-top-left-radius: 10px;
}
th:last-of-type {
  border-top-right-radius: 10px;
}
tr:last-of-type td:first-of-type {
  border-bottom-left-radius: 10px;
}
tr:last-of-type td:last-of-type {
  border-bottom-right-radius: 10px;
}

9 Comments

This is so much better than all the other answers... This is amazingly simple and elegant!
Glad I could help!
This works really well, but I have another table with th elements on the top and left side of the table and this does not work for that. How do I go about rounding the corners of that type of table?
Nice answer, but it does not explain how to solve the conflict with border-collapse: collapse, resulting in double borders between cells. And careful when increasing border-radius; (unpadded) cell content may overlap the rounded corners.
This is brilliant even in 2022😂
|
54

For me, the Twitter Bootstrap Solution looks good. It excludes IE < 9 (no round corners in IE 8 and lower), but that's O.K. I think, if you develop prospective Web-Apps.

CSS/HTML:

table { 
    border: 1px solid #ddd;
    border-collapse: separate;
    border-left: 0;
    border-radius: 4px;
    border-spacing: 0px;
}
thead {
    display: table-header-group;
    vertical-align: middle;
    border-color: inherit;
    border-collapse: separate;
}
tr {
    display: table-row;
    vertical-align: inherit;
    border-color: inherit;
}
th, td {
    padding: 5px 4px 6px 4px; 
    text-align: left;
    vertical-align: top;
    border-left: 1px solid #ddd;    
}
td {
    border-top: 1px solid #ddd;    
}
thead:first-child tr:first-child th:first-child, tbody:first-child tr:first-child td:first-child {
    border-radius: 4px 0 0 0;
}
thead:last-child tr:last-child th:first-child, tbody:last-child tr:last-child td:first-child {
    border-radius: 0 0 0 4px;
}
<table>
  <thead>
    <tr><th>xxx</th><th>xxx</th><th>xxx</th></tr>
  </thead>
  <tbody>
    <tr><td>xxx</td><td>xxx</td><td>xxx</td></tr>
    <tr><td>xxx</td><td>xxx</td><td>xxx</td></tr>
    <tr><td>xxx</td><td>xxx</td><td>xxx</td></tr>
    <tr><td>xxx</td><td>xxx</td><td>xxx</td></tr>
    <tr><td>xxx</td><td>xxx</td><td>xxx</td></tr>
  </tbody>
</table>

You can play with that here (on jsFiddle)

4 Comments

Excellent answer, IMHO this should be the accepted answer.
Careful when increasing border-radius; (unpadded) cell content may overlap the rounded corners. A few CSS rules are missing, causing cell background to overflow the rounded corners at the top right and bottom right.
@RuudHelderman, can you add the missing rules?
thanks, I learned from the jsFiddle and make it work. Thank you.
21

Firstly, you'll need more than just -moz-border-radius if you want to support all browsers. You should specify all variants, including plain border-radius, as follows:

-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;

Secondly, to directly answer your question, border-radius doesn't actually display a border; it just sets how the corners look of the border, if there is one.

To turn on the border, and thus get your rounded corners, you also need the border attribute on your td and th elements.

td, th {
   border:solid black 1px;
}

You will also see the rounded corners if you have a background colour (or graphic), although of course it would need to be a different background colour to the surrounding element in order for the rounded corners to be visible without a border.

It's worth noting that some older browsers don't like putting border-radius on tables/table cells. It may be worth putting a <div> inside each cell and styling that instead. However this shouldn't affect current versions of any browsers (except IE, that doesn't support rounded corners at all - see below)

Finally, not that IE doesn't support border-radius at all (IE9 beta does, but most IE users will be on IE8 or less). If you want to hack IE to support border-radius, look at http://css3pie.com/

[EDIT]

Okay, this was bugging me, so I've done some testing.

Here's a JSFiddle example I've been playing with

It seems like the critical thing you were missing was border-collapse:separate; on the table element. This stops the cells from linking their borders together, which allows them to pick up the border radius.

Hope that helps.

5 Comments

To keep the code to a minimum, i've left out the cross-browser stuff. If i give a border to td and th, they aren't rounded. I get straight edges. Could give sample css code for a table with no css applied to it, which would demonstrate what you're saying.
@Vishal Shah - I have updated my answer after doing some tests. Hope that helps.
Your example displays a border radius for ALL the cells, where as i want it only for the corner cells. This is what i was looking for: jsfiddle.net/JWb4T/1
@Vishal Shah - I understood the problem to be the lack of rounding anywhere on the table, rather than specifically which bits of the table should be rounded. Glad you got it sorted in the end though (it looks like the border-collapse:separate; tip was useful in the end)
+1 for that border-collapse:separate tip. That really helped me.
9

The best solution I've found for rounded corners and other CSS3 behavior for IE<9 can be found here: http://css3pie.com/

Download the plug-in, copy to a directory in your solution structure. Then in your stylesheet make sure to have the behavior tag so that it pulls in the plug-in.

Simple example from my project which gives me rounded corners, color gradient, and box shadow for my table:

.table-canvas 
{
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    overflow:hidden;
    border-radius: 10px;
    -pie-background: linear-gradient(#ece9d8, #E5ECD8);   
    box-shadow: #666 0px 2px 3px;
    behavior: url(Include/PIE.htc);
    overflow: hidden;
}

Don't worry if your Visual Studio CSS intellisense gives you the green underline for unknown properites, it still works when you run it. Some of the elements are not very clearly documented, but the examples are pretty good, especially on the front page.

1 Comment

css behavior property was non-standard MS extension to CSS and it was removed from IE10+ - i.e. this won't work in modern browsers
8

It is a little rough, but here is something I put together that is comprised entirely of CSS and HTML.

  • Outer corners rounded
  • Header row
  • Multiple data rows

This example also makes use of the :hover pseudo class for each data cell <td>. Elements can be easily updated to meet your needs, and the hover can quickly be disabled.

(However, I have not yet gotten the :hover to properly work for full rows <tr>. The last hovered row does not display with rounded corners on the bottom. I'm sure there is something simple that is getting overlooked.)

table.dltrc {
  width: 95%;
  border-collapse: separate;
  border-spacing: 0px;
  border: solid black 2px;
  border-radius: 8px;
}

tr.dlheader {
  text-align: center;
  font-weight: bold;
  border-left: solid black 1px;
  padding: 2px
}

td.dlheader {
  background: #d9d9d9;
  text-align: center;
  font-weight: bold;
  border-left: solid black 1px;
  border-radius: 0px;
  padding: 2px
}

tr.dlinfo,
td.dlinfo {
  text-align: center;
  border-left: solid black 1px;
  border-top: solid black 1px;
  padding: 2px
}

td.dlinfo:first-child,
td.dlheader:first-child {
  border-left: none;
}

td.dlheader:first-child {
  border-radius: 5px 0 0 0;
}

td.dlheader:last-child {
  border-radius: 0 5px 0 0;
}


/*===== hover effects =====*/


/*tr.hover01:hover,
tr.hover02:hover {
  background-color: #dde6ee;
}*/


/* === ROW HOVER === */


/*tr.hover02:hover:last-child {
  background-color: #dde6ee;
  border-radius: 0 0 6px 6px;
  }*/


/* === CELL HOVER === */

td.hover01:hover {
  background-color: #dde6ee;
}

td.hover02:hover {
  background-color: #dde6ee;
}

td.hover02:first-child {
  border-radius: 0 0 0 6px;
}

td.hover02:last-child {
  border-radius: 0 0 6px 0;
}
<body style="background:white">
  <br>
  <center>
    <table class="dltrc" style="background:none">
      <tbody>
        <tr class="dlheader">
          <td class="dlheader">Subject</td>
          <td class="dlheader">Title</td>
          <td class="dlheader">Format</td>
        </tr>
        <tr class="dlinfo hover01">
          <td class="dlinfo hover01">One</td>
          <td class="dlinfo hover01">Two</td>
          <td class="dlinfo hover01">Three</td>
        </tr>
        <tr class="dlinfo hover01">
          <td class="dlinfo hover01">Four</td>
          <td class="dlinfo hover01">Five</td>
          <td class="dlinfo hover01">Six</td>
        </tr>
        <tr class="dlinfo hover01">
          <td class="dlinfo hover01">Seven</td>
          <td class="dlinfo hover01">Eight</td>
          <td class="dlinfo hover01">Nine</td>
        </tr>
        <tr class="dlinfo2 hover02">
          <td class="dlinfo hover02">Ten</td>
          <td class="dlinfo hover01">Eleven</td>
          <td class="dlinfo hover02">Twelve</td>
        </tr>
      </tbody>
    </table>
  </center>
</body>

Comments

8

Some time ago browsers ignored border-radius for outline, but now they apply it, so the possibble solution is use outline with negative offset:

table, tr, th, td {
  border-collapse: collapse;
  border: 1px solid;
}

table {
  border-radius: 1em;
  outline: 1px solid;
  outline-offset: -1px;
  overflow: hidden;
}

th, td {
  padding: .5em 1em;
}
<table>
  <thead>
    <tr><th>first<th>second<th>third</tr>
  </thead>
  <tbody>
    <tr><td>1<td>2<td>3</tr>
    <tr><td>1st<td>2nd<td>3rd</tr>
    <tr><td>one<td>two<td>three</tr>
  </tbody>
</table>

It works with any border width and any radius (even if it's larger then half of the cell):

table, tr, th, td {
  border-collapse: collapse;
  border: .5em solid silver;
}

table {
  border-radius: 5em;
  outline: .5em solid silver;
  outline-offset: -.5em;
  overflow: hidden;
}

th, td {
  padding: .5em 1em;
}

th:first-child, td:first-child {
  padding-left: 3em;
}

th:last-child, td:last-child {
  padding-right: 3em;
}
<table>
  <thead>
    <tr><th>first<th>second<th>third</tr>
  </thead>
  <tbody>
    <tr><td>1<td>2<td>3</tr>
    <tr><td>1st<td>2nd<td>3rd</tr>
    <tr><td>one<td>two<td>three</tr>
  </tbody>
</table>

1 Comment

This worked for my complex table, while some of the other highly-voted answers did not.
6

Alternative solution would be to use a wrapper for table

http://jsfiddle.net/0fmweahc/15/

<div class="table-wrapper">
 <table>
    <tr class="first-line"><td>A</td><td>B</td></tr>
    <tr class="last-line"><td>C</td><td>D</td></tr>
 </table>
</div>

<style>
  .table-wrapper {
    border: 1px solid black;
    border-radius: 20px;
    margin: 10%;
  }

  table, td, th {
    border: 1px solid black;
    padding: 10px;
  }

  table {
    width: 100%;
    border-collapse: collapse;
    border-style: hidden;
  }
</style>

enter image description here

2 Comments

Nice! But why not td, th instead of table, td, th?
Careful with background, it may leak over the rounded corners. Either specify background in .table-wrapper, or (if you need individual rows or cells to have their own background), use overflow: hidden; as proposed in Ubby's answer.
4

To adapt @luke flournoy's brilliant answer - and if you're not using th in your table, here's all the CSS you need to make a rounded table:

.my_table {
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid grey;
    border-radius: 10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
}

.my_table tr:first-of-type {
    border-top-left-radius: 10px;
}

.my_table tr:first-of-type td:last-of-type {
    border-top-right-radius: 10px;
}

.my_table tr:last-of-type td:first-of-type {
    border-bottom-left-radius: 10px;
}

.my_table tr:last-of-type td:last-of-type {
    border-bottom-right-radius: 10px;
}

1 Comment

Great job Colin it solved border seperation problem which is what I am looking for :)
3

2020+ solution

  1. Use CSS variable to pass the border radius of the table to the border radius of the corner cells, so you can change the radius on a single place (like <table class="rounded" style="--radius: 10px">)
  2. border-collapse drops the border radius settings and without it the border-width is doubled. To make the borders 1px wide, I'd suggest box shadows of the cells (like box-shadow: -1px -1px black);

/* rounded corners */
.rounded {
    --radius: 5px;
    --border-color: black;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    border-spacing: 0;
}
.rounded tr:first-child>:first-child { border-top-left-radius: var(--radius); }
.rounded tr:first-child>:last-child { border-top-right-radius: var(--radius); }
.rounded tr:last-child>:first-child { border-bottom-left-radius: var(--radius); }
.rounded tr:last-child>:last-child { border-bottom-right-radius: var(--radius); }

/* design */
.rounded th, .rounded td {
    padding: .2rem;
    /* border: 1px solid var(--border-color); */
    box-shadow: -1px -1px var(--border-color);
}
.rounded th {
    background: hsl(240deg, 100%, 80%);
}
<table class="rounded">
  <tr>
    <th>Name
    <th>Note
  <tr>
    <td>Bill Gates
    <td>Plagiator
  <tr>
    <td>Steve Jobs
    <td>Hipster
</table>

@jt3k in the comments suggests half pixel border which is an interesting but risky idea: the w3 specs allow real numbers in pixels, but they do not describe how are browsers supposed to render them and some users report issues with this.

2 Comments

looks like we could use a half pixel outline instead of a shadow ``` th, td { outline: 0.5px solid var(--border-color); } ```
@jt3k this is a noteworthy idea, but I'd advise against it - I added a note at the end of the answer
2

Looking at these two answers (By RoToRa, By Luke Flournoy), both great, but both lacking for my use case.

I combined them into one that will cater for standard and non-standard implementations of table elements, which will also "collapse" the borders, getting rid of the white spacing.

table {
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid black;
  border-radius: 6px;
  width: 100%;
  page-break-inside: avoid;
}

table tr td,
table tr th {
  border-left: 1px solid #000;
  border-top: 1px solid #000;
  padding: 4px 10px;
}

table tr td:first-child,
table tr th:first-child {
  border-left: none;
}

table tr:first-of-type td,
table tr:first-of-type th {
  border-top: none;
}
<table>
  <tbody>
    <tr>
      <th>
        Name
      </th>
      <th>
        Title
      </th>
      <th>
        Description
      </th>
      <th>
        Rating
      </th>
    </tr>
    <tr>
      <td>
        Test Object 0
      </td>
      <td>
        Test Object 0 title
      </td>
      <td>
        The description of test object 0
      </td>
      <td>
        2
      </td>
    </tr>
    <tr>
      <td>
        Test Object 1
      </td>
      <td>
        Test Object 1 title
      </td>
      <td>
        The description of test object 1
      </td>
      <td>
        2
      </td>
    </tr>
  </tbody>
</table>
<br />
<br />
<table>
  <tbody>
    <tr>
      <td>
        Cell 1, row 1
      </td>
      <td>
        Cell 2, row 1
      </td>
      <td>
        Cell 3, row 1
      </td>
      <td>
        Cell 4, row 1
      </td>
    </tr>
    <tr>
      <td colspan="4">
        Cell 1, row 2, colspan 4
      </td>
    </tr>
    <tr>
      <td>
        Cell 1, row 3
      </td>
      <td>
        Cell 2, row 3
      </td>
      <td>
        Cell 3, row 3
      </td>
      <td rowspan="2">
        Cell 4, row 3, rowspan 2
      </td>
    </tr>
    <tr>
      <th>
        Cell 1, row 4, heading
      </th>
      <th>
        Cell 2, row 4, heading
      </th>
      <th>
        Cell 3, row 4, heading
      </th>
    </tr>
  </tbody>
</table>

Comments

1

For a bordered and scrollable table, use this (replace variables, $ starting texts)

If you use thead, tfoot or th, just replace tr:first-child and tr-last-child and td with them.

#table-wrap {
  border: $border solid $color-border;
  border-radius: $border-radius;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
table td { border: $border solid $color-border; }
table td:first-child { border-left: none; }
table td:last-child { border-right: none; }
table tr:first-child td { border-top: none; }
table tr:last-child td { border-bottom: none; }
table tr:first-child td:first-child { border-top-left-radius: $border-radius; }
table tr:first-child td:last-child { border-top-right-radius: $border-radius; }
table tr:last-child td:first-child { border-bottom-left-radius: $border-radius; }
table tr:last-child td:last-child { border-bottom-right-radius: $border-radius; }

HTML:

<div id=table-wrap>
  <table>
    <tr>
       <td>1</td>
       <td>2</td>
    </tr>
    <tr>
       <td>3</td>
       <td>4</td>
    </tr>
  </table>
</div>

1 Comment

This works for the borders as well as the (cell/row) background. As always, careful when increasing border-radius; (unpadded) cell content may overlap the rounded corners.
1

Sample HTML

<table class="round-corner" aria-describedby="caption">
    <caption id="caption">Table with rounded corners</caption>
    <thead>
        <tr>
            <th scope="col">Head1</th>
            <th scope="col">Head2</th>
            <th scope="col">Head3</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td scope="rowgroup">tbody1 row1</td>
            <td scope="rowgroup">tbody1 row1</td>
            <td scope="rowgroup">tbody1 row1</td>
        </tr>
        <tr>
            <td scope="rowgroup">tbody1 row2</td>
            <td scope="rowgroup">tbody1 row2</td>
            <td scope="rowgroup">tbody1 row2</td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <td scope="rowgroup">tbody2 row1</td>
            <td scope="rowgroup">tbody2 row1</td>
            <td scope="rowgroup">tbody2 row1</td>
        </tr>
        <tr>
            <td scope="rowgroup">tbody2 row2</td>
            <td scope="rowgroup">tbody2 row2</td>
            <td scope="rowgroup">tbody2 row2</td>
        </tr>
    </tbody>
    <tbody>
        <tr>
            <td scope="rowgroup">tbody3 row1</td>
            <td scope="rowgroup">tbody3 row1</td>
            <td scope="rowgroup">tbody3 row1</td>
        </tr>
        <tr>
            <td scope="rowgroup">tbody3 row2</td>
            <td scope="rowgroup">tbody3 row2</td>
            <td scope="rowgroup">tbody3 row2</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td scope="col">Foot</td>
            <td scope="col">Foot</td>
            <td scope="col">Foot</td>
        </tr>
    </tfoot>
</table>

SCSS, easily converted to CSS, use sassmeister.com

// General CSS
table,
th,
td {
    border: 1px solid #000;
    padding: 8px 12px;
}

.round-corner {
    border-collapse: collapse;
    border-style: hidden;
    box-shadow: 0 0 0 1px #000; // fake "border"
    border-radius: 4px;

    // Maybe there's no THEAD after the caption?
    caption + tbody {
        tr:first-child {
            td:first-child,
            th:first-child {
                border-top-left-radius: 4px;
            }

            td:last-child,
            th:last-child {
                border-top-right-radius: 4px;
                border-right: none;
            }
        }
    }

    tbody:first-child {
        tr:first-child {
            td:first-child,
            th:first-child {
                border-top-left-radius: 4px;
            }

            td:last-child,
            th:last-child {
                border-top-right-radius: 4px;
                border-right: none;
            }
        }
    }

    tbody:last-child {
        tr:last-child {
            td:first-child,
            th:first-child {
                border-bottom-left-radius: 4px;
            }

            td:last-child,
            th:last-child {
                border-bottom-right-radius: 4px;
                border-right: none;
            }
        }
    }

    thead {
        tr:last-child {
            td:first-child,
            th:first-child {
                border-top-left-radius: 4px;
            }

            td:last-child,
            th:last-child {
                border-top-right-radius: 4px;
                border-right: none;
            }
        }
    }

    tfoot {
        tr:last-child {
            td:first-child,
            th:first-child {
                border-bottom-left-radius: 4px;
            }

            td:last-child,
            th:last-child {
                border-bottom-right-radius: 4px;
                border-right: none;
            }
        }
    }

    // Reset tables inside table
    table tr th,
    table tr td {
        border-radius: 0;
    }
}

http://jsfiddle.net/MuTLY/xqrgo466/

1 Comment

This works for the borders as well as the (cell/row) background. As always, careful when increasing border-radius; (unpadded) cell content may overlap the rounded corners.
1

Add a <div> wrapper around the table, and apply the following CSS

border-radius: x px;
overflow: hidden;
display: inline-block;

to this wrapper.

Comments

1

Add between <head> tags:

<style>
  td {background: #ffddaa; width: 20%;}
</style>

and in the body:

<div style="background: black; border-radius: 12px;">
  <table width="100%" style="cell-spacing: 1px;">
    <tr>
      <td style="border-top-left-radius: 10px;">
        Noordwest
      </td>
      <td>&nbsp;</td>
      <td>Noord</td>
      <td>&nbsp;</td>
      <td style="border-top-right-radius: 10px;">
        Noordoost
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>West</td>
      <td>&nbsp;</td>
      <td>Centrum</td>
      <td>&nbsp;</td>
      <td>Oost</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td style="border-bottom-left-radius: 10px;">
        Zuidwest
      </td>
      <td>&nbsp;</td>
      <td>Zuid</td>
      <td>&nbsp;</td>
      <td style="border-bottom-right-radius: 10px;">
        Zuidoost
      </td>
    </tr>
  </table>
</div>

The cell color, contents and formatting are of course for example;
it's about spacing color-filled cells within a div. Doing so, the black cell borders/table border are actually the div background color.
Note that you'll need to set the div-border-radius about 2 values greater than the separate cell corner border radii, to take a smooth rounded corner effect.

1 Comment

This works for the borders as well as the (cell/row) background. As always, careful when increasing border-radius; (unpadded) cell content may overlap the rounded corners.
1

Here's a simple solution using pseudo class selectors and handles different possible combination of <table> children. The idea is to put the border on the table as well as cells that aren't the first cells horizontally/vertically.

table {
    border: 1px solid black;
    border-collapse: separate;
    border-radius: 8px;
    border-spacing: 0;
}

th:not(:first-of-type), td:not(:first-of-type) {
    border-left: 1px solid black;
}

tr:not(:first-of-type) th,
tbody:not(:first-of-type) th,
thead ~ tbody th,
thead ~ tfoot th,
tbody ~ tfoot th,
tr:not(:first-of-type) td,
tbody:not(:first-of-type) td,
thead ~ tbody td,
thead ~ tfoot td,
tbody ~ tfoot td {
    border-top: 1px solid black;
}

th, td {
    padding: 8px
}
<table>
    <thead>
    <tr>
        <th>blah</th>
        <th>fwee</th>
        <th>spoon</th>
    </tr>
    </thead>
    <tr>
        <td>blah</td>
        <td>fwee</td>
        <td>spoon</td>
    </tr>
    <tr>
        <td>blah</td>
        <td>fwee</td>
        <td>spoon</td>
    </tr>
</table>

Comments

0

You can try this if you want the rounded corners on each side of the table without touching the cells : http://jsfiddle.net/7veZQ/3983/

<table>
    <tr class="first-line"><td>A</td><td>B</td></tr>
    <tr class="last-line"><td>C</td><td>D</td></tr>
</table>

Comments

0

The following is something I used that worked for me across browsers so I hope it helps someone in the future:

#contentblock th:first-child {
    -moz-border-radius: 6px 0 0 0;
    -webkit-border-radius: 6px 0 0 0;
    border-radius: 6px 0 0 0;
    behavior: url(/images/border-radius.htc);
    border-radius: 6px 0 0 0;
}

#contentblock th:last-child {
    -moz-border-radius: 0 6px 0 0;
    -webkit-border-radius: 0 6px 0 0;
    border-radius: 0 6px 0 0;
    behavior: url(/images/border-radius.htc);
    border-radius: 0 6px 0 0;
}
#contentblock tr:last-child td:last-child {
     border-radius: 0 0 6px 0;
    -moz-border-radius: 0 0 6px 0;
    -webkit-border-radius: 0 0 6px 0;
    behavior: url(/images/border-radius.htc);
    border-radius: 0 0 6px 0;
 }

#contentblock tr:last-child td:first-child {
    -moz-border-radius: 0 0 0 6px;
    -webkit-border-radius: 0 0 0 6px;
    border-radius: 0 0 0 6px;
    behavior: url(/images/border-radius.htc);
    border-radius: 0 0 0 6px;
}

Obviously the #contentblock portion can be replaced/edited as needed and you can find the border-radius.htc file by doing a search in Google or your favorite web browser.

Comments

0

Since none of the higher rated solutions worked for me, as I am working with a table, that has an alternating color scheme, I tried a lot and finally got my solution based on the solution, @[luke flournoy] provided.

Basically the solution with putting a rounded border on the table works - but when you apply a background color on a table row or work with a designated table head, it overwrites the overall table setting and will be displayed as a rectangle.

Luke's solutions targets only the specific corner cells, that got me to the idea, that I should maybe also apply the alternating background color to the cells of that row and not the row itself. Adding td to the tr:nth-child did the trick. Same goes if you want to use a third color on the table head. You can check this out in the code snippet below.

I didn't see any other solution actually working with background colors and especially not with different colors in one table so I hope this one helps those, who need more than just a plain mono-colored table. Rate this up if it helped you, so it moves to the top. There are a lot of very fussy and not quite helpful answers here, so.

Here's a look at my result https://i.sstatic.net/XHOEN.png

And here's the code for it:

    .LezzonPrize{
        text-align: center;
        line-height: 1.8rem;
        border-collapse: collapse;
        border-radius: 36px;
        -moz-border-radius: 36px;
        -webkit-border-radius: 36px;
        background-color: #FCF3C6;
    }

    .LezzonPrize thead th{
        background-color:#FFCF5A;
    }

    .LezzonPrize thead th:first-child{
        border-radius: 36px 0 0 0;
    }

    .LezzonPrize thead th:last-child{
        border-radius: 0 36px 0 0;
    }

    .LezzonPrize th{
        text-align: center;
        vertical-align: middle;
        line-height: 1.8rem;
        font-weight: 700;
        text-transform: none;
        border-bottom:
            2px solid #3F5A1B;
    }

    .LezzonPrize td:first-child{
        text-align:left;
    }

    .LezzonPrize td{
        font-size:18px;
    }

    .LezzonPrize tr:nth-child(2n-1) td{
        background-color: #F3CF87;
    }

    .LezzonPrize tr:last-child td:first-child{
        border-radius: 0 0 0 36px;
        -moz-border-radius: 0 0 0 36px;
        -webkit-border-radius: 0 0 0 36px;
    }

    .LezzonPrize tr:last-child td:last-child{
        border-radius: 0 0 36px 0;
        -moz-border-radius: 0 0 36px 0;
        -webkit-border-radius: 0 0 36px 0;
    }
    <table class="LezzonPrize" width="100%">
        <thead>
            <tr>
                <th width="32%">
                    Head
                </th>
                <th width="17%">
                    Head
                </th>
                <th width="17%">
                    Head
                </th>
                <th width="17%">
                    Head
                </th>
                <th width="17%">
                    Head
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>
            </tr>
            <tr>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>           
            </tr>
            <tr>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>
                <td>
                    Content
                </td>   
            </tr>
            <tr>
                <td colspan="5">Try deleting this to confirm that the round corners also work on the 2nth-child table rows</td>
            </tr>
        </tbody>
    </table>

2 Comments

This gives the background rounded corners, but the border (if any) will still have sharp edges. And careful when increasing border-radius; (unpadded) cell content may overlap the rounded corners.
I refer you to the first paragraphs of my answer.
0

Looking at the answers above I have made this

:root {
    --table-background: #fff;
    --table-border: 1px solid #ccc;
    --table-th-background: #f2f2f2;
    --table-td-background: #fff;
    --table-roundness: 7px;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
}

table {
    background: var(--table-background);
    border: var(--table-border);
    overflow: hidden;
    border-collapse: separate;
    border-radius: var(--table-roundness);
    width: 100%;
    border-top: 0;
    border-left: 0;
    border-spacing: 0;
}

table thead th:first-child {
    border-top-left-radius: var(--table-roundness);
}

table thead th:last-child {
    border-top-right-radius: var(--table-roundness);
}

table tbody tr:last-child td:first-child {
    border-bottom-left-radius: var(--table-roundness);
}

table tbody tr:last-child td:last-child {
    border-bottom-right-radius: var(--table-roundness);
}

table:not(:has(thead)) tbody tr:first-child td:first-child {
    border-top-left-radius: var(--table-roundness);
}

table:not(:has(thead)) tbody tr:first-child td:last-child {
    border-top-right-radius: var(--table-roundness);
}

table th,
table td {
    border-top: var(--table-border);
    border-left: var(--table-border);
    padding: 5px 10px;
    text-align: center;
}

table th {
    background-color: var(--table-th-background);
    font-weight: 500;
    font-size: 16px;
    line-height: 1.4;
}

table td {
    background: var(--table-td-background);
    font-weight: 400;
    font-size: 14px;
    line-height: 1.4;
}
with thead

<div class="table-wrapper">
    <table>

        <thead>
            <th>ID</th>
            <th>Amount</th>
            <th>Payment Method</th>
            <th>Status</th>
        </thead>
        
        <tbody>

          <tr>
              <td>1</td>
              <td>$100</td>
              <td>Paypal</td>
              <td>Pending</td>
          </tr>

      </tbody>


  </table>
  
  <br><br>
without thead
<br>

<div class="table-wrapper">
    <table>
        
        <tbody>

          <tr>
              <td>1</td>
              <td>$100</td>
              <td>Paypal</td>
              <td>Pending</td>
          </tr>

          <tr>
              <td>2</td>
              <td>$100</td>
              <td>Paypal</td>
              <td>Pending</td>
          </tr>

      </tbody>


  </table>

Comments

-2

Lesson in Table Borders...

NOTE: The HTML/CSS code below should be viewed in IE only. The code will not be rendered correctly in Chrome!

We need to remember that:

  1. A table has a border: its outer boundary (which can also have a border-radius.)

  2. The cells themselves ALSO have borders (which too, can also have a border-radius.)

  3. The table and cell borders can interfere with each other:

    The cell border can pierce through the table border (ie: table boundary).

    To see this effect, amend the CSS style rules in the code below as follows:
    i. table {border-collapse: separate;}
    ii. Delete the style rules which round the corner cells of the table.
    iii. Then play with border-spacing so you can see the interference.

  4. However, the table border and cell borders can be COLLAPSED (using: border-collapse: collapse;).

  5. When they are collapsed, the cell and table borders interfere in a different way:

    i. If the table border is rounded but cell borders remain square, then the cell's shape takes precedence and the table loses its curved corners.

    ii. Conversely, if the corner cell's are curved but the table boundary is square, then you will see an ugly square corner bordering the curvature of the corner cells.

  6. Given that cell's attribute takes precedence, the way to round the table's four corner's then, is by:

    i. Collapsing borders on the table (using: border-collapse: collapse;).

    ii. Setting your desired curvature on the corner cells of the table.
    iii. It does not matter if the table's corner's are rounded (ie: Its border-radius can be zero).

			.zui-table-rounded {
				border: 2px solid blue;
				/*border-radius: 20px;*/
				
				border-collapse: collapse;
				border-spacing: 0px;
			}
						
			.zui-table-rounded thead th:first-child {
				border-radius: 30px 0 0 0;
			}
			
			.zui-table-rounded thead th:last-child {
				border-radius: 0 10px 0 0;
			}
			
			.zui-table-rounded tbody tr:last-child td:first-child {
				border-radius: 0 0 0 10px;
			}
			
			.zui-table-rounded tbody tr:last-child td:last-child {
				border-radius: 0 0 10px 0;
			}
			
			
			.zui-table-rounded thead th {
				background-color: #CFAD70;
			}
			
			.zui-table-rounded tbody td {
				border-top: solid 1px #957030;
				background-color: #EED592;
			}
			<table class="zui-table-rounded">
			<thead>
				<tr>
					<th>Name</th>
					<th>Position</th>
					<th>Height</th>
					<th>Born</th>
					<th>Salary</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>DeMarcus Cousins</td>
					<td>C</td>
					<td>6'11"</td>
					<td>08-13-1990</td>
					<td>$4,917,000</td>
				</tr>
				<tr>
					<td>Isaiah Thomas</td>
					<td>PG</td>
					<td>5'9"</td>
					<td>02-07-1989</td>
					<td>$473,604</td>
				</tr>
				<tr>
					<td>Ben McLemore</td>
					<td>SG</td>
					<td>6'5"</td>
					<td>02-11-1993</td>
					<td>$2,895,960</td>
				</tr>
				<tr>
					<td>Marcus Thornton</td>
					<td>SG</td>
					<td>6'4"</td>
					<td>05-05-1987</td>
					<td>$7,000,000</td>
				</tr>
				<tr>
					<td>Jason Thompson</td>
					<td>PF</td>
					<td>6'11"</td>
					<td>06-21-1986</td>
					<td>$3,001,000</td>
				</tr>
			</tbody>
		</table>

1 Comment

Thanks for the lesson, but it does not work on Chrome, Firefox, Edge. The brown background has rounded edges, the blue border has sharp edges.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.