Step-By-Step HTML Tutorial - Advanced
Step-By-Step HTML Tutorial - Advanced
Credits: http://www.w3schools.com/
About: This is a step-by-step, easy-to-follow manual for those who want to learn advanced
level HTML to develop web pages. It has been compiled from http://www.w3schools.com/ in
a book format for the benefit of those who have slow or no access to the internet and also for
those who would like to have a handy copy with them as a reference.
HTML ADVANCED
Table of Contents
HTML Layout..........................................................................................................................................4
Examples........................................................................................................................................5
Frames...............................................................................................................................................5
The Frameset Tag..............................................................................................................................5
The Frame Tag...................................................................................................................................6
Basic Notes - Useful Tips....................................................................................................................6
More Examples.............................................................................................................................6
Frame Tags........................................................................................................................................9
HTML Fonts............................................................................................................................................9
Examples..........................................................................................................................................13
How to Use Styles............................................................................................................................13
Page 1 of 32
External Style Sheet.....................................................................................................................13
Internal Style Sheet......................................................................................................................13
Inline Styles..................................................................................................................................14
Style Tags.........................................................................................................................................14
HTML Character Entities......................................................................................................................14
Character Entities............................................................................................................................14
Non-breaking Space.........................................................................................................................15
Try It Yourself..................................................................................................................................15
Commonly Used Character Entities.................................................................................................15
HTML Head..........................................................................................................................................16
Examples..........................................................................................................................................16
The Head Element...........................................................................................................................16
Information Inside the Head Element..............................................................................................16
Head Tags........................................................................................................................................17
HTML Meta..........................................................................................................................................17
Examples..........................................................................................................................................17
The Meta Element...........................................................................................................................18
Keywords for Search Engines...........................................................................................................18
Unknown Meta Attributes...............................................................................................................18
HTML Uniform Resource Locators.......................................................................................................19
HTML Links......................................................................................................................................19
URL - Uniform Resource Locator......................................................................................................19
URL Schemes...................................................................................................................................19
Accessing a Newsgroup...................................................................................................................20
Downloading with FTP.....................................................................................................................20
Link to your Mail system..................................................................................................................20
HTML Scripts........................................................................................................................................21
Examples..........................................................................................................................................21
Insert a Script into HTML Page.........................................................................................................21
How to Handle Older Browsers.......................................................................................................21
Example.......................................................................................................................................22
The <noscript> Tag..........................................................................................................................22
Example.......................................................................................................................................22
Page 2 of 32
Script Tags.......................................................................................................................................23
HTML 4.0 Standard Attributes.............................................................................................................23
Core Attributes................................................................................................................................23
Language Attributes.........................................................................................................................24
Keyboard Attributes.........................................................................................................................24
HTML 4.0 Event Attributes...................................................................................................................24
Window Events................................................................................................................................24
Form Element Events.......................................................................................................................25
Keyboard Events..............................................................................................................................25
Mouse Events..................................................................................................................................25
HTML URL Encoding.............................................................................................................................26
HTML Summary...............................................................................................................................30
Now You Know HTML, What's Next?...............................................................................................30
Page 3 of 32
HTML Layout
Everywhere on the Web you will find pages that are formatted like newspaper pages
using HTML columns.
One very common practice with HTML, is An HTML <table> is used to divide a part
to use HTML tables to format the layout of of this Web page into two columns.
an HTML page.
The trick is to use a table without borders,
A part of this page is formatted with two and maybe a little extra cell-padding.
columns, like a newspaper page.
No matter how much text you add to this
As you can see on this page, there is a page, it will stay inside its column
left column and a right column. borders.
One very common practice with HTML, is An HTML <table> is used to divide a part
to use HTML tables to format the layout of of this Web page into two columns.
an HTML page.
This text is displayed in the right column.
A part of this page is formatted with two
columns, like a newspaper page. The trick is to use a table without borders,
and maybe a little extra cell-padding.
As you can see at this page, there is a left
column and a right column. No matter how much text you add to this
page, it will stay inside its column
borders.
Examples
Dividing a part of an HTML page into table columns is very easy to do. To let you experiment with it,
we have put together this simple example.
<html>
<body>
Page 4 of 32
</td>
</tr>
</table>
</body>
</html>
HTML Joke
Student: "How do you spell HTML?"
HTML Frames
With frames, you can display more than one Web page in the same browser window.
Examples
Vertical frameset
This example demonstrates how to make a vertical frameset with three different
documents.
Horizontal frameset
This example demonstrates how to make a horizontal frameset with three different
documents.
Frames
With frames, you can display more than one HTML document in the same browser
window. Each HTML document is called a frame, and each frame is independent of the
others.
Page 5 of 32
Each frameset defines a set of rows or columns
The values of the rows/columns indicate the amount of screen area each
row/column will occupy
In the example below we have a frameset with two columns. The first column is set to 25% of the
width of the browser window. The second column is set to 75% of the width of the browser window.
The HTML document "frame_a.htm" is put into the first column, and the HTML document
"frame_b.htm" is put into the second column:
<frameset cols="25%,75%">
<frame src="frame_a.htm">
<frame src="frame_b.htm">
</frameset>
Note: The frameset column size value can also be set in pixels (cols="200,500"), and
one of the columns can be set to use the remaining space (cols="25%,*").
If a frame has visible borders, the user can resize it by dragging the border. To prevent
a user from doing this, you can add noresize="noresize" to the <frame> tag.
Add the <noframes> tag for browsers that do not support frames.
Important: You cannot use the <body></body> tags together with the
<frameset></frameset> tags! However, if you add a <noframes> tag containing some
text for browsers that do not support frames, you will have to enclose the text in
<body></body> tags! See how it is done in the first example below.
More Examples
<html>
<frameset cols="25%,50%,25%">
<frame src="frame_a.htm">
<frame src="frame_b.htm">
Page 6 of 32
<frame src="frame_c.htm">
<noframes>
<body>Your browser does not handle frames!</body>
</noframes>
</frameset>
</html>
Mixed frameset
This example demonstrates how to make a frameset with three documents, and how to
mix them in rows and columns.
<html>
<frameset rows="50%,50%">
<frame src="frame_a.htm">
<frameset cols="25%,75%">
<frame src="frame_b.htm">
<frame src="frame_c.htm">
</frameset>
</frameset>
</html>
<frameset rows="50%,50%">
<frameset cols="25%,75%">
<frame noresize="noresize" src="frame_b.htm">
<frame noresize="noresize" src="frame_c.htm">
</frameset>
</frameset>
</html>
Navigation frame
This example demonstrates how to make a navigation frame. The navigation frame
contains a list of links with the second frame as the target. The file called
Page 7 of 32
"tryhtml_contents.htm" contains three links. The source code of the links:
<a href ="frame_a.htm" target ="showframe">Frame a</a><br>
<a href ="frame_b.htm" target ="showframe">Frame b</a><br>
<a href ="frame_c.htm" target ="showframe">Frame c</a>
The second frame will show the linked document.
<html>
<frameset cols="120,*">
<frame src="tryhtml_contents.htm">
<frame src="frame_a.htm"
name="showframe">
</frameset>
</html>
Inline frame
This example demonstrates how to create an inline frame (a frame inside an HTML
page).
<html>
<body>
<iframe src="default.asp"></iframe>
</body>
</html>
<frameset cols="20%,80%">
<frame src="frame_a.htm">
<frame src="link.htm#C10">
</frameset>
</html>
Page 8 of 32
contains a list of links with the second frame (link.htm) as a target. The second frame
shows the linked document. One of the links in the navigation frame is linked to a
specified section in the target file. The HTML code in the file "content.htm" looks like
this: <a href ="link.htm" target ="showframe">Link without Anchor</a><br><a href
="link.htm#C10" target ="showframe">Link with Anchor</a>.
<html>
<frameset cols="180,*">
<frame src="content.htm">
<frame src="link.htm" name="showframe">
</frameset>
</html>
Frame Tags
Tag Description
<frameset> Defines a set of frames
<frame> Defines a sub window (a frame)
<noframes> Defines a noframe section for browsers that do not handle frames
<iframe> Defines an inline sub window (frame)
HTML Fonts
Even if a lot of people are using it, you should try to avoid it, and use styles instead.
With HTML code like this, you can specify both the size and the type of
the browser output :
Example
<p>
<font size="2" face="Verdana">
This is a paragraph.
</font>
</p>
Page 9 of 32
<p>
<font size="3" face="Times">
This is another paragraph.
</font>
</p>
Try it yourself »
Font Attributes
Attribute Example Purpose
The <font> tag is deprecated in the latest versions of HTML (HTML 4 and XHTML).
The World Wide Web Consortium (W3C) has removed the <font> tag from its
recommendations. In future versions of HTML, style sheets (CSS) will be used to define
the layout and display properties of HTML elements.
Page 10 of 32
Set the font, font size, and font color of text
This example demonstrates how to set the font, font size, and font color of a text.
First off: Finish the last chapters in our HTML tutorial !!! In the following chapters we
will explain why some tags, like <font>, are to be removed from the HTML
recommendations, and how to insert a style sheet in an HTML document.
The original HTML was never intended to contain tags for formatting a document.
HTML tags were intended to define the content of the document like:
<p>This is a paragraph</p>
<h1>This is a heading</h1>
When tags like <font> and color attributes were added to the HTML 3.2 specification, it
started a nightmare for web developers. Development of large web sites where fonts
and color information had to be added to every single Web page, became a long,
expensive and unduly painful process.
In HTML 4.0 all formatting can be removed from the HTML document and stored in a
separate style sheet.
Because HTML 4.0 separates the presentation from the document structure, we have
what we always needed: Total control of presentation layout without messing up the
document content.
Do not use presentation attributes inside your HTML tags if you can avoid it. Start using
styles! Please read our CSS tutorial to learn about style sheets.
Do not use deprecated tags. Visit our complete HTML 4.01 Reference to see which tags
and attributes that are deprecated.
Page 11 of 32
Prepare Yourself for XHTML
XHTML is the "new" HTML. The most important thing you can do is to start writing valid
HTML 4.01. Also start writing your tags in lower case. Always close your tag elements.
Never end a paragraph without </p>.
NOTE: The official HTML 4.01 recommends the use of lower case tags.
If you want to read about how this web site was converted to XHTML, please visit our
XHTML tutorial.
The HTML 4.01 Strict DTD includes elements and attributes that have not
been deprecated or do not appear in framesets:
The HTML 4.01 Transitional DTD includes everything in the strict DTD plus
deprecated elements and attributes:
The HTML 4.01 Frameset DTD includes everything in the transitional DTD
plus frames as well:
Page 12 of 32
HTML Styles
With HTML 4.0 all formatting can be moved out of the HTML document and into a
separate style sheet.
Examples
Styles in HTML
This example demonstrates how to format an HTML document with style information
added to the <head> section.
When a browser reads a style sheet, it will format the document according to it. There
are three ways of inserting a style sheet:
An external style sheet is ideal when the style is applied to many pages.
With an external style sheet, you can change the look of an entire Web
site by changing one file. Each page must link to the style sheet using the
<link> tag. The <link> tag goes inside the head section.
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<head>
<style type="text/css">
body {background-color: red}
Page 13 of 32
p {margin-left: 20px}
</style>
</head>
Inline Styles
An inline style should be used when a unique style is to be applied to a single occurrence
of an element.
To use inline styles you use the style attribute in the relevant tag. The
style attribute can contain any CSS property. The example shows how to
change the color and the left margin of a paragraph:
Style Tags
Tag Description
Character Entities
Page 14 of 32
Some characters are reserved in HTML. For example, you cannot use the greater than or
less than signs within your text because the browser could mistake them for markup.
If we want the browser to actually display these characters we must insert character
entities in the HTML source.
The advantage of using an entity name instead of a number is that the name often is
easier to remember. However, the disadvantage is that browsers may not support all
entity names (while the support for entity numbers is very good).
Non-breaking Space
Normally HTML will truncate spaces in your text. If you write 10 spaces in your text
HTML will remove 9 of them. To add lots of spaces to your text, use the
character entity.
Try It Yourself
This example lets you experiment with character entities: Try it yourself
Page 15 of 32
€ euro € €
HTML Head
Examples
The head element contains general information, also called meta-information, about a
document. Meta means "information about".
You can say that meta-data means information about data, or meta-information means
information about information.
The elements inside the head element should not be displayed by a browser.
According to the HTML standard, only a few tags are legal inside the head section. These
are: <base>, <link>, <meta>, <title>, <style>, and <script>.
<head>
<p>This is some text</p>
</head>
Page 16 of 32
If you put an HTML element like <h1> or <p> inside a head element like this, most
browsers will display it, even if it is illegal.
Should browsers forgive you for errors like this? We don't think so. Others do.
Head Tags
Tag Description
Tag Description
<!DOCTYPE> Defines the document type. This tag goes before the <html> start
tag
HTML Meta
Examples
Document description
Information inside a meta element describes the document.
Document keywords
Information inside a meta element describes the document's keywords.
Redirect a user
This example demonstrates how to redirect a user if your site address has changed.
As we explained in the previous chapter, the head element contains general information
(meta-information) about a document.
HTML also includes a meta element that goes inside the head element. The purpose of
the meta element is to provide meta-information about the document.
Page 17 of 32
Most often the meta element is used to provide information that is relevant to browsers
or search engines like describing the content of your document.
Note: W3C states that "Some user agents support the use of META to refresh the
current page after a specified number of seconds, with the option of replacing it by a
different URI. Authors should not use this technique to forward users to different pages,
as this makes the page inaccessible to some users. Instead, automatic page forwarding
should be done using server-side redirects" at
http://www.w3.org/TR/html4/struct/global.html#adef-http-equiv.
Some search engines on the WWW will use the name and content attributes of the meta
tag to index your pages.
The intention of the name and content attributes is to describe the content of a page.
However, since too many webmasters have used meta tags for spamming, like repeating
keywords to give pages a higher ranking, some search engines have stopped using them
entirely.
You can read more about search engines in our Web Building Tutorial.
Sometimes you will see meta attributes that are unknown to you like this:
Then you just have to accept that this is something unique to the site or to the author of
the site, and that it has probably no relevance to you.
Page 18 of 32
HTML Uniform Resource Locators
HTML Links
When you click on a link in an HTML document like this: Last Page, an underlying <a>
tag points to a place (an address) on the Web with an href attribute value like this: <a
href="lastpage.htm">Last Page</a>.
The Last Page link in the example is a link that is relative to the Web site that you are
browsing, and your browser will construct a full Web address like
http://www.w3schools.com/html/lastpage.htm to access the page.
Something called a Uniform Resource Locator (URL) is used to address a document (or
other data) on the World Wide Web. A full Web address like this:
http://www.w3schools.com/html/lastpage.htm follows these syntax rules:
scheme://host.domain:port/path/filename
The scheme is defining the type of Internet service. The most common type is http.
The host is defining the domain host. If omitted, the default host for http is www.
The :port is defining the port number at the host. The port number is normally
omitted. The default port number for http is 80.
The path is defining a path (a sub directory) at the server. If the path is omitted, the
resource (the document) must be located at the root directory of the Web site.
The filename is defining the name of a document. The default filename might be
default.asp, or index.html or something else depending on the settings of the Web
server.
URL Schemes
Schemes Access
Page 19 of 32
http a file on a World Wide Web Server
Accessing a Newsgroup
(The link doesn't work. Don't try it. It is just an example. W3Schools doesn't really have
an ftp directory.)
<a href="mailto:someone@w3schools.com">someone@w3schools.com</a>
someone@w3schools.com
HTML Scripts
Page 20 of 32
Add scripts to HTML pages to make them more dynamic and interactive.
Examples
Insert a script
This example demonstrates how to insert a script into your HTML document.
<html>
<body>
<script type="text/javascript">
document.write("Hello World!")
</script>
</body>
</html>
Hello World!
Note: To learn more about scripting in HTML, visit our JavaScript School.
A browser that does not recognize the <script> tag at all, will display the <script> tag's
content as text on the page. To prevent the browser from doing this, you should hide the
script in comment tags. An old browser (that does not recognize the <script> tag) will
ignore the comment and it will not write the tag's content on the page, while a new
browser will understand that the script should be executed, even if it is surrounded by
comment tags.
Example
JavaScript:
<script type="text/javascript">
<!--
Page 21 of 32
document.write("Hello World!")
//-->
</script>
VBScript:
<script type="text/vbscript">
<!--
document.write("Hello World!")
'-->
</script>
In addition to hiding the script inside a comment, you can also add a <noscript> tag.
The <noscript> tag is used to define an alternate text if a script is NOT executed. This
tag is used for browsers that recognize the <script> tag, but do not support the script
inside, so these browsers will display the text inside the <noscript> tag instead.
However, if a browser supports the script inside the <script> tag it will ignore the
<noscript> tag.
Example
JavaScript:
<script type="text/javascript">
<!--
document.write("Hello World!")
//-->
</script>
<noscript>Your browser does not support JavaScript!</noscript>
VBScript:
<script type="text/vbscript">
<!--
document.write("Hello World!")
'-->
</script>
<noscript>Your browser does not support VBScript!</noscript>
Script Tags
Tag Description
Page 22 of 32
<object> Defines an embedded object
HTML tags can have attributes. The special attributes for each tag are listed under each
tag description. The attributes listed here are the core and language attributes that are
standard for all tags (with a few exceptions):
Core Attributes
Not valid in base, head, html, meta, param, script, style, and title
elements.
Language Attributes
Not valid in base, br, frame, frameset, hr, iframe, param, and script
elements.
Page 23 of 32
Keyboard Attributes
Attribute Value Description
If you want to learn more about programming with these events, you should study our
JavaScript tutorial and our DHTML tutorial.
Window Events
Page 24 of 32
onselect script Script to be run when the element is selected
Keyboard Events
Not valid in base, bdo, br, frame, frameset, head, html, iframe, meta,
param, script, style, and title elements.
Mouse Events
Not valid in base, bdo, br, frame, frameset, head, html, iframe, meta,
param, script, style, title elements.
Page 25 of 32
HTML URL Encoding
URL Encoding
URLs can only be sent over the Internet using the ASCII character-set.
Since URLs often contains characters outside the ASCII set, the URL has to be converted.
URL encoding converts the URL into a valid ASCII format.
URL encoding replaces unsafe ASCII characters with "%" followed by two hexadecimal
digits corresponding to the character values in the ISO-8859-1 character-set.
URLs cannot contain spaces. URL encoding normally replaces a space with a + sign.
€ %80
£ %A3
© %A9
® %AE
À %C0
Á %C1
 %C2
