|
|||||||
|
Introduction:
HTML stands for HyperText Markup Language.
It's the 'universal language' of the World Wide Web. HTML first appeared in 1995
(HTML version 2.0). The following years versions 3.0 and 3.2 were introduced
.and today, in the year 2002, HTML 6.0 is used. In all these years there have
been major differences in the behavior of the HTML language in different
browsers and on different platforms. Most of us will agree that HTML documents
should work well in different browsers and platforms but there are still
differences in the behavior of HTML documents in different browsers. The good
news is that the gap is closing rapidly.
HTML stands for Hyper Text Markup Language.
An HTML file is a text file
containing small markup tags
The markup tags tell the Web browser how to
display the page
An HTML file must have an htm or html file extension
An
HTML file can be created using a simple text editor.
When you save an HTML file, you can use either the .htm or the .html extension. It might be a bad habit inherited from the past when some of the commonly used software only allowed three letter extensions. With newer software we think it will be perfectly safe to use .html.
Remember the HTML example from the previous page:-
4:44 AM 3/12/2003This is an HTML element: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<body> This is my first homepage. <b>This text is bold</b> </body> |
This HTML element starts with the start tag <body>, and ends with the end tag </body>.
The purpose of the tag is to define the HTML element that contains the body of the HTML document.
We have just said that HTML tags are not case sensitive: <B> means the same as . When you surf the Web, you will notice that most tutorials use uppercase HTML tags in their examples. We always use lowercase tags. Why?
If you want to prepare yourself for the next generations of HTML you should start using lowercase tags. The World Wide Web Consortium (W3C) recommends lowercase tags in their HTML 4 recommendation, and XHTML (the next generation HTML) demands lowercase tags.
Tags can have attributes. Attributes can provide additional information about the HTML elements on your page.This tag defines the body element of your HTML page: <body>. With an added bgcolor attribute, you can tell the browser that the background color of your page should be red, like this: <body bgcolor="red">.
This tag defines an HTML table: <table>. With an added border attribute, you can tell the browser that the table should have no borders: <table border="0">
Attributes always come in name/value pairs like this: name="value". Attributes are always added to the start tag of an HTML element.
Headings are defined with the <h1> to <h6> tags. <h1> defines the largest heading. <h6> defines the smallest heading.
<h1>This is a heading</h1> <h2>This is a heading</h2> <h3>This is a heading</h3> <h4>This is a heading</h4> <h5>This is a heading</h5> <h6>This is a heading</h6> |
HTML automatically adds an extra blank line before and after a heading.
Paragraphs are defined with the <p> tag.
<p>This is a paragraph</p> <p>This is another paragraph</p> |
HTML automatically adds an extra blank line before and after a paragraph.
The <br> tag is used when you want to end a line, but don't want to start a new paragraph. The <br> tag forces a line break wherever you place it.
<p>This <br> is a para<br>graph with line breaks</p> |
The <br> tag is an empty tag. It has no closing tag.
The comment tag is used to insert a comment in the HTML source code. A comment will be ignored by the browser. You can use comments to explain your code, which can help you when you edit the source code at a later date.
<!-- This is a comment --> |
Note that you need an exclamation point after the opening bracket, but not before the closing bracket.
With HTML code like this, you can specify both the size and the type of the browser output :
<p><font size="2" face="Verdana">This is a paragraph.</font></p> <p><font size="3" face="Times">This is another paragraph.</font></p> |
Attribute | Example | Purpose |
---|---|---|
size="number" | size="2" | Defines the font size |
size="+number" | size="+1" | Increases the font size |
size="-number" | size="-1" | Decreases the font size |
face="face-name" | face="Times" | Defines the font-name |
color="color-value" | color="#eeff00" | Defines the font color |
color="color-name" | color="red" | Defines the font color |
These tags are used for making lists.
HTML uses the <a> (anchor) tag to create a link to another document.
An anchor can point to any resource on the Web: an HTML page, an image, a sound file, a movie, etc.
The syntax of creating an anchor:
<a href="url">Text to be displayed</a> |
The <a> tag is used to create an anchor to link from, the href attribute is used to address the document to link to, and the words between the open and close of the anchor tag will be displayed as a hyperlink.
This anchor defines a link to Myresearchinstitute.com
The line above will look like this in a browser:
With the target attribute, you can define where the linked document will be opened.
The line below will open the document in a new browser window:
<a href="http://www.myresearchinstitute.com/" target="_blank">Visit MyresearchInstitute</a> |
The name attribute is used to create a named anchor. When using named anchors we can create links that can jump directly into a specified section on a page, instead of letting the user scroll around to find what he/she is looking for.
Syntax of a named anchor:
<a name="label">Text to be displayed</a> |
The name attribute is used to create a named anchor. The name of the anchor can be any text you care to use.
The line below defines a named anchor:
<a name="tips">Read the Useful Tips section</a> |
You should notice that a named anchor does not display in a special way.
To link to the named anchor you add a # sign and the name of the anchor to the end of the URL, like this:
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 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 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.
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> |
row 1, cell 1 | row 1, cell 2 |
row 2, cell 1 | row 2, cell 2 |
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 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> |
Heading | Another Heading |
---|---|
row 1, cell 1 | row 1, cell 2 |
row 2, cell 1 | row 2, cell 2 |
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> |
row 1, cell 1 | row 1, cell 2 |
row 2, cell 1 |
Note that the borders around the empty table cell are missing.
To avoid this, add a non-breaking space ( ) 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> </td> </tr> </table> |
row 1, cell 1 | row 1, cell 2 |
row 2, cell 1 |
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> |
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 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> |
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 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> |
Note that only one option can be chosen.
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">I have a bike <br> <input type="checkbox" name="car"> I have a car </form> |
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="htm_form_action.asp" method="get"> Username: <input type="text" name="user"> <input type="submit" value="Submit"> </form> |
If you type some characters in the text field above, and click the "Submit" button, you will send your input to a page called "htm_form_action.asp". That page will show you the received input.
frame1.html | frame2.html | frame3.html | ||||||
<html> <head> <title> </title> </head> <body> This is frame 1 </body> </html> |
<html> <head> <title> </title> </head> <body> This is frame 2 </body> </html> |
<html> <head> <title> </title> </head> <body> This is frame 3 </body> </html> |
Save these HTML documents (in your folder called
'frames') as "frame1.html, frame2.html and frame3.html". Now we will create our main document 'index.html'. This is done like this: (the part in red are only my comments, there's no need to typ them in): |
<html> <head> <title> </title> </head> <frameset cols="25%,75%"> <frame src="frame1.html"> <-- contents of column 1 <frameset rows="15%,85%"> <-- create two rows in the second column <frame src="frame2.html"> <-- contents row 1, column 2 <frame src="frame3.html"> <-- contents row 2, column 2 </frameset> <noframes> Your
browser doesn't support frames, click here for
.... </noframes></frameset> </html> |
Save the document in your folder as
'index.html'. There have to be 4 documents in your folder called 'frames' (or the name you chose for it) now. Doubleclick on the document 'index.html' to see your first frames construction. Lets have a closer look to all the tags: Note: we can divide our page into columns and rows: |
So, we told the browser: 'Create two columns'. Now we tell the browser that
the first column has to contain 'frame1.html' by saying:
<frameset cols="15%,75%">
--> <frame src="frame1.html">
src means source and tells the browser which document to
use.
Now that we have two columns and assigned document 'frame1.html' to
the first column we will divide the second column into 2 rows. It's done this
way:
<frameset cols="15%,75%">
<frame src="frame1.html">
--> <frameset rows="15%,85%">
The first row in our second
column will get 15% of the space and the second row will get 85% of the space.
The only thing we have to do now is tell the browser which documents have to be
assigned to these 2 rows:
<frameset
cols="15%,75%">
<frame
src="frame1.html">
<frameset
rows="15%,85%">
-> <frame src="frame2.html">
-> <frame src="frame3.html">
The first row of the
second column will contain the information of 'frame2.html', the second row of
the second column will contain the information of 'frame3.html'.
The tag <noframes> can be used (it's
optional) as an alternative for a browser that for some kind of reason doesn't
support frames.
--> <noframes> Contents goes here </noframes>
</noframes> is required when
you use the <noframes> tag!
Note! There's an end tag for the <frameset> tag --> </frameset> which you HAVE TO use for every <frameset> tag that you use! Be sure to NEST the tags
correctly! Remember?
GOOD:
(1-2-3-3-2-1)
<html><head><title></title></head></html>
GOOD: (1-2-3-3-2-4-4-1)
<html><head><title></title></head><body></body></html>
WRONG:
(1-2-3-1-2-3)
<html><head><title></html></head></title>
If you don't nest the tags correctly
then you will get weird constructions or no constructions at all!
Now
that we have divided everything nicely we can assign every document to every
frame we choose. Isn't that great?!
There are several attributes that we
can add to the <frame> tag:
Cascading Style Sheet
How to Use Styles
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> |
An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section with the <style> tag.
<head> <style type="text/css"> body {background-color: red} p {margin-left: 20px} </style> </head>
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:
<p style="color: red; margin-left: 20px"> This is a paragraph </p> |
ASP Tutorial CGI Tutorial CSS Tutorial JavaScript Tutorial Perl Tutorial PHP Tutorial