Curriculum
Course: HTML Basic
Login

Curriculum

HTML Basic

HTML Introduction

0/1

HTML Editors

0/1

HTML Elements

0/1

HTML Attributes

0/1

HTML Headings

0/1

HTML Paragraphs

0/1

HTML Styles

0/1

HTML Formatting

0/1

HTML Quotation

0/1

HTML Comments

0/1

HTML Colors

0/1

HTML Favicon

0/1

HTML Page Title

0/1

HTML Block and Inline

0/1

HTML Iframes

0/1

HTML Java Script

0/1

HTML File Paths

0/1

HTML - The Head Element

0/1

HTML Style Guide

0/1

HTML Entities

0/1

HTML Symbols

0/1
Text lesson

Table Headers

HTML Table Headers

HTML tables may include headers for individual columns or rows, or for multiple columns/rows.

IMG_3836

HTML Table Headers

Table headers are designated using th elements, with each th element representing a cell within the table.

Example

<table>
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
</table>

 

Click to Learn

 

Vertical Table Headers

To utilize the first column as table headers, designate the first cell in each row as a <th> element.

Example

<table>
  <tr>
    <th>Firstname</th>
    <td>Jill</td>
    <td>Eve</td>
  </tr>
  <tr>
    <th>Lastname</th>
    <td>Smith</td>
    <td>Jackson</td>
  </tr>
  <tr>
    <th>Age</th>
    <td>94</td>
    <td>50</td>
  </tr>
</table>

 

Click to Learn

 

Align Table Headers

As a default, table headers are both bold and centered.

Firstname

Lastname

Age

Jill

Smith

50

Eve

Jackson

94

To align the headers of the table to the left, apply the CSS text-align property.

Example

th {
  text-align: left;
}

Header for Multiple Columns

You can create a header that extends across two or more columns.

Name Age
Jill Smith 50
Eve Jackson 94

To achieve this, apply the colspan attribute to the <th> element.   

Example

<table>
  <tr>
    <th colspan=”2″>Name</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
</table>

Table Caption

You have the option to include a caption that acts as a title for the entire table.

                           Monthly savings

IMG_3837

For adding a caption to a table, utilize the <caption> tag.

Example

<table style=”width:100%”>
  <caption>Monthly savings</caption>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$50</td>
  </tr>
</table>

Note: Place the <caption> tag immediately following the <table> tag.