How to create table rows and columns in HTML?

WBOY
Release: 2023-09-09 13:45:06
forward
1297 people have browsed it

How to create table rows and columns in HTML?

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 tags. For table rows and columns, we use and
,
elements to set headers, rows and columns, and table data.

Table rows are defined by

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template