/

HTML / CSS / JavaScript Tutorial

HTML Standard attribute: span

[this page | pdf | back links]

The HTML span attribute specifies the number of columns that a <col> or <colgroup> element spans.

 

Valid attribute values (for <col>, <colgroup>) include:

 

Value

Description

integer

Number of columns the element should span

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table, th, td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
Created using HTML:<br>
<table>
  <colgroup>
    <col span="2" style="background-color: yellow">
    <col style="background-color: orange">
  </colgroup>
  <tr><td>1</td><td>2</td><td>3</td></tr>
</table>

<br><br>Created using JavaScript:<br>
<table id="tbl">
  <tr><td>1</td><td>2</td><td>3</td></tr>
</table>

<script>
var x = document.createElement("COLGROUP");
var x1 = document.createElement("COL");
var x2 = document.createElement("COL");
x1.setAttribute("span","2");
x1.setAttribute("style","background-color: yellow");
x2.setAttribute("style","background-color: orange");
x.appendChild(x1); x.appendChild(x2);
document.getElementById("tbl").appendChild(x);
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Attributes


Desktop view | Switch to Mobile