LAB I T HTML: Ntroduction O
LAB I T HTML: Ntroduction O
INTRODUCTION TO HTML
Approximate Time
The exercises in this lab should take approximately 30 minutes to complete.
2 Lab 2: Introduction to HTML
1 If you haven’t done so already, create a folder in your personal drive for all the labs for
this book.
2 From the main labs folder (either downloaded from the textbook’s web site using code
provided with book or in a common location provided by your instructor), copy the folder
titled lab02 to your course folder created in step one.
Now we are ready to create our first web page.
1 Using some type of text or HTML editor (such as Notepad, Notepad++, PSPad, etc), type
in the following:
<!DOCTYPE html>
<title>A Very Small Document</title>
<p>This is a simple document with not much content</p>
Note: these labs use the convention of red bolded text to indicate content to
change/enter.
2 Save the file as lab02‐exercise01.html in the lab02 folder on your personal drive (the
folder you just created in the Preparing Directories step above).
3 Start up FireFox, Chrome, Internet Explorer or some other browser. Open the file lab02‐
exercise01.html. To do this, you could use the Open command in the menu, drag-and-
drop the file from the file manager of the operating system, or double-click the file from
the operating system file manager.
This will display the file created in step one in the browser window.
4 Switch back to your text editor. Position the cursor before “This is a simple” and then
press Enter three times. Position cursor after the word “much”. Press space five times.
5 Save the changes and then switch back to browser. Refresh the page.
Notice that the browser ignores extra spaces and paragraph returns.
6 Remove the extra spaces and returns added in step 4. Save changes.
Fundamentals of Web Development 3
EXERCISE 2.2 — ADDITIONAL STRUCTURE TAGS
2 Save your file as lab02‐exercise02.html and test file in browser. The result should
look similar to that shown in Figure 2.1.
Figure 2.1 – Exercise 2 Complete
1 Open lab02‐exercise03.html (which has the same content as the last exercise).
2 Before the text “Conservatory” (in the second paragraph tag), add the tag <randy>.
3 Save and then test in browser. After testing, remove the <randy> tag.
Sadly there is no <randy> tag in HTML. Your browser will simply ignore any tag it does
not recognize.
4 Remove the trailing </h1> end tag, save and then test.
Since the <h1> tag is never closed, the browser assumes that the content after it should
continue being displayed as a first-level heading.
5 Put back the trailing </h1> end tag (i.e., after “Share Your Travels”).
6 Change the <h1> tag to <H1>, save and then test.
Notice that HTML5 is case insensitive.
LINKING
Hyperlinks are an essential feature of any web page. Links are created via
the anchor (<a>) element.
ADDING IMAGES
EXERCISE 2.5 — ADDING IMAGES
2 Modify the image tag as follows and test (be sure to move your mouse over the image).
<img src="images/central‐park.jpg" alt="Central Park"
title="Central Park" />
The title attribute is used to display a tooltip; Internet Explorer, also displays the content
of the alt attribute in a tooltip if there is no title attribute specified.
3 Change the src attribute to the following (i.e., add a slash before the folder name) and
test.
<img src="/images/central‐park.jpg" alt="Central Park"
title="Central Park" />
You will no longer see the central park image. Why? Because the root reference does
not work when tested locally.
Also, depending on the browser, you may or may not see a missing image icon, as
shown in Figure 2.2. Notice that all three of the browsers in the Figure 2.2 will also
display the alt attribute, but Firefox does not display a missing image icon.
What would we see in Firefox if the missing <img> did not have an alt attribute
defined? The answer is nothing. While this makes sense perhaps from an end-user
perspective, from a developer’s perspective this behavior can be frustrating. This is one
of the many reasons why we strongly recommend testing your pages in multiple
browsers.
Figure 2.2 – Missing image indication in different browsers
7 Remove the returns between each <img> tag, as shown below, and then test.
<p>Share:
<img src="images/social/email_16.png" alt="Email this to someone" /><img
src="images/social/rss_16.png" alt="Syndicated content" /><img src=
"images/social/twitter_16.png" alt="Share this on Twitter" />
</p>
Notice that the browser interprets each (or multiple ones in a row) carriage return in the
HTML as a single space, as shown in Figure 2.3.
Fundamentals of Web Development 7
Figure 2.3 – Carriage return treated as a space
LIST BASICS
Lists are a way of organizing information. HTML supports several different
types of list: definition lists, ordered lists, and unordered lists.
It is common practice to create a list of related links. The next exercise
demonstrates this technique.
EXERCISE 2.7 — LINKING WITH LISTS
1 Continue working with lab02‐exercise05.html and add the following to the list and
test:
<ul>
<li><a href="#">Description</a></li>
<li><a href="#">Reviews</a></li>
</ul>
Notice the target for the links (i.e., href="#"). The # simply indicates the current page
(i.e., it goes nowhere). This is a common technique for showing links whose
destinations are not yet known.
1 Open lab02‐exercise11.html, view in browser, then add the following to the large
image and test.
<figure>
<a href="images/large‐central‐park.jpg"><img src="images/central‐park.jpg"
alt="Central Park" title="Central Park"/></a>
<figcaption>Conservatory Pond in Central Park</figcaption>
</figure>
<p>Share: <br/>
Here’s a surprise … there is in fact a little bit of additional browser formatting for the
<figure> HTML5 semantic element. Also notice that we are not wrapping the share
icon images in a <figure> element. As discussed in the text, the <figure> element
should be used only for images (or other content) that is essential but whose position
on the page could change. The share icons are not really essential so they are not
contained within a <figure>.
Fundamentals of Web Development 11
VALIDATING HTML
In the next exercise, we will use an external validation service to verify that
our web page contains HTML that is valid according to the HTML5 DTD.
4 Remove the closing </ul> element, save, and then redo steps 1-3 of this exercise.
The page will not be valid and the service may find not one but many errors. At the time
of writing, the validator lists the missing </ul> element as error number 10. Thus, while
a validator can help you find an error in your markup, the error messages do take some
interpretation.
5 Put the closing </ul> tag back in, save, and re-validate.
Figure 2.4 – Using a validation service