HOW TO CREATE A TABLE IN HTML AND CSS

HOW TO CREATE A TABLE IN HTML AND CSS

Introduction

You may want to consider using HTML tables in your website. In addition to creating HTML tables to present data in rows and columns, you can also create HTML tables to organize information on your web page.

JavaScript for Beginners

The process of creating an HTML table is similar to the process that you used to create your web page and any elements that you may have already included in your page, such as links or frames. Coding HTML tables into your web page is fairly easy since you need only understand a few basic table codes.

Creating a basic table

The basic structure of an HTML table consists of the following tags:

  • Table tags:
  • Row tags:
  • Cell tags:

Constructing an HTML table consists of describing the table between the beginning table tag, , and the ending table table tag,

Between these tags, you then construct each row and each cell in the row. To do this, you would first start the row with the beginning row tag, , and then build the row by creating each cell with the beginning cell tag, , adding the data for that cell, and then closing the cell with the ending cell tag, . When you finish all of the cells for a row, you would then close the row with the ending row tag, .Then, for each new row, you would repeat the process of beginning the row, building each cell in the row, and closing the row.

READ ALSO » HTML103: HOW TO CREATE A TABLE IN HTML AND CSS

The following table is an example of a basic table with three rows and two columns of data.

S/NNameCountryGender
1BOMAUSAMale
2OPTIMISTCANADAMale
3OLAUKFemale
4YUSUFMEXICONULL
5HENRYLONDONMale
6VICKYSPAINFemale
7BOSEINDIAFemale

border and border-collapse to Create the Initial Table Style

The first step to styling a table is understanding some of the browser default styles and behaviors. This section will cover the border property and the border-collapse property, and show how to create a boundary line between cells.

To begin styling your table, create and open a file named styles.css in your text editor, in the same folder as index.html. Add a selector group consisting of a th element selector and a td element selector. Then, in the selector block, add a border property with a value of 1px solid black, as shown in the following code above.