anantamu.com


What is an HTML File?

  • 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

Do You Want to Try It?

If you are running Windows, start Notepad.
If you are on a Mac, start SimpleText.
In OSX, start TextEdit and change the following preferences:

Open the Format menu and select Plain Text instead of Rich Text.
Then open the Preferences window under the TextEdit menu and select Ignore rich text commands in HTML files.

Your HTML code may not work correctly if you do not change the preferences above.

Type the following text:

<html>
<head>
<title>Title of page</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b>
</body>
</html>

Save the file as mypage.htm.

Open your Internet browser and select Open (or Open Page) from the File menu. Click Browse, locate the file mypage.htm, and click Open.

The browser will display the page you created.

Example Explained

The first tag in an HTML document is <html>. This tag tells the browser that the document is an HTML document. The last tag is </html>, which tells the browser that the HTML document has ended.

The text between the <head> and </head> tags is header information. This information is not displayed in the browser window.

The text between the <title> tags is the title of the document. The title is displayed in the browser's title bar.

The text between the <body> tags is the content that will be displayed in the browser.

The text between the <b> and </b> tags is displayed in bold font.


HTM or HTML Extension?

When saving an HTML file, you can use either the .htm or .html extension. In older systems, only three-letter extensions were allowed, which is why .htm was commonly used.

With modern software, it is perfectly safe to use the .html extension.


Note on HTML Editors

HTML files can be edited using WYSIWYG (What You See Is What You Get) editors such as FrontPage or Dreamweaver.

However, to become a skilled web developer, it is recommended to use a plain text editor to learn basic HTML.

HTML documents are text files made up of HTML elements. HTML elements are defined using HTML tags.


HTML Tags

HTML tags are used to define and structure HTML elements in a document.

HTML Tags

  • HTML tags are used to mark-up HTML elements.
  • HTML tags are surrounded by the characters < and >.
  • The surrounding characters are called angle brackets.
  • HTML tags normally come in pairs like <b> and </b>.
  • The first tag in a pair is the start tag, the second tag is the end tag.
  • The text between the start and end tags is the element content.
  • HTML tags are not case sensitive; <b> is the same as <B>.

HTML Elements

Consider the following HTML example:

<html>
<head>
    <title>Title of page</title>
</head>
<body>
    This is my first homepage. <b>This text is bold</b>
</body>
</html>

This is an HTML element:

<b>This text is bold</b>

The HTML element starts with a start tag <b>.
The content of the HTML element is This text is bold.
The HTML element ends with an end tag </b>.

The purpose of the <b> tag is to define text that should be displayed in bold.

This is also an HTML element:

<body>
    This is my first homepage. <b>This text is bold</b>
</body>

This HTML element starts with the <body> tag and ends with the </body> tag. The purpose of the <body> tag is to define the body of the HTML document.


Why Do We Use Lowercase Tags?

HTML tags are not case sensitive; <B> means the same as <b>. However, modern web standards recommend using lowercase tags.

The World Wide Web Consortium (W3C) recommends lowercase tags in HTML 4, and XHTML requires lowercase tags.

The most important HTML tags define headings, paragraphs, and line breaks. The best way to learn HTML is by working with examples.


Headings

Headings are defined using the <h1> to <h6> tags.

<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 extra space before and after headings.


Paragraphs

Paragraphs are defined using the <p> tag.

<p>This is a paragraph</p>
<p>This is another paragraph</p>

HTML automatically adds extra space before and after paragraphs.

Don't Forget the Closing Tag

Paragraphs can sometimes be written without closing tags, like this:

<p>This is a paragraph
<p>This is another paragraph

The example above may work in most browsers, but you should not rely on it. Future versions of HTML will not allow skipping end tags.

Closing all HTML elements with an end tag is a future-proof way of writing HTML. It also makes code easier to read and understand.


Line Breaks

The <br> tag is used when you want to break a line without starting a new paragraph. It forces a line break wherever it is placed.

<p>This <br> is a para<br>graph with line breaks</p>

The <br> tag is an empty tag. It has no closing tag like </br>.


<br> or <br />

You may also see the line break written as <br />. This format follows XHTML rules where all elements must be closed.

Using <br /> is accepted by both HTML and XML and is future-proof.


Comments in HTML

Comments are used to insert notes inside HTML code. Comments are ignored by the browser and are helpful for explaining code.

<!-- This is a comment -->

Note: An exclamation mark is required after the opening bracket, but not before the closing bracket.


Recap on HTML Elements

  • Each HTML element has an element name (body, h1, p, br).
  • The start tag is the name inside angle brackets, for example <h1>.
  • The end tag includes a slash, for example </h1>.
  • The element content appears between the start and end tags.
  • Some HTML elements have no content.
  • Some HTML elements have no end tag.

Basic Notes – Useful Tips

HTML text may look different in different browsers and screen sizes. Text automatically adjusts when the browser window is resized.

Extra spaces and new lines in HTML count as a single space. Do not use empty paragraphs to create space.

Use the <br> tag for line breaks and the <hr> tag to separate sections.


Horizontal Rule Example

<html>
<body>
<p>The hr tag defines a horizontal rule:</p>
<hr>
<p>This is a paragraph</p>
<hr>
<p>This is a paragraph</p>
<hr>
<p>This is a paragraph</p>
</body>
</html>

Basic HTML Tags

Tag Description
<html> Defines an HTML document
<body> Defines the document body
<h1> to <h6> Defines headings
<p> Defines a paragraph
<br> Inserts a line break
<hr> Defines a horizontal rule
<!-- --> Defines a comment

Attributes provide additional information about an HTML element.

HTML Tag Attributes

HTML tags can have attributes. Attributes provide additional information about an HTML element.

  • Attributes come in name/value pairs like name="value".
  • Attributes are always written in the start tag.

Attributes Example 1

The <h1> tag defines a heading.

<h1 align="center">Center aligned heading</h1>
<h1 align="center"> has additional information about the alignment.

Attributes Example 2

The <body> tag defines the document body.

<body bgcolor="yellow">

This demonstrates a background color.


Attributes Example 3

The <table> tag defines an HTML table.

<table border="1"> has additional information about the border around the table.
Sample Cell Sample Cell

Use Lowercase Attributes

HTML attributes are not case sensitive, but W3C recommends using lowercase. XHTML strictly requires lowercase attributes.


Always Quote Attribute Values

Attribute values must be enclosed in quotes.

name='John "ShotGun" Nelson'

<html>
<body>

<b>This text is bold</b>

<br>

<strong>
This text is strong
</strong>

<br>

<big>
This text is big
</big>

<br>

<em>
This text is emphasized
</em>

<br>

<i>
This text is italic
</i>

<br>

<small>
This text is small
</small>

<br>

This text contains
<sub>
subscript
</sub>

<br>

This text contains
<sup>
superscript
</sup>

</body>
</html>
This text is bold
This text is strong
This text is big
This text is emphasized
This text is italic
This text is small
This text contains subscript
This text contains superscript

Preformatted Text

<html> <body> <pre> This is preformatted text. It preserves both spaces and line breaks. </pre>

The <pre> tag is useful for displaying computer code:

<pre> for i = 1 to 10 print i next i </pre> <html> <body>

OutPut:

This is

preformatted text.

It preserves both spaces

and line breaks.

The pre tag is good for displaying computer code:

for i = 1 to 10

print i

next i

<html> <body> Computer code
Keyboard input
Teletype text
Sample text
Computer variable

Note: These tags are often used to display computer/programming code.

</body> </html> HTML Formatting Tags Example Computer code
Keyboard input
Teletype text
Sample text
Computer variable

Note: These tags are often used to display computer/programming code.


<html> <body>
Donald Duck
BOX 555
Disneyland
USA
</body> </html>

OUT PUT:

Donald Duck

BOX 555

Disneyland

USA

Abbrevation Tag:

<html> <body> <abbr title="United Nations">UN</abbr> <br> <acronym title="World Wide Web">WWW</acronym> <p>The title attribute is used to show the spelled-out version when holding the mouse pointer over the acronym or abbreviation.</p> <p>This only works for the acronym element in IE 5.</p> <p>This works for both the abbr and acronym element in Netscape 6.2.</p> </body> </html>

Output:

UN

WWW

The title attribute is used to show the spelled-out version when holding the mouse pointer over the acronym or abbreviation.

This only works for the acronym element in IE 5.

This works for both the abbr and acronym element in Netscape 6.2.


Text Editor: <html> <body> <p> If your browser supports bi-directional override (bdo), the next line will be written from the right to the left (rtl): </p> <bdo dir="rtl"> Here is some Hebrew text </bdo> </body> </html>

OutPut:

If your browser supports bi-directional override (bdo), the next line will be written from the right to the left (rtl):

Here is some Hebrew text


Display HTML Code in Browser

<html>
<body>

Here comes a long quotation:
<blockquote>
This is a long quotation. This is a long quotation. This is a long quotation. This is a long quotation. This is a long quotation.
</blockquote>

Here comes a short quotation:
<q>
This is a short quotation
</q>

<p>
With the block quote element, the browser inserts line breaks and margins, but the q element does not render as anything special.
</p>

</body>
</html>

Here comes a long quotation:

This is a long quotation. This is a long quotation. This is a long quotation. This is a long quotation. This is a long quotation.

Here comes a short quotation: This is a short quotation

With the block quote element, the browser inserts line breaks and margins, but the q element does not render as anything special.

Deleted And Inserted Text:

Display HTML Code in Browser

<html>
<body>

<p>
a dozen is 
<del>twenty</del> 
<ins>twelve</ins> 
pieces
</p>

<p>
Most browsers will overstrike deleted text and underline inserted text.
</p>

<p>
Some older browsers will display deleted or inserted text as plain text.
</p>

</body>
</html>
HTML Text Formatting and Tags

A dozen is twenty twelve pieces

Most browsers will overstrike deleted text and underline inserted text.

Some older browsers will display deleted or inserted text as plain text.


How to View HTML Source

Have you ever seen a Web page and wondered "Hey! How did they do that?"

To find out, click the View option in your browser's toolbar and select Source or Page Source. This will open a window that shows you the HTML code of the page.


Text Formatting Tags

  • <b> – Defines bold text
  • <big> – Defines big text
  • <em> – Defines emphasized text
  • <i> – Defines italic text
  • <small> – Defines small text
  • <strong> – Defines strong text
  • <sub> – Defines subscripted text
  • <sup> – Defines superscripted text
  • <ins> – Defines inserted text
  • <del> – Defines deleted text
  • <s> – Deprecated (use <del>)
  • <strike> – Deprecated (use <del>)
  • <u> – Deprecated (use styles)

Computer Output Tags

  • <code> – Defines computer code
  • <kbd> – Defines keyboard input
  • <samp> – Defines sample output
  • <tt> – Defines teletype text
  • <var> – Defines a variable
  • <pre> – Defines preformatted text
  • <listing> – Deprecated (use <pre>)
  • <plaintext> – Deprecated (use <pre>)
  • <xmp> – Deprecated (use <pre>)

Citations, Quotations, and Definition Tags

  • <abbr> – Defines an abbreviation
  • <acronym> – Defines an acronym
  • <address> – Defines an address
  • <bdo> – Defines text direction
  • <blockquote> – Defines a long quotation
  • <q> – Defines a short quotation
  • <cite> – Defines a citation
  • <dfn> – Defines a definition term
HTML Character Entities, Links and Frames

Character Entities

Some characters like the < character have a special meaning in HTML and cannot be used directly.

To display a less than sign (<) in HTML, we must use a character entity like &lt; or &#60;.

A character entity has three parts:

  • An ampersand (&)
  • An entity name or number
  • A semicolon (;)

Entities are case sensitive.


Non-breaking Space

HTML normally removes extra spaces. To add extra spaces, use the non-breaking space entity: &nbsp;

Example: Hello   World


Most Common Character Entities

Result Description Entity Name Entity Number
  Non-breaking space &nbsp; &#160;
< Less than &lt; &#60;
> Greater than &gt; &#62;
& Ampersand &amp; &#38;
" Quotation mark &quot; &#34;

Character Entities Display

Some Other Commonly Used Character Entities:
Result    Description                  Entity Name    Entity Number
¢         cent                         &cent;     ¢
£         pound                        &pound;    £
¥         yen                          &yen;      ¥
€         euro                         &euro;     €
§         section                      &sect;     §
©         copyright                    &copy;     ©
®         registered trademark         &reg;      ®
×         multiplication               &times;    ×
÷         division                     &divide;   ÷

HTML uses a hyperlink to link to another document on the Web.

Anchor Tag Example

The Anchor Tag and the Href Attribute
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>
Anchor Tag Example

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 anantamu:


<a href="http://www.anantamu.com/">Visit anantamu!</a>

The line above will look like this in a browser:

Visit anantamu!

Target Attribute

Anchor Tag Target Attribute Example

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.anantamu.com/" target="_blank">Visit anantamu!</a>

The line above will look like this in a browser:

Visit anantamu!
Named Anchor Example

The Anchor Tag and the Name Attribute

The name attribute is used to create a named anchor. When using named anchors we can create links that jump directly to a specific section on a page, instead of making the user scroll.

Syntax of a named anchor:


<a name="label">Text to be displayed</a>

The name of the anchor can be any text you care to use. Below defines a named anchor:


<a name="tips">Useful Tips Section</a>

You should notice that a named anchor is not displayed in a special way.

To link directly to the "tips" section from another page, add a # sign and the name of the anchor to the end of a URL:


<a href="http://www.anantamu.com/html_links.asp#tips">
Jump to the Useful Tips Section</a>

From within the same file, you can jump to the "tips" section using:


<a href="#tips">Jump to the Useful Tips Section</a>

Jump to the Useful Tips Section

Useful Tips Section

Here is the content of the Useful Tips Section. You jumped directly here using the named anchor link above!


HTML Basic Notes and Tips

Basic Notes - Useful Tips

Always add a trailing slash to subfolder references. If you link like this: href="http://www.anantamu.com/html", the browser may generate two HTTP requests because the server will add a slash automatically, creating a new request like this: href="http://www.anantamu.com/html/".

Named anchors are often used to create a "table of contents" at the beginning of a large document. Each chapter within the document is given a named anchor, and links to each of these anchors are put at the top of the document.

If a browser cannot find a named anchor that has been specified, it goes to the top of the document. No error occurs.


Link Tags

Tag Description
<a> Defines an anchor

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.

Disadvantages of using frames:

  • The web developer must keep track of more HTML documents.
  • It is difficult to print the entire page.

HTML Frameset and Frame Tags

The Frameset Tag

  • The <frameset> tag defines how to divide the window into frames.
  • 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.

The Frame Tag

  • The <frame> tag defines what HTML document to put into each frame.

Example: 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 "frame_b.htm" into the second column:


<frameset cols="25%,75%">
   <frame src="frame_a.htm">
   <frame src="frame_b.htm">
