/

HTML / CSS / JavaScript Tutorial

CSS Property: border-collapse

[this page | pdf | back links]

The CSS (CSS2) border-collapse property indicates whether table borders are collapsed into a single border or detached as in standard HTML. Note if a !DOCTYPE is not specified then the border-collapse property can produce unexpected results.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

collapse

Borders are collapsed into a single border where possible (ignoring border-spacing and empty-cells properties)

separate

(default value). Borders are detached, and border-spacing and empty-cells properties have some meaning

 

Default Value:

separate

JavaScript syntax:

e.g. object.style.borderCollapse="collapse"

Inherited:

Yes

Animatable:

No

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,td {border: thin solid red}
table.x1 {border-collapse: collapse;}
</style>
</head>
<body>
<table>
  <tr><td>1. Element with default property</td></tr>
  <tr><td>&nbsp;</td></tr>
</table>
<br>
<table class="x1">
  <tr><td>2. Element set using in-file HTML style</td></tr>
  <tr><td>&nbsp;</td></tr>
</table>
<br>
<table id="x2">
  <tr><td>3. Element set using JavaScript</td></tr>
  <tr><td>&nbsp;</td></tr>
</table>

<script>
document.getElementById("x2").style.borderCollapse="collapse";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyBorderCollapse() {
  var x = document.createElement("DIV"); x.style.borderCollapse = "collapse"; return (window.getComputedStyle(x, null).borderCollapse == "collapse");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile