Examples
Tables
This example demonstrates how to create tables in an HTML document.

Table borders
This example demonstrates different table borders.

More Examples


--------------------------------------------------------------------------------

Tables
Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). The letters td stands for "table data," which is the content of a data cell. A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables, etc.

<table border="1">
<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>
 

How it looks in a browser:

row 1, cell 1 row 1, cell 2 
row 2, cell 1 row 2, cell 2 


--------------------------------------------------------------------------------

Tables and the Border Attribute
If you do not specify a border attribute the table will be displayed without any borders. Sometimes this can be useful, but most of the time, you want the borders to show. 

To display a table with borders, you will have to use the border attribute:

<table border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>
 


--------------------------------------------------------------------------------

Headings in a Table
Headings in a table are defined with the <th> tag.

<table border="1">
<tr>
<th>Heading</th>
<th>Another Heading</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>
 

How it looks in a browser:

Heading Another Heading 
row 1, cell 1 row 1, cell 2 
row 2, cell 1 row 2, cell 2 


--------------------------------------------------------------------------------

Empty Cells in a Table
Table cells with no content are not displayed very well in most browsers.

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td></td>
</tr>
</table>
 

How it looks in a browser:

row 1, cell 1 row 1, cell 2 
row 2, cell 1  

Note that the borders around the empty table cell is missing.

To avoid this, add a non-breaking space (&nbsp;) to empty data cells, to make the borders visible: 

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>&nbsp;</td>
</tr>
</table>
 

How it looks in a browser:

row 1, cell 1 row 1, cell 2 
row 2, cell 1   


--------------------------------------------------------------------------------

Basic Notes - Useful Tips
The <thead>,<tbody> and <tfoot> elements are seldom used, because of bad browser support. Expect this to change in future versions of XHTML. If you have Internet Explorer 5.0 or newer, you can view a working example from our XML School.


--------------------------------------------------------------------------------

More Examples
Table with no border
This example demonstrates a table with no borders.

Headings in a table
This example demonstrates how to display table headers.

Empty cells
This example demonstrates how to use "&nbsp;" to handle cells that have no content.

Table with a caption
This example demonstrates a table with a caption.

Table cells that spans more than one row/column
This example demonstrates how to define table cells that spans more than one row or one column.

Tags inside a table
This example demonstrates how to display elements inside other elements.

Cell padding
This example demonstrates how to use cellpadding to create more white space between the cell content and its borders.

Cell spacing
This example demonstrates how to use cellspacing to increase the distance between the cells.

Add a background color or a background image to a table
This example demonstrates how to add a background to a table.

Add a background color or a background image to a table cell
This example demonstrates how to add a background to one or more table cells.

Align the content in a table cell
This example demonstrates how to use the "align" attribute to align the content of cells, to create a "nice-looking" table.

The frame attribute
This example demonstrates how to use the "frame" attribute to control the borders around the table.


--------------------------------------------------------------------------------

Table Tags:
NN: Netscape, IE: Internet Explorer, W3C: Web Standard

Start Tag NN IE W3C Purpose 
<table> 3.0 3.0 3.2  Defines a table 
<th> 3.0 3.0 3.2 Defines a table header 
<tr> 3.0 3.0 3.2 Defines a table row 
<td> 3.0 3.0 3.0 Defines a table cell 
<caption> 3.0 3.0 3.2 Defines a table caption 
<colgroup>   3.0 4.0  Defines groups of table columns 
<col>   3.0 4.0 Defines the attribute values for one or more columns in a table 
<thead>   4.0 4.0 Defines a table header that will not scroll 
<tbody>   4.0 4.0 Defines a table body that scrolls within a fixed table header and table footer  
<tfoot>   4.0 4.0 Defines a table footer that will not scroll  


HTML LISTS/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Examples
An unordered list
This example demonstrates an unordered list.

An ordered list
This example demonstrates an ordered list.

More Examples


--------------------------------------------------------------------------------

Unordered Lists
An unordered list is a list of items. The list items are marked with bullets (typically small black circles).

An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.

<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>
 

Here is how it looks in a browser:

Coffee 
Milk 
Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc.


--------------------------------------------------------------------------------

Ordered Lists
An ordered list is also a list of items. The list items are marked with numbers.

An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.

<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>
 

Here is how it looks in a browser:

Coffee 
Milk 
Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc.


--------------------------------------------------------------------------------

Definition Lists
A definition list is not a list of items. This is a list of terms and explanation of the terms.

A definition list starts with the <dl> tag. Each definition-list term starts with the <dt> tag. Each definition-list definition starts with the <dd> tag.

<dl>
<dt>Coffee</dt>
<dd>Black hot drink</dd>
<dt>Milk</dt>
<dd>White cold drink</dd>
</dl>
 

Here is how it looks in a browser:

Coffee 
Black hot drink 
Milk 
White cold drink 
Inside a definition-list definition (the <dd> tag) you can put paragraphs, line breaks, images, links, other lists, etc.


--------------------------------------------------------------------------------

Examples
Different types of ordered lists
This example demonstrates different types of ordered lists.

Different types of unordered Lists
This example demonstrates different types of unordered lists.

Nested list
This example demonstrates how you can nest lists.

Definition list
This example demonstrates a definition list.


--------------------------------------------------------------------------------

List Tags:
NN: Netscape, IE: Internet Explorer, W3C: Web Standard

Start Tag NN IE W3C Purpose 
<ol> 3.0 3.0 3.2  Defines an ordered list 
<ul> 3.0 3.0 3.2  Defines an unordered list 
<li> 3.0 3.0 3.2 Defines a list item 
<dl> 3.0 3.0 3.2  Defines a definition list 
<dt> 3.0 3.0 3.2 Defines a definition term 
<dd> 3.0 3.0 3.2  Defines a definition description 
<dir>       Deprecated. Use <ul> instead 
<menu>       Deprecated. Use <ul> instead 


HTML FORMS &INPUTS////////////////////////////////////////////////////////////////////////////////////////////////

Examples
Text fields
This example demonstrates how to create text fields on a HTML page. A user can write text in a text field.

Password fields
This example demonstrates how to create a password field on a HTML page.

More Examples


--------------------------------------------------------------------------------

Forms
A form is an area that can contain form elements.

Form elements are elements that allow the user to enter information (like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc.) in a form.

A form is defined with the <form> tag.

<form>
  <input>
  <input>
</form>
 


--------------------------------------------------------------------------------

Input
The most used form tag is the <input> tag. The type of input is specified with the type attribute. The most commonly used input types are explained below.

Text Fields
Text fields are used when you want the user to type letters, numbers, etc. in a form.

<form>
First name: 
<input type="text" name="firstname">
<br>
Last name: 
<input type="text" name="lastname">
</form>
 

How it looks in a browser:

First name:  
Last name:  
Note that the form itself is not visible. Also note that in most browsers, the width of the text field is 20 characters by default.  

Radio Buttons
Radio Buttons are used when you want the user to select one of a limited number of choices.

<form>
<input type="radio" name="sex" value="male"> Male
<br>
<input type="radio" name="sex" value="female"> Female
</form>
 

How it looks in a browser:

 Male 
 Female 
Note that only one option can be chosen. 

Checkboxes 
Checkboxes are used when you want the user to select one or more options of a limited number of choices.

<form>
<input type="checkbox" name="bike" value="yes">
I have a bike
<br>
<input type="checkbox" name="car" value="yes">
I have a car
</form>
 

How it looks in a browser:

 I have a bike 
 I have a car 

--------------------------------------------------------------------------------

The Form's Action Attribute and the Submit Button
When the user clicks on the "Submit" button, the content of the form is sent to another file. The form's action attribute defines the name of the file to send the content to. The file defined in the action attribute usually does something with the received input.

<form name="input" action="html_form_action.asp"
method="get">
Username: 
<input type="text" name="user">
<input type="submit" value="Submit">
</form>
 

How it looks in a browser:

Username:   
If you type some characters in the text field above, and click the "Submit" button, you will send your input to a page called "html_form_action.asp". That page will show you the received input. 


--------------------------------------------------------------------------------

More Examples
Checkboxes
This example demonstrates how to create check-boxes on a HTML page. A user can select or unselect a checkbox.

Radiobuttons
This example demonstrates how to create radio-buttons on a HTML page.

Simple drop down box
This example demonstrates how to create a simple drop-down box on a HTML page. A drop-down box is a selectable list.

Another drop down box
This example demonstrates how to create a simple drop-down box with a pre-selected value.

Textarea
This example demonstrates how to create a text-area (a multi-line text input control). A user can write text in the text-area. In a text-area you can write an unlimited number of characters.

Create a button
This example demonstrates how to create a button. On the button you can define your own text.

Fieldset around data
This example demonstrates how to draw a border with a caption around your data.

Form Examples
Form with an input field and a submit button
This example demonstrates how to add a form to a page. The form contains an input field and a submit button.

Form with checkboxes
This form contains two checkboxes, and a submit button.

Form with radiobuttons
This form contains two radio buttons, and a submit button.

Send a mail from a form
This example demonstrates how to send a mail from a form.


--------------------------------------------------------------------------------

Form Tags:
NN: Netscape, IE: Internet Explorer, W3C: Web Standard

Start Tag NN IE W3C Purpose 
<form> 3.0 3.0 3.2  Defines a form for user input 
<input> 3.0 3.0 3.2 Defines an input field 
<textarea> 3.0 3.0 3.2  Defines a text-area (a multi-line text input control) 
<label>   4.0 4.0  Defines a label to a control 
<fieldset>   4.0 4.0 Defines a fieldset 
<legend>   4.0 4.0  Defines a caption for a fieldset 
<select> 3.0 3.0 3.2  Defines a selectable list (a drop-down box) 
<optgroup> 6.0   4.0  Defines an option group 
<option> 3.0 3.0 3.2  Defines an option in the drop-down box 
<button>   4.0 4.0 Defines a push button 
<isindex>       Deprecated. Use <input> instead 

HTML IMAGES/////////////////////////////////////////////////////////////////////////////////////////////////////////////

Examples
Insert images
This example demonstrates how to display images in your Web page.

Insert images from different locations
This example demonstrates how to display images from another folder or another server in your Web page.

More Examples


--------------------------------------------------------------------------------

The Image Tag and the Src Attribute 
In HTML, images are defined with the <img> tag.  

The <img> tag is empty, which means that it contains attributes only and it has no closing tag. 

To display an image on a page, you need to use the src attribute. Src stands for "source". The value of the src attribute is the URL of the image you want to display on your page. 

The syntax of defining an image:

<img src="url">
 

The URL points to the location where the image is stored. An image named "boat.gif" located in the directory "images" on "www.w3schools.com" has the URL: http://www.w3schools.com/images/boat.gif. 

The browser puts the image where the image tag occurs in the document. If you put an image tag between two paragraphs, the browser shows the first paragraph, then the image, and then the second paragraph. 


--------------------------------------------------------------------------------

The Alt Attribute 
The alt attribute is used to define an "alternate text" for an image. The value of the alt attribute is an author-defined text: 

<img src="boat.gif" alt="Big Boat">
 

The "alt" attribute tells the reader what he or she is missing on a page if the browser can't load images. The browser will then display the alternate text instead of the image. It is a good practice to include the "alt" attribute for each image on a page, to improve the display and usefulness of your document for people who have text-only browsers. 


--------------------------------------------------------------------------------

Basic Notes - Useful Tips
If an HTML file contains ten images - eleven files are required to display the page right. Loading images take time, so my best advice is: Use images carefully. 


--------------------------------------------------------------------------------

More Examples
Aligning images
This example demonstrates how to align an image within the text.

Let the image float
This example demonstrates how to let an image float to the left or right of a paragraph.

Adjust images to different sizes
This example demonstrates how to adjust images to different sizes.

Display an alternate text for an image
This example demonstrates how to display an alternate text for an image. The "alt" attribute tells the reader what he or she is missing on a page if the browser can't load images. It is a good practice to include the "alt" attribute for each image on a page.

Make a hyperlink of an image
This example demonstrates how to use an image as a link.

Create an image-map
This example demonstrates how to create an image-map, with click-able regions. Each of the regions are hyperlinks.


--------------------------------------------------------------------------------

Image Tags:
NN: Netscape, IE: Internet Explorer, W3C: Web Standard

Start Tag NN IE W3C Purpose 
<img> 3.0 3.0 3.2 Defines an image 
<map> 3.0 3.0 3.2 Defines an image map 
<area> 3.0 3.0 3.2 Defines an area inside an image map 

HTML Backgrounds
 
--------------------------------------------------------------------------------
 
A good background can make a Web site look really great.


--------------------------------------------------------------------------------

Examples
Good background and text color
An example of a background color and a text color that makes the text on the page easy to read.  

Bad background and text color
An example of a background color and a text color that makes the text on the page difficult to read.  

More Examples 


--------------------------------------------------------------------------------

Backgrounds
The <body> tag has two attributes where you can specify backgrounds. The background can be a color or an image.

Bgcolor
The bgcolor attribute sets the background to a color. The value of this attribute can be a hexadecimal number, an RGB value, or a color name.

<body bgcolor="#000000">
<body bgcolor="rgb(0,0,0)">
<body bgcolor="black">
 

The lines above all sets the background color to black. 

Background
The background attribute sets the background to an image. The value of this attribute is the URL of the image you want to use. If the image is smaller than the browser window, the image will repeat itself until it fills the entire browser window.

<body background="clouds.gif">
<body background="http://www.w3schools.com/clouds.gif">
 

The URL can be relative (as in the first line above) or absolute (as in the second line above).

Note: If you want to use a background image, you should keep in mind:

Will the background image increase the loading time too much? Tip: Image files should be maximum 10k 
Will the background image look good with other images on the page? 
Will the background image look good with the text colors on the page? 
Will the background image look good when it is repeated on the page? 
Will the background image take away the focus from the text? 

--------------------------------------------------------------------------------

Basic Notes - Useful Tips
The bgcolor, background, and the text attributes in the <body> tag is deprecated in the latest versions of HTML (HTML 4 and XHTML). The World Wide Web Consortium (W3C) has removed these attributes from its recommendations. In future versions of HTML, style sheets (CSS) will be used to define the layout and display properties of HTML elements. 

Few of the most visited web sites use background images.

The most used background colors are: white, black and gray.


--------------------------------------------------------------------------------

More Examples
Good background image
An example of a background image and a text color that makes the text on the page easy to read.  

Good background image 2
An example of a background image and a text color that makes the text on the page easy to read.  

Bad background image
An example of a background image and a text color that makes the text on the page very difficult to read.  

HTML BACKGROUND



