Thursday 18 February 2016

HTML TABLE

HTML table tag is used to display data in tabular form (row * column). There can be many columns in a row.
HTML tables are used to manage the layout of the page e.g. header section, navigation bar, body content, footer section etc. But it is recommended to use div tag over table to manage the layout of the page .

HTML Table Tags

Tag
Description
<table>
It defines a table.
<tr>
It defines a row in a table.
<th>
It defines a header cell in a table.
<td>
It defines a cell in a table.
<caption>
It defines the table caption.
<colgroup>
It specifies a group of one or more columns in a table for formatting.
<col>
It is used with <colgroup> element to specify column properties for each column.
<tbody>
It is used to group the body content in a table.
<thead>
It is used to group the header content in a table.
<tfooter>
It is used to group the footer content in a table.

HTML Table Example

Let's see the example of HTML table tag. It output is shown above.

  1. <table>  
  2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>  
  3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>  
  4. <tr><td>James</td><td>William</td><td>80</td></tr>  
  5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>  
  6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>  
  7. </table>  


HTML Table with Border

There are two ways to specify border for HTML tables.
  1. By border attribute of table in HTML
  2. By border property in CSS

1) HTML Border attribute

You can use border attribute of table tag in HTML to specify border. But it is not recommended now.

  1. <table border="1">  
  2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>  
  3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>  
  4. <tr><td>James</td><td>William</td><td>80</td></tr>  
  5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>  
  6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>  
  7. </table>  

2) CSS Border property

It is now recommended to use border property of CSS to specify border in table.

  1. <style>  
  2. table, th, td {  
  3.     border: 1px solid black;  
  4. }  
  5. </style>  


HTML Table with cell padding

You can specify padding for table header and table data by two ways:
  1. By cellpadding attribute of table in HTML
  2. By padding property in CSS
The cellpadding attribute of HTML table tag is obselete now. It is recommended to use CSS. So let's see the code of CSS.

  1. <style>  
  2. table, th, td {  
  3.     border: 1px solid pink;  
  4.     border-collapse: collapse;  
  5. }  
  6. th, td {  
  7.     padding: 10px;  
  8. }  
  9. </style>  


HTML Lists

HTML Lists are used to specify lists of information. All lists may contain one or more list elements. There are three different types of HTML lists:
  1. Ordered List or Numbered List (ol)
  2. Unordered List or Bulleted List (ul)
  3. Description List or Definition List (dl)

HTML Ordered List or Numbered List

In the ordered HTML lists, all the list items are marked with numbers. It is known as numbered list also. The ordered list starts with <ol> tag and the list items start with <li> tag.

  1. <ol>  
  2.  <li>Aries</li>  
  3.  <li>Bingo</li>  
  4.  <li>Leo</li>  
  5.  <li>Oracle</li>  
  6. </ol>  


HTML Description List or Definition List

HTML Description list is also a list style which is supported by HTML and XHTML. It is also known as definition list where entries are listed like a dictionary or encyclopedia.
The definition list is very appropriate when you want to present glossary, list of terms or other name-value list.
The HTML definition list contains following three tags:
  1. <dl> tag defines the start of the list.
  2. <dt> tag defines a term.
  3. <dd> tag defines the term definition (description).

  1. <dl>  
  2.   <dt>Aries</dt>  
  3.   <dd>-One of the 12 horoscope sign.</dd>  
  4.   <dt>Bingo</dt>  
  5.   <dd>-One of my evening snacks</dd>  
  6.  <dt>Leo</dt>  
  7.  <dd>-It is also an one of the 12 horoscope sign.</dd>  
  8.   <dt>Oracle</dt>  
  9.   <dd>-It is a multinational technology corporation.</dd>   
  10. </dl>  

No comments:

Post a Comment