HTML tables allow us to arrange data in rows and columns on a web page.
We use the
tag to create tables in HTML. A table consists of rows and columns. You can use one or more , |
, and elements to set headers, rows and columns, and table data.
Table rows are defined by
|
tags. For table rows and columns, we use
and tags within the tag respectively.
Example
The following is a sample program to create table rows and columns.
<!DOCTYPE html>
<html>
<style>
table {
border:1px solid black;
padding: 10px;
}
th, td{
border:1px solid black;
padding: 20px;
}
</style>
<body>
<h2>Tables in HTML</h2>
<table style="width: 100%">
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
Copy after login
Example
The following is another example program that creates table rows and columns.
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid green;
}
</style>
</head>
<body>
<h2>Adding table rows and colomns in HTML</h2>
<table>
<tr>
<th>S.no</th>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>Kohli</td>
<td>34</td>
<td>India</td>
</tr>
<tr>
<td>2</td>
<td>Rabada</td>
<td>29</td>
<td>South Africa</td>
</tr>
<tr>
<td>3</td>
<td>Starc</td>
<td>33</td>
<td>Australia</td>
</tr>
</table>
</body>
</html>
Copy after login
Example
Below is another example program for creating table rows and columns.
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid green;
}
</style>
</head>
<body>
<h2>Adding table rows and colomns in HTML</h2>
<table style="width:80%">
<caption>Cricketers...</caption>
<tr style="background-color: Mediumseagreen">
<th>S.no</th>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>Kohli</td>
<td>34</td>
<td>India</td>
</tr>
<tr>
<td>2</td>
<td>Rabada</td>
<td>29</td>
<td>South Africa</td>
</tr>
<tr style="background-color: Mediumseagreen">
<td>3</td>
<td>Starc</td>
<td>33</td>
<td>Australia</td>
</tr>
</table>
</body>
</html>
Copy after login
|
The above is the detailed content of How to create table rows and columns in HTML?. For more information, please follow other related articles on the PHP Chinese website!