HTML is the HyperText Markup Language, the language used to build Web pages. It is used to describe how text, images, and multimedia are displayed by Web browsers. In this lab you will learn the basics of HTML and create a web page containing headings, paragraphs, lists, images, and links. Section 6.2 of the textbook (pages 510-516 discusses HTML.) The process of creating and publishing a web page involves several steps:
http://cs.roanoke.edu/Spring2007/CPSC101AClick on the link to this lab. You will see an electronic version of this handout. Follow the handout (either online or on paper) for today's lab work.
<title>HTML Lab</title>There are a few tags that almost every document will have: <html>, <head>, <title>, <body>, and <p>. Here is an example of a simple HTML document:
<html> <head> <title>HTML Lab</title> </head> <body> <p> In this lab you will learn about HTML, a markup language for Web pages. The HTML document is nothing but text - words and tags. The tags "mark up" the text - they give the browser information about how to display the text. The part of the document between the <body> and </body> is what is displayed in the browser window. The <p> tag indicates a paragraph. </p> <p> Here is another paragraph. The browser will display a blank line between paragraphs. The <title> tag is used to specify the text that appears on the title bar of the browser window when the page is displayed. </p> </body> </html>Click here to see what this looks like in the browser. Change the size of the browser window (click and drag any corner) and see how the text is reformatted as the window changes. Note that the title appears on the title bar of the window, not as part of the document.
The head of a document (everything between <head> and </head>) contains the introduction to the document. The title goes in the head, but for now we won't use the head for anything else. The body of a document (everything between <body> and </body>) contains everything that will be displayed as part of the document. Both the head and the body are enclosed by the HTML tags, which begin and end the document.
This document contains only plain text, but an HTML document can have much more structure: headings, paragraphs, lists, bold and italic text, images, links, tables, and so on. Here is a version that contains a heading and two paragraphs. Note that the tag pair for a heading is <h1 align="center"> ... <h1> (that is a one not an el).
<html> <head> <title>HTML Lab</title> </head> <body> <h1 align="center">Dr. Ingram's Web Page</h1> <p> This is the first paragraph of Dr. Ingram's page. Pretty boring, huh? You could come up with something much more interesting! </p> <p> Here is another paragraph. When you go on to a new topic, you can start a new paragraph. You don't have to worry about indenting or otherwise formatting the paragraph -- the browser will decide that for you. Usually it leaves a blank line. If you just want to go to a new line, without any vertical space, you <br> can <br>do <br> that <br> too. </p> </body> </html>Click here to see what this looks like in the browser.
In this document the <h1> tag creates a level 1 heading. This is the biggest heading; it might be used at the beginning of the document or the start of a new chapter. The align attribute was used in the tag to tell the browser to center the heading. If that were left out the heading would be left aligned. Level 2 through level 6 headings are also available with the <h2> through <h6> tags.
The <p> tag creates a new paragraph. Most browsers leave a blank line between paragraphs. The end tag </p> for a paragraph is optional - the browser knows one paragraph ended when it encounters another one. The <br> tag (line break tag) just goes to the next line, without leaving a blank line.
Note that line breaks and blank lines in the HTML document do not matter -- the browser will format paragraphs to fit the window. If it weren't for the <P> tag, the blank line between the paragraphs in this document would not show up in the displayed document.
<html> <head> <title> ... put your own title in here ... </title> </head> <body> <h1 align="center"> ... heading for your page here ... </h1> <p> ... your first paragraph goes here ... a brief bio of yourself </p> <p> ... another paragraph goes here ... something you are passionate about </p> </body> </html>
When you are done, save your page as follows:
Viewing the File: We use the browser to see what the page looks like. Leave Notepad open because you'll be coming back to it to make additions (and maybe corrections). In Netscape click on File then Open File. You will get the usual Windows Open window. Go to the Look In box and select the Z drive (use the down arrow to find it) and your CPSC101 folder. You should see default.htm in the list of files. Click on it then click open. If all your tags are correct you should see your page. Make sure you see your title on the title bar of the window and that the content of your page shows up (including the heading) without any stray tags showing. If it doesn't you probably have a typo in a tag. You will need to go back to Notepad to fix it.
Lists We often want to add a list to a document. HTML provides two kinds of lists, ordered (e.g., 1, 2, 3) and unordered (e.g., bulleted). A list is introduced with the <ol> or <ul> tag, depending on whether it is ordered or unordered. Each list item is introduced with a <LI> tag and ended with the </LI> tag (which is optional). The entire list is then ended with </ol> or </ul>, as appropriate. The following is an ordered list of instructions for creating a list:
<ol> <li>Type the tag <ol> (if you want an ordered list) or <ul> (if you want an unordered list) <li>For each item in your list, type the <li> tag followed by the text you want in the list. <li>To end the list type the tag </ol> or </ul> (depending on the list type - match the beginning tag) </ol>Click here to see what this looks like in the browser.
*** Exercise: Update your page! Add a list, either ordered or unordered, of at least three items to your document. Your list should have a heading (use a smaller heading tag - either an <h2> or <h3>). Make your list related to what is already on the page.
After typing your list in your document, reload the document in Netscape to make sure it displays correctly. If it doesn't, check your tags and make corrections!
More Tags There's lots you can do with HTML. You can make the page a pretty color, <u>underline</u> text, or put it in <i>italics</i> or <b>bold</b>. You can also make links and tables, but we'll get to those later. The <b> tag creates bold text, the <i> tag creates italic text, and the <u> tag creates underlined text. Note that each of these tags is closed with the corresponding end tag.
*** Exercise: Enhance Your Page Add bold, italics, and underlining to your page. Choose appropriate parts of your page for each (don't get carried away and make the whole page bold, for example). After adding the tags for bold, italics, and underline, save your page, then reload it in Netscape. Make sure things look right!
Visit <a HREF="http://cs.roanoke.edu/Spring2007/CPSC101A">my favorite course!</a>creates a link to the CPSC 101 home page that link looks like this when the browser displays it:
Visit my favorite course!
When adding a link to a page it is important to get the URL exactly right - a small typo will cause a link to not work. One way to be sure to get the link right is to do the following: In Netscape go to the page you want to link your page to. Then, using your mouse, highlight the URL in the location box at the top of the page. Now right click on the highlighted URL then choose Copy. In Notepad, place your cursor in your anchor tag and choose Edit, Paste (or use CTRL-V). The correct URL will be there but you need to correctly type in the rest of the anchor tag (including the HREF= and the quotation marks, etc).
*** Exercise: Add Links to your page: Add at least two links to external Web sites that tie in to the material on your page. Don't link to the course home page! You can put your links in a paragraph some place (for example you can make a word in a sentence a link) or you can make a list of links. Be sure that you use meaningful words for your links! After adding the links reload your page and click on each link to make sure it is correct.
Images You can add any picture to a web page with an <img> tag. The tag must specify the source file using the SRC attribute. For example,
<img SRC="smiley.gif">adds the picture in the smiley.gif file (note - this assumes that file is stored in the same directory as the Web page). You can scan pictures, use pictures taken from a digital camera, or get copies of pictures that are on the web (as long a they are not copyrighted!). The image files should be either .jpg or .gif since most browsers know how to display these formats (in other words they know the compression algorithms that can decode the image). If you don't have your own images you can find images on the Web to use. One way to use images you find on the Web is to put the Web address (URL) of the image in the SRC attribute of the IMG tag. Another way is to save the image to your computer or network drive. To save an image, right click on it then choose the "Save Image As" option. Then save it to the same folder you have your Web page in (for today's lab that is your CPSC101 folder on the Z drive).
*** Exercise: Add an Image Add an image to your page. The image should be related to the page (it can be a picture of you, for example, or a picture of something you are passionate about). Placement of images can be tricky - they often don't show up where you want. For today don't worry about that. Using a table to help place them is a common trick. We'll learn about tables later!