The following example code demonstrates How to Create Tables in HTML.
In order to create tables in HTML, we use the <table> tag. Within the <table> tag, we use <tr> tag to create a row. Whereas, the <td> tag is used to create a column. In order to create a cell that spans more than one column, we use the colspan attribute in the <td> tag. Similarly, we can use the rowspan attribute, if a cell spans for more than one row.
Example Code to Create Tables in HTML that Uses Rowspan and Colspan
In the following example, we create a table with a specified height and width using the height and width attributes respectively. Also, there is cellpadding attribute that indicates the distance between the cell content and the border of the cell.
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<div style="margin: 50px;">
<center><h1>HTML Table</h1>
<table border="1" width="800" height="400" cellpadding="20" style="text-align: center;">
<tr>
<td colspan="2">Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
<tr>
<td rowspan="3">Cell 4</td>
<td>Cell 5</td>
<td>Cell 6</td>
<td>Cell 7</td>
</tr>
<tr>
<td colspan="3">Cell 8</td>
</tr>
<tr>
<td>Cell 9</td>
<td colspan="2">Cell 10</td>
</tr>
<table></center>
</div>
</body>
</html>
Output
Further Reading
Evolution of JavaScript from ES1 to ES2020
Introduction to HTML DOM Methods in JavaScript
Understanding Document Object Model (DOM) in JavaScript
Understanding HTTP Requests and Responses
What is Asynchronous JavaScript?
JavaScript Code for Event Handling
- AI
- Android
- Angular
- ASP.NET
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Data Visualization
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- ES6
- Extended Reality
- Flutter and Dart
- Full Stack Development
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- Tkinter
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML