HTML

This webpage lists all the HTML Tags that a student is expected to understand after finishing the E-learning material. For each topic, we list some examples, the corresponding outputs, as well as the related E-learning materials (follow the link).
The HTML tutorial prepared by W3School (
http://www.w3schools.com/html/) is selected as the complementary material.


Table of Contents

  1. Table Tags
  2. Advanced Tags
  3. Frequently Asked Questions
  4. More Exercises


HTML

  1. HTML stands for Hyper Text Markup Language
  2. An HTML file is a text file containing small markup tags
  3. The markup tags tell the Web browser how to present the text sent
  4. An HTML file must have an htm or html file extension
  5. An HTML file can be created using a simple text editor
  6. Each tag will appear as letters or words between a < (less than sign) and a > (greater than sign).
  7. Example:

<HTML></HTML>

Back to Top


Basic Tags weblink

The basic html tags that are used to create a simple web page are the tags that define titles, links, headings, comments, paragraphs, line breaks etc. 

HTML

Tells the Web browser that this is the beginning of an HTML document .             

  <html>       </html>


BODY

       <body>
           My first html page
      </body>


HEAD and TITLE

          <head>      
                 <title>
MyPage </title>         
          </head>      


 TAG Attibutes weblink

      <body bgcolor="green">
           My first html page with green background
      </body>

The example above gives a green background to the html page. Click to see.

      <body background="sunset.jpg">
           My html page with sunset image
      </body>

The example above gives a sunset.jpg as a background to the html page. Sunset.jpg file is the same directory of the sunset.html file. Click to see.

Back to Top


 Exercise 1: Simple HTML file.

Step 1: If you are running Windows, start Notepad.

Step 2: Writes the following text into notepad.

<html>
    <head>
        <title>My Page</title>
    </head>
    <body bgcolor="yellow">
        This is my first html page. 
    </body>
</html>

Step 3: Save the file as "c:\html\mypage.html". 

Step 4: Start your Internet browser. Enter C:\html\mypage.html in the address bar. Click Enter.

Click to see the result.

Back to Top


 Headings weblink

<h1>This is a heading 1</h1>
<h2>This is a heading 2</h2>

The example above shows two texts with different font size. Click to see.


 Paragraphs

<p>This is a paragraph</p>

The example above shows a paragraph. Click to see.


 Line Breaks

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

The example above shows a paragraph with line breaks. Click to see.


 Comments

<!-- This is a comment -->

 


 Links  weblink

 

             <a href="http://www.google.com"> link
            </a> to the google web site. 

Back to Top


Exercise 2: Simple HTML file with link, header, breaks and comments.

Step 1: If you are running Windows, start Notepad.

Step 2: Writes the following text into notepad.

<html>
    <head>
        <title>My Page</title>
    </head>
    <body bgcolor="yellow">
         <!-- You can't see me on browser, I am a comment -->
         <h1> This is header 1 </h1> <br>
          I am a <a href="
http://www.google.com" > link
            </a> to the google web site.
         <br>
         <p>HTML is Hypertext Markup Language</p>
     </body>
</html>

Step 3: Save the file as "c:\html\mypage2.html". 

Step 4: Start your Internet browser. Enter C:\html\mypage2.html in the address bar. Click Enter.

 

Click to see the result.


Basic HTML Tags

Tag

Description

<html>

Defines an HTML document

<body>

Defines the document's body

<h1> to <h6>

Defines header 1 to header 6

<p>

Defines a paragraph

<br>

Inserts a single line break

<hr>

Defines a horizontal rule

<!-->

Defines a comment

<a> Defines an anchor

Back to Top


Table Tags   weblink


The tags in this section are used to create the tables on the web document.


 Table

      <table border="1">
      </table>


 Row

      <table border="1">
           <tr>
           </tr>
      </table>

  • border="1" represents the border width in pixels for the table.
  • Set border="0" to display tables with no borders!

  •  Table Cell

          <table border="2">
             <tr>
                <td>School of Information Systems</td>
                <td>80 Stamford Road Singapore 178902
    </td>
             </tr>
          </table> 

    The example above shows a table with one row and two columns. Click to see.


     Header

          <table border="1">
             <tr>
                <th>School</th><th>Address</th>
                   
    <th>My
    School</th> <th>MyAddress</th>
             </tr>
          </table> 

    The example above shows a table with a header and one row. The table has two columns. Click to see.


     Exercise 3: HTML file with tables.

    Step 1: If you are running Windows, start Notepad.

    Step 2: Writes the following text into notepad.

     <html>
      <body>
        <table border="1" bgcolor="green">
          <tr>
            <th>School</th>
            <th>Address</th>
          </tr>
          <tr>
            <td>School of Information Systems</font></td>
            <td>80 Stamford Road Singapore 178902</td>
          </tr>
          <tr>
            <td>
    School of Economics</td>
            <td>
    90 Stamford Road Singapore 178903</td>
          </tr>
        </table>
      </body>
    </html>

    Step 3: Save the file as "c:\html\mypage2.html". 

    Step 4: Start your Internet browser. Enter C:\html\mypage2.html in the address bar. Click Enter.

     

    Click to see the result.

    Back to Top


     Table Tags Summary

    Tag

    Description

    <table>

    Defines a table

    <th>

    Defines a table header

    <tr>

    Defines a table row

    <td>

    Defines a table cell

    Back to Top


    Advanced Tags

    This tags in this section are used to create forms which are used to select different kinds of user input.


    Form  weblink

      <form action="/process" method="post">
      </form> 

    Back to Top


    Form Components

    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.
    Rules to create the form components:
    1. Every component must have either a NAME or ID to identify it. Submit and Reset are exceptional.
    2. The components are created using th <INPUT> tag except the list which is created using <SELECT> tag
    3. Each type of component is recognised by the TYPE attribute. for eg:
    TEXT FIELD:      <INPUT TYPE="TEXT" NAME="COLOR">
    RADIO BUTTON:  <INPUT TYPE="RADIO" ID="GENDER">
    4. The VALUE attribute represents the value for the components and is optional. If you specify the value, then it is the default value else the user will input the value during run-time.

    Text Fields

    <html>
      <body>
        <form action="/process">
        Name:
          <input type="text" name="aName"  value="default value"
                size="20">
        </form>
      </body>
    </html>

    Click to see how it looks on browser

    Back to Top


     Radio Buttons

     <html>
      <body>
        <form action="/process">
          Your preferred Color:
            <input name="color" type="radio" value="red" checked>Red
            <input name="color" type="radio" value="green">Green
            <input name="color" type="radio" value="blue">Blue
        </form>
      </body>
    </html>

     Click to see how it looks on browser

    Back to Top


     Check Boxes

    <html>
      <body>
        <form action="/process.html">
         My favourite colors:
          <input name="color" type="checkbox" value="red" checked>Red
          <input name="color" type="checkbox" value="green" checked>Green
          <input name="color" type="checkbox" value="blue"> Blue
         </form>
       </body>
    </html>

    Click to see how it looks on browser

    Back to Top


     Dropdown List (Single Selection)

     <html>
      <body>
        <form action="/process">
          My favorite color:
          <select name="color">
            <option value="R" selected>red
            <option value="G">green
            <option value="B">blue
          </select>
        </form>
      </body>
    </html>  

    Click to see how it looks on browser

    Back to Top


     Dropdown List (Multiple Selection)

    <html>
      <body>
        <form action="/process">
          My favorite colors:
          <select name="color" SIZE="3" MULTIPLE>
            <option value="R" selected>red
            <option value="G">green
            <option value="B" selected>blue
          </select>
        </form>
      </body>
    </html>

    Click to see how it looks on browser

    Back to Top


    Hidden Field


            <input type="hidden" name="user" value="SMU">

    Click to see how it looks on browser

    Back to Top


    Buttons

    Buttons are elements on the form which are used for the user actions. You can define the buttons which are of type Submit or Reset.


     Submit

      <html>
        <body>
           <form action="/process">
              <input type="submit">
              <input type="submit" value="Register">
              <input type="submit" name="operation" value="Send Mail">
         
      </form>
        </body>
    </html>

    Click to see how it looks on browser    

    Back to Top


     Reset

    <html>
      <body>
        <form action="/process">
            <input type="text" value="reset me">
     <input type="reset">
        </form>
      </body>
    </html>

    Click to see how it looks on browser

    Back to Top


    Password

                  <input type="password" name="pwd" size="20">

    Click to see how it looks on browser

    Back to Top


    Exercise 4: HTML file with forms

    Step 1: If you are running Windows, start Notepad.

    Step 2: Writes the following text into notepad.

    <html>
        <body>
           <form action="process.html">
                 Name: <input type="text" name="aName"  value="default value"><br>
                 Password:<input type="password" name="pwd" size="20"><br>
                 Choose your favorite color:
                    <input name="color" type="radio" value="red" checked>Red
                    <input name="color" type="radio" value="green">Green
                    <input name="color" type="radio" value="blue">Blue <br>
                 Choose your favorite fruits:
                     <input name="fruit" type="checkbox" value="Apple" checked>Apple
                    <input name="fruit" type="checkbox" value="Pear" checked>Pear
                    <input name="fruit" type="checkbox" value="Banana"> Banana <br>
                 Select your favorite languanges: <br>
                    <select name="color" size=3 multiple>
                           <option value="J" selected>Java
                           <option value="H">HTML
                           <option value="A">ASP
                    </select> <br>
                 <input type="submit" value="Submit">
                 <input type="reset">          
            </form>
        </body>
    </html>

    Step 3: Save the file as "c:\html\myform.html". 

    Step 4: Start your Internet browser. Enter C:\html\myform.html in the address bar. Click Enter.

     

    Click to see the result.

    Back to Top


     Advanced Tags Summary

    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)

    <select>

    Defines a selectable list (a drop-down box)

    <input type=”radio”>

    Defines a radio button

    <input type=”checkbox”>

     Defines a check box

    <input type=”password”>

     Defines a password

    <input type=”hidden”>

     Defines a hidden field

    <input type=”submit”>

     Defines a submit button

    <input type=”reset”>

     Defines a reset button

    Back to Top


    Frequently Asked Questions

    Q: After I have edited an HTML file, I cannot view the result in my browser. Why?
    A:
    Make sure that you have saved the file with a proper name and extension like "c:\mypage.htm". Also make sure that you use the same name when you open the file in your browser.

     

    Q: I have edited an HTML file, but the changes don't show in the browser. Why?
    A:
    A browser caches pages so it doesn't have to read the same page twice. When you have modified a page, the browser doesn't know that. Use the browser's refresh/reload button to force the browser to reload the page.

     

    Q: What browser should I use?
    A:
    You can do all the training with all of the well-known browsers, like Internet Explorer, Firefox, Netscape, or Opera. However, some of the examples in our advanced classes require the latest versions of the browsers.

    Q: Why do I see different fonts for the same html file in diferent browsers?
    A: When you write HTML text, you can never be sure how the text is displayed in another browser. Some people have large computer displays, some have small. The text will be reformatted every time the user resizes his window. Never try to format the text in your editor by adding empty lines and spaces to the text.

    Q: How to seperate sections?
    A:
    Use the <hr> tag to seperate sections.

    Q: How do I display "<" on the browser?
    A:
    Some characters like the < character, have a special meaning in HTML, and therefore cannot be used in the text.

    Q: What the free HTML editors ?
    A:
     
    Notepad++, HTML kit, Textpad etc

    Back to Top


    More Exercises

    This link http://www.w3schools.com/html/html_examples.asp provides an editor where, you can edit HTML, and click on a test button to view the result.


    Back to Top

     © Copyright 2008 Singapore Management University. All Rights Reserved