2079 12

BIT251 ยท 2079 ยท 5 marks

What is table in HTML? Create a HTML page containing a DIV with name "divtb". The divtb should contain a table as below[Note the border should be dotted ]

What is table in HTML? Create a HTML page containing a DIV with name "divtb". The divtb should contain a table as below[Note the border should be dotted ] [5]

Web Technology IChapter 3: HTML Content and TablesHTML table structure and attributes

Quick answer

An HTML table is a structured way to display data in rows and columns format. Tables are created using the <table> tag along with several related tags: id="divtb" is used to identify the element; border; border-collapse.

HTML Table - Model Answer

What is a Table in HTML?

An HTML table is a structured way to display data in rows and columns format. Tables are created using the <table> tag along with several related tags:

TagDescription
<table>Defines the table
<tr>Defines a table row
<th>Defines a table header cell (bold & centered by default)
<td>Defines a table data cell
<caption>Defines a table caption/title

Tables are used to organize and present data in a grid-like structure on a webpage.


HTML Page with DIV "divtb" containing a Dotted Border Table

<!DOCTYPE html>
<html>
  <head>
    <title>HTML Table Example</title>
    <style>
      #divtb {
        width: 50%;
        margin: 20px auto;
      }

      #divtb table {
        width: 100%;
        border-collapse: collapse;
      }

      #divtb table, 
      #divtb th, 
      #divtb td {
        border: 2px dotted black;
        padding: 8px;
        text-align: center;
      }

      #divtb th {
        background-color: #cccccc;
      }
    </style>
  </head>
  <body>

    <div id="divtb">
      <table>
        <caption><strong>Student Table</strong></caption>
        <tr>
          <th>S.N.</th>
          <th>Name</th>
          <th>Age</th>
          <th>Address</th>
        </tr>
        <tr>
          <td>1</td>
          <td>Ram</td>
          <td>20</td>
          <td>Kathmandu</td>
        </tr>
        <tr>
          <td>2</td>
          <td>Sita</td>
          <td>22</td>
          <td>Pokhara</td>
        </tr>
        <tr>
          <td>3</td>
          <td>Hari</td>
          <td>21</td>
          <td>Chitwan</td>
        </tr>
      </table>
    </div>

  </body>
</html>

Key Points to Note

  • id="divtb" is used to identify the <div> element
  • border: 2px dotted black applies the dotted border to the table, <th>, and <td> elements
  • border-collapse: collapse ensures borders between cells are merged into a single border
  • <th> tags are used for header row (S.N., Name, Age, Address)
  • <td> tags are used for data rows

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.