</frameset>

Notes:

  • The frameset column size value can also be set in pixels: cols="200,500".
  • One column can take the remaining space: cols="25%,*".

Basic Notes - Useful Tips

  • If a frame has visible borders, the user can resize it by dragging the border. To prevent resizing, add noresize="noresize" to the <frame> tag.
  • Add the <noframes> tag for browsers that do not support frames.
  • Important: You cannot use <body></body> together with <frameset></frameset> tags. However, if you add a <noframes> section, the text inside it must be enclosed in <body></body> tags.
HTML Frame Tags

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 Tables Example

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 stand 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.

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

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

The border attribute specifies whether the table should have borders. You can set the value of the border in pixels, for example <table border="2"> for thicker borders.

HTML Tables Example

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:

Row 1, cell 1 Row 1, cell 2

Headings in a Table

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

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

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

Empty Cells in a Table

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

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

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 are missing (NB! Mozilla Firefox displays the border).
To avoid this, add a non-breaking space (&nbsp;) to empty data cells, to make the borders visible:

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

How it looks in a browser:

row 1, cell 1 row 1, cell 2
row 2, cell 1  
Table Sections Notes

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 in our XML tutorial.


Table Tags

  • <table> – Defines a table
  • <tr> – Defines a table row
  • <td> – Defines a table cell
  • <th> – Defines a table header
  • <caption> – Defines a table caption
  • <colgroup> – Groups table columns
  • <col> – Defines column properties
  • <thead> – Table header section
  • <tbody> – Table body section
  • <tfoot> – Table footer section
HTML Lists Example

Unordered Lists

An unordered list is a list of items. The list items are marked with bullets.

Display HTML Code

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

Ordered Lists

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

Display HTML Code

<ol>
    <li>Coffee</li>
    <li>Milk</li>
</ol>
Definition List Example

Definition List HTML Code


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

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.


List Tags

  • <ul> – Defines an unordered list
  • <ol> – Defines an ordered list
  • <li> – Defines a list item
  • <dl> – Defines a definition list
  • <dt> – Defines a definition term
  • <dd> – Defines a definition description
  • <dir> – Deprecated (use <ul>)
  • <menu> – Deprecated (use <ul>)
HTML Form Example

Form HTML Code


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

Rendered Form in Browser

A form is an area that can contain form elements. Form elements allow the user to enter information (like text fields, textarea fields, drop-down menus, radio buttons, checkboxes, etc.). A form is defined with the <form> tag.

HTML Input Fields Example

Input Field HTML Code


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

Rendered Input Fields in Browser

First name:

Last name:

Text fields are used when you want the user to type letters, numbers, etc. in a form. By default, most browsers display text fields with a width of 20 characters.


HTML Radio Buttons Example

Radio Button HTML Code


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

Rendered Radio Buttons in Browser

Male
Female

Note: Only one option can be selected at a time.


HTML Checkboxes Example

Checkbox HTML Code


<form>
I have a bike:
<input type="checkbox" name="vehicle" value="Bike">
<br>
I have a car: 
<input type="checkbox" name="vehicle" value="Car">
<br>
I have an airplane: 
<input type="checkbox" name="vehicle" value="Airplane">
</form>

Rendered Checkboxes in Browser

I have a bike:
I have a car:
I have an airplane:

Note: Multiple options can be selected at the same time.

HTML Form Action Example

Form HTML Code


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

Rendered Form in Browser

Username:

If you type some characters in the text field above and click the "Submit" button, your input will be sent to a page called html_form_action.asp. That page can then display or process the received input.

HTML Form Tags

Form Tags

Tag Description
Tag Description
<form> Defines a form for user input
<input> Defines an input field
<textarea> Defines a text-area (a multi-line text input control)
<label> Defines a label to a control
<fieldset> Defines a fieldset
<legend> Defines a caption for a fieldset
<select> Defines a selectable list (a drop-down box)
<optgroup> Defines an option group
<option> Defines an option in the drop-down box
<button> Defines a push button
<isindex> Deprecated. Use <input> instead
HTML Image Tag Example

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 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">

Example: An image named "boat.gif" located in the directory "images" on "www.anantamu.com" has the URL:
http://www.anantamu.com/images/boat.gif

The browser puts 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 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:

Example:

<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.

Example image with alt text:

Big Boat HTML Image Notes

Basic Notes - Useful Tips

If an HTML file contains ten images, eleven files are required to display the page correctly. Loading images takes time, so my best advice is: Use images carefully.


Image Tags

Tag Description
<img> Defines an image
<map> Defines an image map
<area> Defines a clickable area inside an image map
HTML Backgrounds

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 specifies a background-color for an HTML page. 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 set the background-color to black.

Background

The background attribute specifies a background-image for an HTML page. 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.anantamu.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?
  • 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?
HTML Background Notes

Basic Notes - Useful Tips

The bgcolor, background, and the text attributes in the <body> tag are deprecated in the latest versions of HTML (HTML 4 and XHTML). The World Wide Web Consortium (W3C) has removed these attributes from its recommendations.

