- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - colspan Attribute
The HTML colspan attribute is used to define how many table columns a cell should span or extend compare to other cells.
The value for this attribute must be a non-negative integer. Its default value is 1, and if we assign a value greater than 1000 to this attribute, it is considered as false value and will be set to the default value of 1.
If you assign a negative value to it, it treats it as a false value and will automatically set the default value 1 to it.
Syntax
<tag colspan = "value"></tag>
Where the value can be any non-negative integer from range 1 to 1000.
Applies On
Below listed elements allow using of the HTML colspan attribute
| Element | Description |
|---|---|
| <th> | HTML <th> tag defines a header cell in an HTML table. |
| <td> | HTML <td> tag defines a standard cell in an HTML table |
Examples of HTML colspan Attribute
Following codes demonstatre usages of colspan attribute
Colspan attribute with th Tag
In the following example, we are using the colspan attribute to span a header cell of a table.
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML 'colspan' attribute</title>
<style>
table,
th,
td {
border: 1px solid black;
}
</style>
</head>
<body>
<!--HTML 'colspan' attribute-->
<p>Example of HTML 'colspan' attribute</p>
<h2>Students Table</h2>
<table>
<tr>
<th colspan="2">Name</th>
<th>Roll No</th>
<th>Gender</th>
</tr>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr>
<td>Revathi</td>
<td>Satya</td>
<td>1</td>
<td>Female</td>
</tr>
<tr>
<td>Aman</td>
<td>Kumar</td>
<td>2</td>
<td>Male</td>
</tr>
</table>
</body>
</html>
Colspan attribute with td tag
Considering the another scenario, where we are going to use the colspan attribute with the td tag.
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML 'colspan' attribute</title>
<style>
table,
th,
td {
border: 1px solid black;
width: 30%;
}
</style>
</head>
<body>
<!--HTML 'colspan' attribute-->
<p>Example of the HTML 'colspan' attribute</p>
<h2>Grocery Bill</h2>
<table>
<tr>
<th>Name</th>
<th>Price</th>
<th>GST</th>
</tr>
<tr>
<td>Bread</td>
<td>50</td>
<td>5</td>
</tr>
<tr>
<td>Eggs</td>
<td>180</td>
<td>10</td>
</tr>
<tr>
<!--colspan with value 2-->
<td colspan="2">Total price(without GST): 230</td>
<td>Total GST: 15</td>
</tr>
<tr>
<!--colspan with value 3-->
<td colspan="3">Total paid price(including GST): 245</td>
</tr>
</table>
</body>
</html>
Supported Browsers
| Attribute | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| colspan | Yes | Yes | Yes | Yes | Yes |




