3 Html Content And Tables

Web Technology I · Unit 3

HTML Content and Tables

Exam-focused notes for HTML Content and Tables (Web Technology I, BIT251): what the TU syllabus asks and how it has actually been tested, with 3 solved past questions from this unit.

HTML Content and Tables in short

This chapter covers the HTML tags used to present lists, tables, special characters and links. These are used in almost every web page.

HTML Content and Tables: notes

HTML lists ordered and unordered

A list groups related items. HTML has three kinds.

  • Unordered list <ul>: items shown with bullets.
  • Ordered list <ol>: items shown with numbers or letters.
  • Description list <dl>: terms <dt> with descriptions <dd>.

Each item in <ul> and <ol> goes inside an <li> tag.

<ul>
  <li>HTML</li>
  <li>CSS</li>
</ul>

<ol type="A" start="3">
  <li>Compile</li>
  <li>Run</li>
</ol>

<dl>
  <dt>HTTP</dt>
  <dd>Protocol for the web</dd>
</dl>

The type attribute of <ol> can be 1, a, A, i or I. The start attribute sets the first number. Lists can be nested by placing a new list inside an <li>.

HTML table structure and attributes

A table shows data in rows and columns. The main tags are shown below.

TagPurpose
<table>Creates the table
<tr>A table row
<th>A header cell, bold and centred by default
<td>A data cell
<caption>Title of the table
<thead>, <tbody>, <tfoot>Group header, body and footer rows

Important attributes are given below.

  • colspan makes a cell span several columns.
  • rowspan makes a cell span several rows.
  • border, cellpadding and cellspacing are older presentation attributes. Use CSS instead.
<table border="1">
  <caption>Marks</caption>
  <thead>
    <tr><th>Name</th><th colspan="2">Marks</th></tr>
  </thead>
  <tbody>
    <tr><td>Ram</td><td>40</td><td>45</td></tr>
    <tr><td>Sita</td><td rowspan="1">50</td><td>48</td></tr>
  </tbody>
</table>

What this unit covers

  • HTML lists ordered and unordered
  • HTML table structure and attributes
  • Table borders and styling
  • HTML entities and special characters
  • HTML links and anchors

HTML table structure and attributes

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 ] [5]

Show solved answer

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
Open this answer on its own page →

0 · 10 marks

Write HTML script to generate following output. Create a table like below. Set link to www.facebook.com in the text "Null". The title of your HTML page should be "Test". The table should be in a div having id dv1. (explanation: The below table is about the use of rows and columns, use of rows , use of subscript and supescript)[10]

Based on the question description, the table contains: - A title "Test" for the HTML page - A table inside a div with id="dv1" - Use of rowspan and colspan - Use of subscript (<sub) and superscript (<sup) - A hyperlink to www.facebook.com on the text "Null" --- --- Tag / Attribute Purpose ------ ...

Open this answer on its own page →

HTML entities and special characters

2080.2 · 5 marks

Write HTML script to display following output in a division under body section. a) The ampersand (and) sign: & b.) equation $3x^2 + 2x_1 y < 4$. $45 < > 30$ [5]

The question requires displaying special characters and mathematical expressions using HTML entities in a <div under the <body section. Symbol HTML Entity -------------------- & (ampersand) & < (less than) < (greater than) > Superscript <sup tag Subscript <sub tag --- --- --- Code Used ...

Open this answer on its own page →