Professional Documents
Culture Documents
Basically an HTML document is a plain text file that contains text and nothing else.
When a browser opens an HTML file, the browser will look for HTML codes in the text and
use them to change the layout, insert images, or create links to other pages.
Since HTML documents are just text files they can be written in even the simplest text editor.
A more popular choice is to use a special HTML editor - maybe even one that puts focus on
the visual result rather than the codes - a so-called WYSIWYG editor ("What You See Is
What You Get").
Some of the most popular HTML editors, such as FrontPage or Dreamweaver will let you
create pages more or less as you write documents in Word or whatever text editor you're
using.
However, there are some very good reasons to create your own pages - or parts of them -
by hand..
You can view the HTML tags for any HTML document by looking at the "source"
document that contains the HTML tags, usually called "View Source" or "View
Document Source" from the "View" menu on most clients. Using this option is a nice
way to learn new things as well as refresh your memory when working with HTML tags.
PAGE STRUCTURE
All normal webpages consist of a head and a body.
Head
Body
The head is used for text and tags that do not show directly on the page.
The body is used for text and tags that are shown directly on the page.
Finally, all webpages have an <html> tag at the beginning and the end, telling the browser
where the document starts and where it stops.
The most basic code - the code you will use for any page you make, is shown below:
<html>
<head>
<!-- This section is for the title and technical info of the page. -->
</head>
<body>
<!-- This section is for all that you want to show on the page. -->
</body>
</html>
HEAD SECTION
The head section of the webpage includes all the stuff that does not show directly on the
resulting page.
The <title> and </title> tags encapsulate the title of your page. The title is what shows in the
top of your browser window when the page is loaded.
Right now it should say something like "Basic - Html" on top of the window containing this
text.
BODY SECTION
The body of the document contains all that can be seen when the user loads the page.
There are excellent editors on the market that will take care of the HTML parts. All you need
to do is layout the page.
You can read the code of other people's pages, and "borrow" the cool effects.
You can do the work yourself, when the editor simply refuses to create the effects
you want.
You can write your HTML by hand with almost any available text editor, including notepad
that comes as a standard program with Windows.
All you need to do is type in the code, then save the document, making sure to put an .html
extension or an .htm extension to the file (for instance "mypage.html").
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.
PWS is easy to install and can be used for developing and testing web applications including
ASP.
Running PWS for anything is not recommended. It is outdated and has security issues.
HTML Elements
An HTML element is everything from the start tag to the end tag:
* The start tag is often called the opening tag. The end tag is often called the closing tag.
<body>
<p>This is my first paragraph.</p>
</body>
</html>
<body>
<p>This is my first paragraph.</p>
</body>
<body>
<p>This is my first paragraph.</p>
</body>
</html>
<p>This is a paragraph
<p>This is a paragraph
The example above will work in most browsers, but don't rely on it. Forgetting the end tag can produce unexpected
results or errors.
<br> is an empty element without a closing tag (the <br> tag defines a line break).
In XHTML, XML, and future versions of HTML, all elements must be closed.
Headers
There are up to six levels of headers that can be used in your document, h1 through h6.
Header 1 is the largest header and they get progressively smaller through header 6. Below
are each of the six headers and how they usually appear in relation to one another.
<h1>This is a header 1 tag</h1>
Headers, as you notice, not only vary in size, they are also bold and have a blank line
inserted before and after them. It's important to use headers only for headings, not just to
make text bold.
Titles
A title tag allows you to specify a Document Title in your browser window. When people
make hotlists, this title is what they see in their list after they add your document. The
format is:
<title>My First HTML Document</title>
Remember, the title usually doesn't appear in the document itself, but in a title box or bar
at the top of the window.
Commonly Used
HTML Codes
Header tags
HTML Code Sample
<H1>Header 1</H1>
Header 1
<H2>Header 2</H2> Header 2
<H3>Header 3</H3>
Header 3
<H4>Header 4</H4>
Header 4
<H5>Header 5</H5>
Header 5
<H6>Header 6</H6>
Header 6
<B>bold</B> bold
<U>underline</U> underline
<I>italic</I> italic
Alignment tags
HTML Code Sample
<P ALIGN=Left>your text your text
<P ALIGN=Center>your
your text
text
<P ALIGN=Right>your
your text
text
Ordered list (numbers)
HTML Code Sample
<OL> 1. First row
<LI>First row 2. Second row
<LI>Second row
</OL>
Definition list
HTML Code Sample
<DL>
<DT>Term Term
<DD>Description Description
</DL>
Break tags
HTML Code Description
<P> Paragraph break
<BR> Forced line break
Indentation tag
HTML Code Sample
Here is some text. <BR> Here is some text.
<BLOCKQUOTE>Here is Here is one line of indented
one line of indented text.
text.<BR> Here is another line of
Here is another line of indented text.
indented text.
</BLOCKQUOTE>
CNN
For example:
<A HREF="filename or
URL">CNN</A>
<A NAME="anchor
name">Section name</A>
For example:
<A NAME="anchor
name">Introduction</A> Introduction
<A HREF="#anchor
name">Destination</A>
For example:
<A HREF="#anchor
name">Introduction</A> Introduction
Graphic tags
HTML Code Sample
<IMG SRC="balloon.gif">
(By default, the graphic is left
aligned.)
<IMG SRC="balloon.gif"
Align=right>
<P ALIGN=Center>
<IMG SRC="balloon.gif">
<IMG
SRC="balloon.gif" Align=right
Vspace=20>
<IMG SRC="balloon.gif"
Align=left Hspace=30>
Text formats:
These are the tags for text formats:
Text Size
These are the tags for changing the font size.
<font size="7">
text </font>
writes text in biggest fontsize (36 pt)
Default font size is 3. The <small> and <big> tags are special in that they can be
repeated. If you want to increase the font size with a factor two, then you could do it
like this:
<p>text</p>
Adds a paragraph break after the text.
(2 linebreaks).
<p align="left">text</p> Left justify text in paragraph.
<p align="center">text</p> Center text in paragraph.
<p align="right">text</p> Right justify text in paragraph.
text<br>
Adds a single linebreak where the tag
is.
Turns off automatic linebreaks
<nobr>text</nobr> - even if text is wider than the
window.
Allows the browser to insert a
text<wbr>
linebreak
at exactly this point
- even if the text is within <nobr> tags.
<center>text</center> Center text.
<div
align="center">text</div> Center text.
<div align="left">text</div> Left justify text.
<div align="right">text</div> Right justify text.
.
<nobr>This option can however be
turned off<wbr>with the nobr This option can however be turned
tag,<wbr>unless a wbr is used to off
force it!</nobr>
with the nobr tag,
The <div> tag defines a division or a section in an HTML document. The <div>
tag is used to group block-elements to format them with styles.
Note in particular the difference between the <p> and the <div> tags. The <div> tag
allows you to justify content without being forced to add a double linebreak.
Also, note that these alignment tags are not limited to text. They work on text,
images, applets or whatever it is that you insert on the page.
HTML Links
How to Create Link in HTML Documents:
<html>
<body>
<p>
</p>
<p>
</p>
</body>
</html>
Output:
When you move the cursor over a link in a Web page, the arrow will turn into a little
hand.
Example
<a href="http://www.google.com/">Visit google</a>
The example below will open the linked document in a new browser window:
Note:
The upcoming HTML5 standard suggest using the id attribute instead of the name
attribute for specifying the name of an anchor.
Using the id attribute actually works also for HTML4 in all modern browsers.
Bookmarks are not displayed in any special way. They are invisible to the reader.
Example
A named anchor inside an HTML document:
<a name="tips">Useful Tips Section</a>
Create a link to the "Useful Tips Section" inside the same document:
Or, create a link to the "Useful Tips Section" from another page:
<a href="http://www.googles.com/html_links.htm#tips">
Visit the Useful Tips Section</a>
<html>
<body>
</body>
</html>
Output:
HTML Lists
The most common HTML lists are ordered and unordered lists:
HTML Lists
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items are marked with bullets (typically small black circles).
<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>
Coffee
Milk
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
<ol>
<li>Coffee</li>
<li>Milk</li>
</ol>
1. Coffee
2. Milk
The <dl> tag is used in conjunction with <dt> (defines the item in the list) and <dd> (describes the item in
the list):
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Coffee
- black hot drink
Milk
- white cold drink
<html>
<body>
<h4>Numbered list:</h4>
<ol>
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
<h4>Letters list:</h4>
<ol type="A">
<li>Apples</li>
<li>Bananas</li>
<li>Lemons</li>
<li>Oranges</li>
</ol>
</body>
</html>
1. Apples
2. Bananas
3. Lemons
4. Oranges
Letters list:
A. Apples
B. Bananas
C. Lemons
D. Oranges
a. Apples
b. Bananas
c. Lemons
d. Oranges
I. Apples
II. Bananas
III. Lemons
IV. Oranges
i. Apples
ii. Bananas
iii. Lemons
iv. Oranges
<html>
<body>
</body>
</html>
Apples
Bananas
Lemons
Oranges
o Apples
o Bananas
o Lemons
o Oranges
Apples
Bananas
Lemons
Oranges
Images in HTML
The <img> tag is empty, which means that it contains attributes only, and 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.
The URL points to the location where the image is stored. An image named "boat.gif",
located in the "images" directory on "www.website.com" has the URL:
http://www.website.com/images/boat.gif.
The browser displays the image where the <img> 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 required alt attribute specifies an alternate text for an image, if the image cannot be
displayed.
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).
HTML Images - Set Height and Width of an Image
The height and width attributes are used to specify the height and width of an image.
Tip: It is a good practice to specify both the height and width attributes for an image. If
these attributes are set, the space required for the image is reserved when the page is
loaded. However, without these attributes, the browser does not know the size of the
image. The effect will be that the page layout will change during loading (while the
images load).
<p>An image
<img src="smiley.gif" alt="Smiley face" align="bottom" width="32" height="32"
/>
with align="bottom".</p>
<p>An image
<img src="smiley.gif" alt="Smiley face" align="middle" width="32" height="32"
/>
with align="middle".</p>
<p>An image
<img src="smiley.gif" alt="Smiley face" align="top" width="32" height="32" />
with align="top".</p>
<p>
<img src="smiley.gif" alt="Smiley face" align="left" width="32" height="32" />
A paragraph with an image. The align attribute of the image is set to "left". The
image will float to the left of this text.
</p>
<p>
<img src="smiley.gif" alt="Smiley face" align="right" width="32" height="32" />
A paragraph with an image. The align attribute of the image is set to "right". The
image will float to the right of this text.
</p>
</body>
</html>
</body>
</html>
HTML 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). 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.
Table Example
<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>
<table border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>
HTML Table Headers
Header information in a table are defined with the <th> tag.
All major browsers will display the text in the <th> element as bold and centered.
<table border="1">
<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>
Header 1 Header 2
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
</body>
</html>
Output:
Table Header:
<html>
<body>
<h4>Table headers:</h4>
<table border="1">
<tr>
<th>Name</th>
<th>Telephone</th>
<th>Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
<h4>Vertical headers:</h4>
<table border="1">
<tr>
<th>First Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 77 855</td>
</tr>
</table>
</body>
</html>
</body>
</html>
The Frame Attribute of Tables:
<html>
<body>
<p>
<b>Note:</b>
If you see no frames/borders around the tables below, your browser does not support
the "frame" attribute.
</p>
<h4>With frame="border":</h4>
<table frame="border">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="box":</h4>
<table frame="box">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="void":</h4>
<table frame="void">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="above":</h4>
<table frame="above">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="below":</h4>
<table frame="below">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="hsides":</h4>
<table frame="hsides">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="vsides":</h4>
<table frame="vsides">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="lhs":</h4>
<table frame="lhs">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="rhs":</h4>
<table frame="rhs">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
</body>
</html>
Output:
Frames
Frames can divide the screen into separate windows.
When a frameset page is loaded, the browser automatically loads each of the pages
associated with the frames.
BASIC EXAMPLE
A frameset is simply an HTML document that tells the browser how to divide the screen into
split windows.
<frameset cols="120,*">
<frame src="menupage.htm" name="menu">
<frameset rows="*,50">
<frame src="welcomepage.htm" name="main">
<frame src="bottombanner.htm" name="bottom">
</frameset>
</frameset>
</html>
CREATING A FRAMESET
As stated on the previous page, a frameset is simply an HTML document that tells the
browser how to divide the screen into split windows.
DEFAULT PAGES
You can add default pages to frame windows with the src setting.
Default pages are the pages that will be loaded when the frameset is opened the
first time.
Furthermore, we can add names to each frame window using the name setting.
This will allow us to make a link in one frame window, open a page in another frame
window.
In this example we added names and default pages to the frame windows:
<frameset cols="120,*" >
<frame src="menu.htm" name="menu" >
<frame src="frontf.htm" name="main" >
</frameset>
m main
e
n
u
We still have the screen divided in two columns, the left being 120 pixels the right
using the rest of the screen. (some screens are set to 640 pixels across, some to
800 and some to 1024, thats why the * is needed).
But now we also have told the browser that the left frame window should load an
HTML page called menu.htm and that the right window should load an HTML
document called frontf.htm .
In addition we have assigned the names menu and main to the two frame windows,
so now we're even able to link to specific windows.
I called the frame windows menu and main, but you could name them whatever
you pleased.
The frameset with a menu window to the left and a main window to the right is the
most common frameset seen on the web.
m main
e
n
u
RESIZEABLE WINDOWS
If you don’t want the frame windows to be resizeable, you should add the parameter
"noresize" to the frame src lines:
SCROLLBARS
Let’s say you don’t want a scroll bar in the menu window.
Furthermore the main window should have a scrollbar if needed (if the HTML
document doesn’t fit in the window), but if not needed - there should be no
scrollbars.
If you leave out the setting for scrolling, a scrollbar will appear if needed - otherwise
not.
LINKS WITHIN
If you have an HTML document with a hyperlink on the text "Analysis" for instance,
that links to a page called "analysis.htm" then it appears in the document as:
Now if the link was in the menu window of our example, and we wanted it to load a
page in the main window, the HTML code would be:
Four target names are reserved, and will be interpreted by the browser in this way:
_blank loads the page into a new browser window
_self loads the page into the current window.
_parent loads the page into the frame that is superior to the frame the
hyperlink is in.
_top cancels all frames, loads in full browser window.
EXAMPLES
top
bottom
<frameset rows="16%,84%">
<frame src="top.htm" name="top">
<frame src="bottom.htm" name="bottom">
</frameset>
tl tr
bottom
<frameset rows="16%,84%">
<frameset cols="50%,50%">
<frame src="tl.htm" name="tl">
<frame src="tr.htm" name="tr">
</frameset>
<frame src="bottom.htm" name="bottom">
</frameset>
top
left right
<frameset rows="16%,84%">
<frame src="top.htm" name="top">
<frameset cols="50%,50%">
<frame src="left.htm" name="left">
<frame src="right.htm" name="right">
</frameset>
</frameset>
topleft topright
botleft botright
topleft topright
brtl brtr
botleft botrbot
topleft topright
botleft botright
topleft topright
botleft botright
HTML was never intended to contain tags for formatting a document. HTML was
intended to define the content of a document, like:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
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 were added to every single page, became a long and expensive process.
To solve this problem, the World Wide Web Consortium (W3C) created CSS. In HTML
4.0, all formatting could be removed from the HTML document, and stored in a separate
CSS file. All browsers support CSS today.
CSS defines HOW HTML elements are to be displayed. Styles are normally saved in
external .css files. External style sheets enable you to change the appearance and layout
of all the pages in a Web site, just by editing one single file!
CSS Syntax
A CSS rule has two main parts: a selector, and one or more declarations:
The selector is normally the HTML element you want to style. Each declaration consists
of a property and a value. The property is the style attribute you want to change. Each
property has a value. CSS declarations always end with a semicolon, and declaration
groups are surrounded by curly brackets:
p { color:red; text-align:center; }
To make the CSS more readable, you can put one declaration on each line, like this:
<html>
<head>
<style type="text/css">
p
{ color:red;
text-align:center; }
</style>
</head>
<body>
<p>Hello World!</p>
<p>This paragraph is styled with CSS.</p>
</body>
</html>
Output:
Example 1:
The HTML file below links to an external style sheet with the <link> tag:
<html>
<head>
<link rel="stylesheet" type="text/css" href="ex1.css" />
</head>
<body>
<h1>This header is 36 pt</h1>
<h2>This header is blue</h2>
<p>This paragraph has a left margin of 50 pixels</p>
</body>
</html>
This is the style sheet file (ex1.css):
body
{ background-color:yellow; }
h1
{ font-size:36pt; }
h2
{ color:blue; }
p
{ margin-left:50px; }
Output:
Example 2:
The HTML file below links to an external style sheet with the <link> tag:
<html>
<head>
<link rel="stylesheet" type="text/css"
href="ex2.css" />
</head>
<body>
<h1>This is a header 1</h1>
<hr />
<p>You can see that the style sheet formats the text</p>
<p><a href="http://www.w3schools.com" target="_blank">This is a
link</a></p>
</body>
</html>
body {background-color:tan;}
h1 {color:maroon;font-size:20pt;}
hr {color:navy;}
p {font-size:11pt;margin-left:15px;}
a:link {color:green;}
a:visited {color:yellow;}
a:hover {color:black;}
a:active {color:blue;}
The id Selector
The id selector is used to specify a style for a single, unique element. The id selector uses
the id attribute of the HTML element, and is defined with ”#"(id). The style rule below
will be applied to the element with id="para1":
Coding Example:
<html>
<head>
<style type="text/css">
#para1
{ text-align:center; color:red; }
</style>
</head>
<body>
<p id="para1">Hello World! </p>
<p>This paragraph is not affected by the style. </p>
</body>
</html>
Output:
Coding Example:
<html>
<head>
<style type="text/css">
.center
{ text-align:center; }
</style>
</head>
Output:
<body>
<h1 class="center">Center-aligned heading</h1>
<p class="center">Center-aligned paragraph.</p>
</body>
</html>
2. Inline Styles
Inline Styles cannot be reused at all, period. Inline styles are placed directly inside an
HTML element in the code. We cannot use the Style Builder to make an Inline Style.
Instead, to purposely create an inline style requires you to go into the HTML code and
type the style yourself.
Note: Inline Styles do not have a Selector. Why not? The reason is because an inline
style is embedded directly inside the html element it styles. Therefore, there's no need for
a selector.
Quite frankly, Inline styles defeat the purpose of using CSS and negate most, if not all of
CSS's advantages, like the separation of content from presentation. Therefore, the use of
Inline Styles should be kept to an absolute minimum. Use Inline Styles only as a last
resort. One example of when using an inline style is useful: Let's say you want to over-
ride a style that's on your external style sheet. Using an inline style is one way to
accomplish this. Example of an Inline Style:
The style is embedded inside the HTML element using the style attribute. The above
style cannot be reused at all. It will only target that one paragraph. In order to style more
paragraphs with an inline style, you'd have to make one inline style per paragraph. That's
not efficient at all. And makes a mess of your code and certainly adds to the amount of
mark-up in your page.
3. External Style Sheet
For the most part, we will want to place the majority of our Style Rules on an External
Style Sheet. This will allow us to reuse the styles as many times as we would like
simply by linking the External Style Sheet to other web pages. It also means we only
have to create the Styles one time! An External Style Sheet is a separate page which is
then linked to the web page. Therefore, the styles are External to, or outside of, the Web
Page.
<form>
.
input elements
.
</form>
1. Text Fields
<input type="text" /> defines a one-line input field that a user can enter text into:
<form>
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" />
</form>
How the HTML code above looks in a browser:
2. Password Fields
<form>
Password: <input type="password" name="pwd" />
</form>
How the HTML code above looks in a browser:
How the HTML code above looks in a browser:
Note: The characters in a password field are masked (shown as asterisks or circles).
3. Radio Buttons
<input type="radio" /> defines a radio button. Radio buttons let a user select ONLY
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>
4. Checkboxes
<input type="checkbox" /> defines a checkbox. Checkboxes let a user select ONE or
MORE options of a limited number of choices.
<form>
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
<input type="checkbox" name="vehicle" value="Car" /> I have a car
</form>
How the HTML code above looks in a browser:
5. Submit Button
<input type="submit" /> defines a submit button. A submit button is used to send form
data to a server. The data is sent to the page specified in the form's action attribute. The
file defined in the action attribute usually does something with the received input: