Basic Table

In HTML, a table is used to display data in rows and columns. The <table> tag is used to create a table, and it contains rows (<tr>) and cells (<td> for data, <th> for headers).

Basic Table Structure

<table border="1">
    <tr>
        <th>Name</th>
        <th>Age</th>
        <th>City</th>
    </tr>
    <tr>
        <td>Alice</td>
        <td>25</td>
        <td>New York</td>
    </tr>
    <tr>
        <td>Bob</td>
        <td>30</td>
        <td>London</td>
    </tr>
</table>

Output:

NameAgeCity
Alice25New York
Bob30London

Attributes of <table> in HTML

AttributeDescriptionExample
borderAdds a border around the table & cells<table border="1">
cellpaddingSpace inside a cell between text & border<table cellpadding="10">
cellspacingSpace between cells<table cellspacing="5">
widthDefines the table width (in pixels or %)<table width="80%">
heightDefines the table height (in pixels or %)<table height="300px">
alignAligns the table (left, center, right)<table align="center">
bgcolorSets the background color of the table<table bgcolor="lightblue">

Attributes of <tr> (Table Row)

AttributeDescriptionExample
alignAligns text (left, center, right)<tr align="center">
bgcolorSets background color for a row<tr bgcolor="yellow">
valignAligns content vertically (top, middle, bottom)<tr valign="top">

Attributes of <td> and <th> (Table Cells)

AttributeDescriptionExample
colspanMerges multiple columns<td colspan="2">Merged</td>
rowspanMerges multiple rows<td rowspan="2">Merged</td>
widthSets the width of a cell<td width="100px">
heightSets the height of a cell<td height="50px">
alignAligns text (left, center, right)<td align="center">
valignAligns content vertically (top, middle, bottom)<td valign="top">
Qus. 1 : Which of the following tag is used to add rows in the table?

  1. <td> and </td>
  2. <th> and </th>
  3. <tr> and </tr>
  4. None of the above
Qus. 2 : What will be added by using <td></td> tag ?

  1. cell
  2. row
  3. step
  4. column
Qus. 3 : Which of these tags are all <table> tags?

  1. <table><head><tfoot>
  2. <table><tr><td>
  3. <table><tr><tt>
  4. <thead><body><tr>
Qus. 4 : Which tag allow you to add a row in a table?

  1. <td> and </td>
  2. <row> and </row>
  3. <th> and </th>
  4. <tr> and </tr>
Qus. 5 : The __________ attribute adds space within each cell.

  1. Cell Spacing
  2. Cell Padding
  3. Width
  4. Align
Qus. 6 : Which of the following is not the element associated with the HTML table layout?

  1. alignment
  2. color
  3. size
  4. spanning
Qus. 7 : Which of the following HTML tag is used to add a row in a table?

  1. <th>
  2. <td>
  3. <tr>
  4. <tt>
Qus. 8 : TD tag is used for?

  1. Table row
  2. Table Records
  3. Table heading
  4. Row Heading
Qus. 9 : The HTML tags that create a table header are

  1. <head></head>
  2. <ttop></ttop>
  3. <th></th>
  4. <td></td>
Qus. 10 : What is cell padding?

  1. Used to separate cell walls from their contents
  2. Used to set space between cells
  3. Both a and b above
  4. Used to provide width to a cell
Qus. 11 : What does the <th> tag in HTML stand for

  1. Table header
  2. Table column
  3. Table row
  4. Table

Programs

html program to display a table with 5 rows and 4 columns. Provide appropriate heading to the form

View Solution


HTML Page to display the following table

View Solution


HTML Code design Time Table using rowspan and colspan

View Solution


HTML Code design complex Time Table using rowspan and colspan

View Solution


HTML Code to Design Basic Table

View Solution


html code to design the complex table with rowspan and colspan

View Solution


html table for Indian Tourist Spots

View Solution


Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad