Professional Documents
Culture Documents
Ordered List
1.
2.
3.
4.
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Try it Yourself
Style
Description
list-style-type:disc The list items will be marked with bullets (default)
list-style-type:circle The list items will be marked with circles
list-style-type:square The list items will be marked with squares
list-style-type:none The list items will not be marked
Disc:
<ul style="list-style-type:disc">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Try it Yourself
Circle:
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Try it Yourself
Square:
<ul style="list-style-type:square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Try it Yourself
None:
<ul style="list-style-type:none">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Try it Yourself
Example
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Try it Yourself
Numbers:
<ol type="1">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Try it Yourself
Uppercase Letters:
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Try it Yourself
Lowercase Letters:
<ol type="a">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Try it Yourself
Example
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Try it Yourself
Example
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
Try it Yourself
List items can contain new list, and other HTML elements, like images and links, etc.
Horizontal Lists
HTML lists can be styled in many different ways with CSS.
One popular way, is to style a list to be displayed horizontally:
Example
<!DOCTYPE html>
<html>
<head>
<style>
ul#menu li {
display:inline;
}
</style>
</head>
<body>
<h2>Horizontal List</h2>
<ul id="menu">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>PHP</li>
</ul>
</body>
</html>
Try it Yourself
With a little extra style, you can make it look like a menu:
Example
ul#menu {
padding: 0;
}
ul#menu li {
display: inline;
}
ul#menu li a {
background-color: black;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 4px 4px 0 0;
}
ul#menu li a:hover {
background-color: orange;
}
Try it Yourself
Chapter Summary
Tables
HTML Table Example
Number
1
2
3
4
First Name
Eve
John
Adam
Jill
Last Name
Jackson
Doe
Johnson
Smith
Points
94
80
67
50
They can contain all sorts of HTML elements like text, images, lists, other tables, etc.
Example
<table border="1" style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Try it Yourself
The border attribute is on its way out of the HTML standard! It is better to use CSS.
To add borders, use the CSS border property:
Example
table, th, td {
border: 1px solid black;
}
Try it Yourself
Remember to define borders for both the table and the table cells.
If you want the borders to collapse into one border, add CSS border-collapse:
Example
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
Try it Yourself
Example
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
}
Try it Yourself
Example
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Try it Yourself
To left-align the table headings, use the CSS text-align property:
Example
th {
text-align: left;
}
Try it Yourself
Example
table {
border-spacing: 5px;
}
Try it Yourself
If the table has collapsed borders, border-spacing has no effect.
Example
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
Try it Yourself
Example
<table style="width:100%">
<tr>
<th>Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<td>555 77 855</td>
</tr>
</table>
Try it Yourself
Example
<table style="width:100%">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
Try it Yourself
The <caption> tag must be inserted immediately after the <table> tag.
Example
<table id="t01">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
table#t01 {
width: 100%;
background-color: #f1f1c1;
}
Try it Yourself
Chapter Summary
Images
Example
GIF Images
JPG Images
PNG Images
<!DOCTYPE html>
<html>
<body>
<h2>Spectacular Mountain</h2>
<img src="pic_mountain.jpg" alt="Mountain View" style="width:304px;height:228px;">
</body>
</html>
Try it Yourself
Always specify the width and height of an image. If width and height are not specified, the
page will flicker while the image loads.
The alt attribute provides alternative information for an image if a user for some reason cannot
view it (because of slow connection, an error in the src attribute, or if the user uses a screen
reader).
If a browser cannot find an image, it will display the alt text:
Example
<img src="wrongname.gif" alt="HTML5 Icon" style="width:128px;height:128px;">
Try it Yourself
The alt attribute is required. A web page will not validate correctly without it.
Example
<img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px;">
Try it Yourself
Alternatively, you can use width and height attributes. Here, the values are specified in pixels by
default:
Example
<img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
Try it Yourself
Example
<!DOCTYPE html>
<html>
<head>
<style>
img {
width:100%;
}
</style>
</head>
<body>
<img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px;">
<img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
</body>
</html>
Try it Yourself
Example
<img src="/images/html5.gif" alt="HTML5 Icon" style="width:128px;height:128px;">
Try it Yourself
Example
<img src="http://www.w3schools.com/images/w3schools_green.jpg" alt="W3Schools.com">
Try it Yourself
Animated Images
The GIF standard allows animated images:
Example
<img src="programming.gif" alt="Computer Man" style="width:48px;height:48px;">
Try it Yourself
Note that the syntax of inserting animated images is no different from non-animated images.
Example
<a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;border:0;">
</a>
Try it Yourself
Add "border:0;" to prevent IE9 (and earlier) from displaying a border around the image.
Image Floating
Use the CSS float property to let the image float.
The image can float to the right or to the left of a text:
Example
<p>
<img src="smiley.gif" alt="Smiley face" style="float:right;width:42px;height:42px;">
The image will float to the right of the text.
</p>
<p>
<img src="smiley.gif" alt="Smiley face" style="float:left;width:42px;height:42px;">
The image will float to the left of the text.
</p>
Try it Yourself
Image Maps
Use the <map> tag to define an image-map. An image-map is an image with clickable areas.
The name attribute of the <map> tag is associated with the <img>'s usemap attribute and creates
a relationship between the image and the map.
The <map> tag contains a number of <area> tags, that defines the clickable areas in the imagemap:
Example
<img src="planets.gif" alt="Planets" usemap="#planetmap" style="width:145px;height:126px;">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
<area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
<area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>
Try it Yourself
Chapter Summary
Frames
HTML frames are used to divide your browser window into multiple sections where each section
can load a separate HTML document. A collection of frames in the browser window is known as
a frameset. The window is divided into frames in a similar way the tables are organized: into
rows and columns.
Disadvantages of Frames
There are few drawbacks with using frames, so it's never recommended to use frames in your
webpages:
Some smaller devices cannot cope with frames often because their screen is not big
enough to be divided up.
Sometimes your page will be displayed differently on different computers due to different
screen resolution.
The browser's back button might not work as the user hopes.
There are still few browsers that do not support frame technology.
Creating Frames
To use frames on a page we use <frameset> tag instead of <body> tag. The <frameset> tag
defines how to divide the window into frames. The rows attribute of <frameset> tag defines
horizontal frames and cols attribute defines vertical frames. Each frame is indicated by <frame>
tag and it defines which HTML document shall open into the frame.
Example
Following is the example to create three horizontal frames:
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset rows="10%,80%,10%">
<frame name="top" src="/html/top_frame.htm" />
<frame name="main" src="/html/main_frame.htm" />
<frame name="bottom" src="/html/bottom_frame.htm" />
<noframes>
<body>
Your browser does not support frames.
</body>
</noframes>
</frameset>
</html>
Example
Let's put above example as follows, here we replaced rows attribute by cols and changed their
width. This will create all the three frames vertically:
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames</title>
</head>
<frameset cols="25%,50%,25%">
<frame name="left" src="/html/top_frame.htm" />
<frame name="center" src="/html/main_frame.htm" />
<frame name="right" src="/html/bottom_frame.htm" />
<noframes>
<body>
Your browser does not support frames.
</body>
</noframes>
</frameset>
</html>
Description
specifies how many columns are contained in the frameset and the size of each
column. You can specify the width of each column in one of four ways:
cols
Absolute values in pixels. For example to create three vertical frames, use
cols="100, 500,100".
A percentage of the browser window. For example to create three vertical
frames, use cols="10%, 80%,10%".
Using a wildcard symbol. For example to create three vertical frames, use
cols="10%, *,10%". In this case wildcard takes remainder of the window.
As relative widths of the browser window. For example to create three
vertical frames, use cols="3*,2*,1*". This is an alternative to percentages.
You can use relative widths of the browser window. Here the window is
divided into sixths: the first column takes up half of the window, the
second takes one third, and the third takes one sixth.
This attribute works just like the cols attribute and takes the same values, but it is
used to specify the rows in the frameset. For example to create two horizontal
rows
frames, use rows="10%, 90%". You can specify the height of each row in the
same way as explained above for columns.
This attribute specifies the width of the border of each frame in pixels. For
border
example border="5". A value of zero means no border.
This attribute specifies whether a three-dimensional border should be displayed
frameborder between frames. This attrubute takes value either 1 (yes) or 0 (no). For example
frameborder="0" specifies no border.
This attribute specifies the amount of space between frames in a frameset. This can
framespacing take any integer value. For example framespacing="10" means there should be 10
pixels spacing between each frames.
Description
This attribute is used to give the file name that should be loaded in the frame. Its
src
value can be any URL. For example, src="/html/top_frame.htm" will load an
HTML file available in html directory.
This attribute allows you to give a name to a frame. It is used to indicate which
frame a document should be loaded into. This is especially important when you
name
want to create links in one frame that load pages into an another frame, in which
case the second frame needs a name to identify itself as the target of the link.
frameborder This attribute specifies whether or not the borders of that frame are shown; it
overrides the value given in the frameborder attribute on the <frameset> tag if one
is given, and this can take values either 1 (yes) or 0 (no).
This attribute allows you to specify the width of the space between the left and
marginwidth right of the frame's borders and the frame's content. The value is given in pixels.
For example marginwidth="10".
This attribute allows you to specify the height of the space between the top and
marginheight bottom of the frame's borders and its contents. The value is given in pixels. For
example marginheight="10".
By default you can resize any frame by clicking and dragging on the borders of a
noresize
frame. The noresize attribute prevents a user from being able to resize the frame.
For example noresize="noresize".
This attribute controls the appearance of the scrollbars that appear on the frame.
scrolling
This takes values either "yes", "no" or "auto". For example scrolling="no" means it
should not have scroll bars.
This attribute allows you to provide a link to another page containing a long
longdesc
description of the contents of the frame. For example
longdesc="framedescription.htm"
Here we have created two columns to fill with two frames. The first frame is 200 pixels wide and
will contain the navigation menubar implemented by menu.htm file. The second column fills in
remaining space and will contain the main part of the page and it is implemented by main.htm
file. For all the three links available in menubar, we have mentioned target frame as main_page,
so whenever you click any of the links in menubar, available link will open in main_page.
Following is the content of menu.htm file
<!DOCTYPE html>
<html>
<body bgcolor="#4a7d49">
<a href="http://www.google.com" target="main_page">Google</a>
<br /><br />
<a href="http://www.microsoft.com" target="main_page">Microsoft</a>
<br /><br />
<a href="http://news.bbc.co.uk" target="main_page">BBC News</a>
</body>
</html>
Now you can try to click links available in the left panel and see the result. The target attribute
can also take one of the following values:
Option
Description
_self
_blank
Forms
The <form> Element
HTML forms are used to collect user input.
The <form> element defines an HTML form:
<form>
.
form elements
.
</form>
HTML forms contain form elements.
Form elements are different types of input elements, checkboxes, radio buttons, submit buttons,
and more.
Text Input
Example
<form>
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
Try it Yourself
This is how it will look like in a browser:
First name:
Last name:
Note: The form itself is not visible. Also note that the default width of a text field is 20
characters.
Example
<form>
<input type="radio" name="sex" value="male" checked>Male
<br>
<input type="radio" name="sex" value="female">Female
</form>
Try it Yourself
This is how the HTML code above will be displayed in a browser:
Male
Female
Example
<form action="action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
Try it Yourself
This is how the HTML code above will be displayed in a browser:
First name:
Mickey
Last name:
Mouse
In the example above, a server-side script is specified to handle the submitted form:
<form action="action_page.php">
If the action attribute is omitted, the action is set to the current page.
Example
<form action="action_page.php">
First name:<br>
<input type="text" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
Try it Yourself
Example
<form action="action_page.php">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
Try it Yourself
This is how the HTML code above will be displayed in a browser:
Last name:
Mouse
Description
Specifies the charset used in the submitted form (default: the page charset).
Specifies an address (url) where to submit the form (default: the submitting page).
Specifies if the browser should autocomplete the form (default: on).
Specifies the encoding of the submitted data (default: is url-encoded).
Specifies the HTTP method used when submitting the form (default: GET).
Specifies a name used to identify the form (for DOM usage:
document.forms.name).
Specifies that the browser should not validate the form.
Specifies the target of the address in the action attribute (default: _self).