à %C3
Ä %C4
Page 26 of 32
Å %C5
For a complete reference of all URL encodings, visit our URL Encoding Reference
Your own PC can act as a web server if you install IIS or PWS.
IIS comes with Windows 2000, XP, and Vista. It is also available for Windows NT.
IIS is easy to install and ideal for developing and testing web applications.
IIS includes Active Server Pages (ASP), a server-side scripting standard that can be used
to create dynamic and interactive web applications.
If you want to read more about ASP, you should study our ASP School.
PWS is easy to install and can be used for developing and testing web applications
including ASP.
We don't recommend running PWS for anything else than training. It is outdated and has
security issues.
Page 27 of 32
Windows Vista Business, Enterprise and Ultimate come with IIS 7
Windows Vista Home Premium comes with IIS 7
4. Select the check box for Internet Information Services (IIS), and click OK
After you have installed IIS, make sure you install all patches for bugs and security
problems. (Run Windows Update).
5. Click Details
6. Select the check box for World Wide Web Service, and click OK
After you have installed IIS, make sure you install all patches for bugs and security
problems. (Run Windows Update).
Page 28 of 32
Test Your Web
After you have installed IIS or PWS follow these steps:
4. Write some ASP code and save the file as "test1.asp" in the new folder
Note: Look for the IIS (or PWS) symbol in your start menu or task bar. The program has
functions for starting and stopping the web server, disable and enable ASP, and much
more.
For Windows 95 or Windows NT: Download "Windows NT 4.0 Option Pack" from
Microsoft, and install PWS.
If your employer has an Internet Server, you can ask him to host your Web site.
If you are really serious about this, you should install your own Internet Server.
Before you select an ISP, make sure you read W3Schools Web Hosting Tutorial
HTML Summary
This tutorial has taught you how to use HTML to create your own web site.
Page 29 of 32
HTML is the universal markup language for the Web. HTML lets you format text, add
graphics, create links, input forms, frames and tables, etc., and save it all in a text file
that any browser can read and display.
The key to HTML is the tags, which indicates what content is coming up.
For more information on HTML, please take a look at our HTML examples and our HTML
reference.
XHTML
If you want to learn more about XHTML, please visit our XHTML tutorial.
CSS
CSS is used to control the style and layout of multiple Web pages all at once.
With CSS, all formatting can be removed from the HTML document and stored in a
separate file.
CSS gives you total control of the layout, without messing up the document content
Page 30 of 32