Style sheets (CSS) should be used instead (to define the layout and display properties of HTML elements).

Color Values

HTML colors can be defined as a hexadecimal notation for the combination of Red, Green, and Blue color values (RGB).
The lowest value that can be given to one light source is 0 (hex #00) and the highest value is 255 (hex #FF).

The table below shows the result of combining Red, Green, and Blue light sources:

Red Green Blue Result
#FF0000 #00FF00 #0000FF Combination of RGB
HTML Color Values

HTML Color Values

RGB Color Combination Table

Color Color HEX Color RGB
#000000 rgb(0,0,0)
#FF0000 rgb(255,0,0)
#00FF00 rgb(0,255,0)
#0000FF rgb(0,0,255)
#FFFF00 rgb(255,255,0)
#00FFFF rgb(0,255,255)
#FF00FF rgb(255,0,255)
#C0C0C0 rgb(192,192,192)
#FFFFFF rgb(255,255,255)

W3C Standard Color Names

The 16 W3C standard color names are:

aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, yellow

Cross-browser Colors

Cross-browser Color Names

A collection of nearly 150 color names are supported by all major browsers.

View the cross-browser color names


Cross-browser Color Values

Some years ago, when most computers only supported 256 different colors, a list of 216 Web Safe Colors was suggested as a Web standard. The reason for this was that the Microsoft and Mac operating systems used 40 different "reserved" fixed system colors (about 20 each).

We are not sure how important this is now, since most computers today have the ability to display millions of different colors, but the choice is left to you.

The 216 cross-browser color palette was created to ensure that all computers would display the colors correctly when running a 256 color palette:

000000 000033 000066 000099 0000CC 0000FF
003300 003333 003366 003399 0033CC 0033FF
006600 006633 006666 006699 0066CC 0066FF
009900 009933 009966 009999 0099CC 0099FF
00CC00 00CC33 00CC66 00CC99 00CCCC 00CCFF
00FF00 00FF33 00FF66 00FF99 00FFCC 00FFFF
330000 330033 330066 330099 3300CC 3300FF
333300 333333 333366 333399 3333CC 3333FF
336600 336633 336666 336699 3366CC 3366FF
339900 339933 339966 339999 3399CC 3399FF
33CC00 33CC33 33CC66 33CC99 33CCCC 33CCFF
33FF00 33FF33 33FF66 33FF99 33FFCC 33FFFF
660000 660033 660066 660099 6600CC 6600FF
663300 663333 663366 663399 6633CC 6633FF
666600 666633 666666 666699 6666CC 6666FF
669900 669933 669966 669999 6699CC 6699FF
66CC00 66CC33 66CC66 66CC99 66CCCC 66CCFF
66FF00 66FF33 66FF66 66FF99 66FFCC 66FFFF
990000 990033 990066 990099 9900CC 9900FF
993300 993333 993366 993399 9933CC 9933FF
996600 996633 996666 996699 9966CC 9966FF
999900 999933 999966 999999 9999CC 9999FF
99CC00 99CC33 99CC66 99CC99 99CCCC 99CCFF
99FF00 99FF33 99FF66 99FF99 99FFCC 99FFFF
CC0000 CC0033 CC0066 CC0099 CC00CC CC00FF
CC3300 CC3333 CC3366 CC3399 CC33CC CC33FF
CC6600 CC6633 CC6666 CC6699 CC66CC CC66FF
CC9900 CC9933 CC9966 CC9999 CC99CC CC99FF
CCCC00 CCCC33 CCCC66 CCCC99 CCCCCC CCCCFF
CCFF00 CCFF33 CCFF66 CCFF99 CCFFCC CCFFFF
FF0000 FF0033 FF0066 FF0099 FF00CC FF00FF
FF3300 FF3333 FF3366 FF3399 FF33CC FF33FF
FF6600 FF6633 FF6666 FF6699 FF66CC FF66FF
FF9900 FF9933 FF9966 FF9999 FF99CC FF99FF
FFCC00 FFCC33 FFCC66 FFCC99 FFCCCC FFCCFF
FFFF00 FFFF33 FFFF66 FFFF99 FFFFCC FFFFFF

Color Values

HTML colors are defined using a hexadecimal notation for the combination of Red, Green, and Blue color values (RGB). The lowest value that can be given to one of the light sources is 0 (hex #00). The highest value is 255 (hex #FF).

HTML Color System

HTML Color System

Turn Off the Red

If you turn off the Red light completely, there are 65536 different combinations of Green and Blue (256 × 256) to experiment with.

Turn On the Red

By setting the Red parameter to its maximum value, there are still 65536 combinations of Green and Blue.

16 Million Different Colors

Combining Red, Green, and Blue values from 0 to 255 produces over 16 million colors (256 × 256 × 256).

Most modern monitors can display at least 16384 colors.

Red Light Variations

Color HEX RGB
#000000rgb(0,0,0)
#400000rgb(64,0,0)
#800000rgb(128,0,0)
#C00000rgb(192,0,0)
#FF0000rgb(255,0,0)

Shades of Gray

Color RGB HEX
rgb(0,0,0)#000000
rgb(64,64,64)#404040
rgb(128,128,128)#808080
rgb(192,192,192)#C0C0C0
rgb(255,255,255)#FFFFFF

HTML Color Names (Supported by Browsers)

Color Name HEX Preview
Red#FF0000
Green#008000
Blue#0000FF
Black#000000
White#FFFFFF
Yellow#FFFF00
Silver#C0C0C0
Aqua#00FFFF
Fuchsia#FF00FF

W3C recommends only 16 standard color names. Other colors should be defined using HEX or RGB values.

HTML Quick Glance

QUICK GLANCE:

HTML Quick List from anantamu. Print it, fold it, and put it in your pocket.


HTML Basic Document


<html>
<head>
<title>Document name goes here</title>
</head>
<body>
Visible text goes here
</body>
</html>

Heading Elements


<h1>Largest Heading</h1>
<h2>. . .</h2>
<h3>. . .</h3>
<h4>. . .</h4>
<h5>. . .</h5>
<h6>Smallest Heading</h6>

Text Elements


<p>This is a paragraph</p>
<br> (line break)
<hr> (horizontal rule)
<pre>This text is preformatted</pre>

Logical Styles


<em>This text is emphasized</em>
<strong>This text is strong</strong>
<code>This is some computer code</code>

Physical Styles


<b>This text is bold</b>
<i>This text is italic</i>

Links, Anchors, and Image Elements


<a href="http://www.example.com/">This is a Link</a>
<a href="http://www.example.com/"><img src="URL" alt="Alternate Text"></a>
<a href="mailto:webmaster@example.com">Send e-mail</a>

A named anchor:
<a name="tips">Useful Tips Section</a>
<a href="#tips">Jump to the Useful Tips Section</a>

Unordered List


<ul>
<li>First item</li>
<li>Next item</li>
</ul>

Ordered List


<ol>
<li>First item</li>
<li>Next item</li>
</ol>

Definition List


<dl>
<dt>First term</dt>
<dd>Definition</dd>
<dt>Next term</dt>
<dd>Definition</dd>
</dl>
HTML Reference: Tables, Frames, Forms, Entities

Tables


<table border="1">
<tr>
<th>someheader</th>
<th>someheader</th>
</tr>
<tr>
<td>sometext</td>
<td>sometext</td>
</tr>
</table>

Frames


<frameset cols="25%,75%">
  <frame src="page1.htm">
  <frame src="page2.htm">
</frameset>

Forms


<form action="http://www.example.com/test.asp" method="post/get"> 
<input type="text" name="lastname" value="Nixon" size="30" maxlength="50">
<input type="password">
<input type="checkbox" checked="checked">
<input type="radio" checked="checked">
<input type="submit">
<input type="reset">
<input type="hidden">

<select>
<option>Apples
<option selected>Bananas
<option>Cherries
</select>

<textarea name="Comment" rows="60" cols="20"></textarea>

</form>

Entities


< is the same as <
> is the same as >
© is the same as ©

Other Elements


<!-- This is a comment -->

<blockquote>
Text quoted from some source.
</blockquote>

<address>
Address 1<br>
Address 2<br>
City<br>
</address>

Everywhere on the Web you will find pages that are formatted like newspaper pages using HTML columns.
HTML Layout & Fonts

HTML Layout - Using Tables

One very common practice with HTML, is to use HTML tables to format the layout of an HTML page. A part of this page is formatted with two columns, like a newspaper page.

As you can see on this page, there is a left column and a right column. This text is displayed in the left column. An HTML <table> is used to divide a part of this Web page into two columns. The trick is to use a table without borders, and maybe a little extra cell-padding. No matter how much text you add to this page, it will stay inside its column borders.

Same Layout - Color Added

One very common practice with HTML, is to use HTML tables to format the layout of an HTML page. This text is displayed in the left column. An HTML <table> is used to divide a part of this Web page into two columns. The trick is to use a table without borders, and maybe a little extra cell-padding.

HTML Fonts

The <font> tag in HTML is deprecated. Even if a lot of people are using it, you should try to avoid it, and use styles instead.

The HTML <font> Tag

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>

Font Attributes

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-name" color="red" Defines the font color

The <font> Tag Should NOT be Used

The <font> tag is deprecated in the latest versions of HTML. The World Wide Web Consortium (W3C) has removed the <font> tag from its recommendations.

What is so Great About HTML 4.0?

In HTML 4.0 all formatting can be removed from the HTML document and stored in a separate style sheet. This separates presentation from document structure and gives full control over layout.

HTML Styles, XHTML & Head Element

What Should You Do About It?

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.


Prepare Yourself for XHTML

XHTML is the "new" HTML. The most important thing you can do is to start writing valid HTML 4.01.

  • Write tags in lower case
  • Always close your tags
  • Never end a paragraph without </p>

NOTE: The official HTML 4.01 recommends the use of lower case tags.


Validate Your HTML Files as HTML 4.01

HTML 4.01 Strict DTD:

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
    

HTML 4.01 Transitional DTD:

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
    

HTML 4.01 Frameset DTD:

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
    

HTML Styles

External Style Sheet

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
    

Internal Style Sheet

<head>
<style type="text/css">
body { background-color: red; }
p { margin-left: 20px; }
</style>
</head>
    

Inline Styles

<p style="color:red; margin-left:20px">
This is a paragraph
</p>
    

Style Tags

Tag Description
<style> Defines a style definition
<link> Defines a resource reference
<div> Defines a section in a document
<span> Defines a section in a document
<font> Deprecated. Use styles instead
<basefont> Deprecated. Use styles instead
<center> Deprecated. Use styles instead

Joke

Customer: Hello, it's me!
Support: It's me too!
Customer: No, Esmie. E, s, m, i, e!
Support: Sorry!

The Head Element

The head element contains general information, also called meta-information, about a document.

The elements inside the head element should not be displayed by a browser.

HTML Head, Meta, Links & Scripts

Legal Tags Inside the Head Section

According to the HTML standard, only a few tags are legal inside the head section:

<base>, <link>, <meta>, <title>, <style>, and <script>

Illegal example:

<head>
  <p>This is some text</p>
</head>
    

Most browsers will still display the text even if it is illegal. Should browsers forgive such errors? Some think yes, others think no.


Head Tags

Tag Description
<head> Defines information about the document
<title> Defines the document title
<base> Defines a base URL for all links
<link> Defines a resource reference
<meta> Defines meta information
<!DOCTYPE> Defines the document type

The Meta Element

The meta element provides meta-information about the document, mainly for browsers and search engines.

Description meta tag:

<meta name="description"
content="Free Web tutorials on HTML, CSS, XML, and XHTML">
    

Keywords meta tag:

<meta name="keywords"
content="HTML, DHTML, CSS, XML, XHTML, JavaScript, VBScript">
    

Due to misuse and spamming, many search engines no longer rely heavily on meta keywords.


Unknown Meta Attributes

<meta name="security" content="low">
    

Such meta attributes are site-specific and usually have no standard meaning.


HTML Links

Example link: Last Page

<a href="lastpage.htm">Last Page</a>
    

Uniform Resource Locator (URL)

scheme://host.domain:port/path/filename
    
  • scheme – protocol (http, ftp)
  • domain – domain name
  • port – default 80 for http
  • path – directory on server
  • filename – document name

URL Schemes

SchemeAccess
fileLocal file
ftpFTP server
httpWeb server
newsNewsgroup
telnetTelnet connection
WAISWAIS server

Script Example

<script type="text/javascript">
document.write("Hello World!")
</script>
    

Output: Hello World!


Handling Older Browsers

<script type="text/javascript">
<!--
document.write("Hello World!")
//-->
</script>
    
HTML Script, Attributes & Events

The <noscript> Tag

The <noscript> tag defines alternate text if a script is not executed. It is used for browsers that do not support scripts.

JavaScript Example:

<script type="text/javascript">
<!--
document.write("Hello World!")
//-->
</script>

<noscript>Your browser does not support JavaScript!</noscript>
    

VBScript Example:

<script type="text/vbscript">
<!--
document.write("Hello World!")
'-->
</script>

<noscript>Your browser does not support VBScript!</noscript>
    

Script Tags

TagDescription
<script>Defines a script
<noscript>Defines alternate text if script is not executed
<object>Defines an embedded object
<param>Defines parameters for an object
<applet>Deprecated. Use <object>

Core Attributes

Not valid in base, head, html, meta, param, script, style, and title elements.

AttributeValueDescription
classclass_ruleClass of the element
idid_nameUnique id
stylestyle_definitionInline CSS
titletooltip_textTooltip text

Language Attributes

Not valid in base, br, frame, frameset, hr, iframe, param, and script.

AttributeValueDescription
dirltr | rtlText direction
langlanguage_codeLanguage code

Keyboard Attributes

AttributeValueDescription
accesskeycharacterKeyboard shortcut
tabindexnumberTab order

Window Events

Only valid in body and frameset elements.

AttributeDescription
onloadRuns when page loads
onunloadRuns when page unloads

Form Element Events

AttributeDescription
onchangeElement value changes
onsubmitForm is submitted
onresetForm is reset
onselectText selected
onblurElement loses focus
onfocusElement gets focus

Keyboard Events

AttributeDescription
onkeydownKey pressed
onkeypressKey pressed & released
onkeyupKey released

Mouse Events

AttributeDescription
onclickMouse click
ondblclickDouble click
onmousedownMouse button pressed
onmousemoveMouse moves
onmouseoutMouse leaves element
onmouseoverMouse enters element
onmouseupMouse button released

ASCII URL Encoding

Hexadecimal values are used to display non-standard characters in URLs.

Example: Space = %20

URL Encoding and Web Server Notes

URL Encoding

URL encoding is used to convert characters into a format that can be transmitted over the Internet. Characters are replaced with a % followed by their hexadecimal ASCII value.

URL-encoding from %00 to %8F

ASCII URL Code ASCII URL Code ASCII URL Code
space%20 0%30 A%41
!%21 1%31 B%42
"%22 2%32 C%43
#%23 3%33 D%44

URL-encoding from %90 to %FF

ASCII URL Code ASCII URL Code
À%C0 à%E0
Á%C1 á%E1
Â%C2 â%E2
Ã%C3 ã%E3

Your First Step: A Personal Web Server

  • If you want other people to view your pages, you must publish them.
  • To publish your work, you must copy your files to a web server.
  • Your own PC can act as a web server if it is connected to a network.
  • Windows 98 users can use PWS (Personal Web Server).
  • PWS is available on the Windows CD.

Personal Web Server (PWS)

A Personal Web Server allows you to test and host web pages locally before publishing them online.

PWS, IIS and HTML Reference

Personal Web Server (PWS)

PWS turns any Windows computer into a Web server. PWS is easy to install and ideal for developing and testing Web applications. PWS has been optimized for workstation use, but has all the requirements of a full Web server. It also runs Active Server Pages (ASP) just like its larger brother IIS.


How to Install a Personal Web Server (PWS)

  • Browse your Windows installation to see if PWS is already installed.
  • If not, install PWS from the PWS directory on your Windows CD.
  • Follow the instructions and get your Personal Web Server running.

Note: Microsoft Windows XP Home Edition does not support PWS.


Internet Information Server (IIS)

Windows 2000's built-in Web server IIS makes it easy to build large Web applications. Both PWS and IIS include ASP, a server-side scripting standard used to create dynamic and interactive Web applications.

IIS is also available for Windows NT.


Your Next Step: A Professional Web Server

  • If you do not want to use PWS or IIS, upload your files to a public server.
  • Most Internet Service Providers (ISPs) offer web hosting.
  • If your employer has an Internet server, ask them to host your website.
  • If you are serious, install your own Internet server.

HTML Summary

HTML is the universal markup language for the Web. HTML lets you format text, add graphics, create links, forms, frames, and tables.

HTML documents are saved as text files and can be read by any browser. The key to HTML is the use of tags, which describe the content.


Now You Know HTML, What's Next?

The next step is to learn XHTML and CSS.

XHTML

XHTML is the next generation of HTML. HTML 4.01 is the final version of HTML. XHTML is stricter and cleaner and will replace HTML.


HTML Tags Reference

Ordered Alphabetically

Tag Description DTD
<!--...--> Defines a comment STF
<!DOCTYPE> Defines the document type STF
<a> Defines an anchor STF
<b> Defines bold text STF
<body> Defines the body element STF
<br> Inserts a line break STF
<div> Defines a section in a document STF
<img> Defines an image STF
<p> Defines a paragraph STF
<table> Defines a table STF

HTML Tags by Function

Basic Tags

  • <html> – Defines an HTML document
  • <head> – Contains document information
  • <title> – Defines the document title
  • <body> – Defines the body

Formatting Tags

  • <b> – Bold text
  • <i> – Italic text
  • <u> – Underlined text (deprecated)
  • <strong> – Strong importance
  • <em> – Emphasized text

Lists

  • <ul> – Unordered list
  • <ol> – Ordered list
  • <li> – List item

Forms

  • <form> – Defines a form
  • <input> – Input field
  • <textarea> – Text area
  • <button> – Button

Note: HTML tags can have attributes. Core and language attributes are common to most tags.

HTML Attributes Reference

HTML Attributes

Core Attributes

Not valid in base, head, html, meta, param, script, style, and title elements.

Attribute Value Description
class class_rule or style_rule The class of the element
id id_name A unique id for the element
style style_definition An inline style definition
title tooltip_text Text to display as a tooltip

Language Attributes

Not valid in base, br, frame, frameset, hr, iframe, param, and script elements.

Attribute Value Description
dir ltr | rtl Sets the text direction
lang language_code Sets the language code

Keyboard Attributes

Attribute Value Description
accesskey character Sets a keyboard shortcut to access an element
tabindex number Sets the tab order of an element

HTML Event Attributes

HTML 4.0 introduced the ability to trigger browser actions using events, such as running JavaScript when a user clicks an element.


Window Events

Only valid in body and frameset elements.

Attribute Value Description
onload script Runs when the document loads
onunload script Runs when the document unloads

Form Element Events

Only valid in form elements.

Attribute Value Description
onchange script Runs when the element value changes
onsubmit script Runs when the form is submitted
onreset script Runs when the form is reset
onselect script Runs when text is selected
onblur script Runs when the element loses focus
onfocus script Runs when the element gets focus

Keyboard Events

Attribute Value Description
onkeydown script Runs when a key is pressed
onkeypress script Runs when a key is pressed and released
onkeyup script Runs when a key is released

Mouse Events

Attribute Value Description
onclick script Runs on mouse click
ondblclick script Runs on mouse double-click
onmousedown script Runs when mouse button is pressed
onmousemove script Runs when mouse pointer moves
onmouseover script Runs when mouse pointer enters an element
onmouseout script Runs when mouse pointer leaves an element
onmouseup script Runs when mouse button is released

School