Skip to main content

HTML Tables

The HTML tables is used to show your datas, information, etc in an appropriate way.
A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). td stands for “table data,” and holds the content of a data cell. A <td> tag can contain text, links, images, lists, forms, other tables, etc.
To create table, <table> tag is used. An HTML table consists of one or more <tr>, <th> and <td> elements.


  •  <tr> element defines a table row.
  •  <th> element defines a table header.
  •  <td> element defines a table cell.
A more complex HTML table may also include <caption>, <col>, <colgroup>, <thead>, <tfoot>, and <tbody> elements.

Attribute Value Description
align left center right Deprecated. Use styles instead. Specifies the alignment of a table according to surrounding text
bgcolor rgb(x,x,x) #xxxxxx colorname Deprecated. Use styles instead. Specifies the background color for a table
border pixels Specifies the width of the borders around a table
cellpadding pixels Specifies the space between the cell wall and the cell content
cellspacing pixels Specifies the space between cells
frame void above below hsides lhs rhs vsides box border Specifies which parts of the outside borders that should be visible
rules none groups rows cols all Specifies which parts of the inside borders that should be visible
summary text Specifies a summary of the content of a table
width pixels % Specifies the width of a table

HTML code:
<table border="1" align="center" width="200">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
Output:





HTML Table Headers code
<table border="1" width="200">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
Output:






HTML Table Tags
 
Tag Description
<table> Creates a table
<th> Defines a table header
<tr> Defines a table row
<td> Defines a table cell
<caption> Defines a table caption
<colgroup> Defines a group of columns in a table, for formatting
<col /> Defines attribute values for one or more columns in a table
<thead> Groups the header content in a table
<tbody> Groups the body content in a table
<tfoot> Groups the footer content in a table

Table Colspan:
A colspan is used to merge two or more than two columns in a table.
HTML code:
<table align=”center” width=”200″ bgcolor=”#DADADA” border=”1″>
<tr>
<td colspan=2 align=”center”> Namaste</td>
</tr>
<tr>
<td> Column 1</td>
<td>Column 2</td>
</tr>
</table>
Output:





Table Rowspan:
A rowspan is used to merge two or more than two rows in a table.
HTML code:
<table align="center" width="300" bgcolor="#8CC6FF" border="1">
<tr>
<td rowspan="2"> Namaste</td>                                                                                                                               <td> Column 1</td>
</tr>
<tr>
<td> Column 1</td>
</tr>
</table>
Output:




Comments

Popular posts from this blog

MySQL Connection

Connection with MySQL Database Before accessing database, you must create a connection to the database Syntax: mysql_connect(servername,username,password); where, servername specifies the server to connect to. Default value is “localhost” username specifies the username to log in with. Default value is the name of the user that owns the server process. To connect offline we use username “root”. password specifies the password to log in with. Default is “” Code : Creating connection to the database and selecting the required database <?php $con = mysql_connect(“localhost”,”root”,”"); if (!$con) { die(‘Could not connect: ‘ . mysql_error()); } else{ mysql_select_db(“test”, $con) }; ?> Here, we have store connection in a variable called $con and trap error using die function. Closing connection The connection will be closed automatically when the script ends. To close the connection before, use the mysql_close() function: <?php $con = mysql_conne...

Type Juggling and Type Casting

Type Juggling: PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by the context in which the variable is used. That is to say, if a string value is assigned to variable $var, $var becomes a string. If an integer value is then assigned to $var, it becomes an integer.

Doctype Defination

A Document Type Declaration, or DOCTYPE, is an instruction that associates a particular SGML or XML document (for example, a webpage) with a Document Type Definition (DTD). Syntax The general syntax for a document type declaration is: <!DOCTYPE root-element PUBLIC "FPI" ["URI"] [ <!-- internal subset declarations --> ]>