HTML Tables Lists
HTML Tables Lists
BIT 381
HTML Tables
HTML tables allow web developers to arrange data into rows and columns.
By default, the text in <th> elements are bold and centered.
By default, the text in <td> elements are regular and left-aligned.
Define an HTML Table
Define an HTML Table
A simple HTML table:
A simple HTML table:
Table Cells
o Each table cell is defined by a <td> and a </td> tag.
o td stands for table data.
<td>Jill</td>
<style>
table, th, td {
border: 1px solid black;
}
</style>
Collapsed Table Borders
o To avoid having double borders like in the example above, set the CSS border-
collapse property to collapse.
o This will make the borders collapse into a single border
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
Border Color
o With the border-color property, you can set the color of the border.
<style>
th, td {
border-color: #96D4D4;
}</style>
HTML Table - Add Cell Padding
o Cell padding specifies the space between the cell content and its borders.
o If you do not specify a padding, the table cells will be displayed without padding.
o By default the padding is set to 0.
o To set the padding, use the CSS padding property:
<style>
th, td {
padding: 15px;
}</style>
HTML Table - Add Border Spacing
<style>
table {
border-spacing: 30px;
}</style>
HTML Table - Example
HTML Table - Example
<BODY>
<!DOCTYPE html> <H2> Creating a Table with border </H2>
<table>
<HTML> <caption> Employees </caption>
<HEAD> <tr>
<TITLE> BIT 381 </TITLE> <th>Firstname</th>
<th>Lastname</th>
<STYLE> <th>Age</th>
table, th,td { </tr>
<tr>
border: 2px solid black; <td>Mohammad </td>
padding: 20px;} <td>AHMAD</td>
<td>40</td>
table {border-spacing: 15px; } </tr>
th, td { padding: 10px; } <tr>
th {text-align: center; } <td>SHATHA </td>
<td>KHALID</td>
td { text-align: left; } <td>23</td>
</STYLE> </tr>
</table>
</HEAD> </BODY>
</HTML>
HTML Lists
o HTML lists allow web developers to group a set of related items in lists.
o An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
o The list items will be marked with bullets (small black circles) by default:
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Ordered HTML List
o An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
o The list items will be marked with numbers by default:
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
HTML Description Lists
o HTML also supports description lists.
o A description list is a list of terms, with a description of each term.
o The <dl> tag defines the description list, the <dt> tag defines the term (name), and the
<dd> tag describes each term.
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold
drink</dd>
</dl>
HTML Lists - Example
HTML Lists - Example
<!DOCTYPE html> <dl>
<HTML> <dt>Coffee</dt>
<TITLE> BIT381 Lists </TITLE>
<BODY>
<dd>- black hot drink</dd>
<ul> <dt>Milk</dt>
<li>Coffee</li> <dd>- white cold drink</dd>
<li>Tea</li> <dt>Tea</dt>
<li>Milk</li> <dd>- Hot Tea drink with Mint
</ul>
<ol>
</dd>
<li>Coffee</li> </dl>
<li>Tea</li> </BODY>
<li>Milk</li> </HTML>
</ol>