-->
Previous Table of Contents Next


You’ll find that HTML is pretty straightforward:

  All HTML tags are enclosed by angle brackets (the < and > characters). The <HTML> tag at the beginning of Listing 32.1 is an example.
  Most HTML tags require you to use a starting tag (<tag_name>) and an ending tag (</tag_name>). You start and stop formatting by the placement of these tags. If you leave out a required ending tag, you won’t see any formatting; you may not even see the text.
  Many HTML tags have attributes that you can customize. An attribute allows you to change the default behavior of a tag. If you want a table without a border, for example, you change it by setting an attribute (BORDER= some_number) within the <TABLE> tag.
  All HTML files require an <HTML> tag at the beginning of the file and the closing </HTML> tag at the end. These tags tell a Web browser that the document it’s processing is written in HTML.

An HTML document typically consists of two logical sections: the head and the body. The head contains information about the document; the body contains the document information itself. As you may have guessed, the header section is enclosed with the <HEAD> and </HEAD> tags, whereas the body is enclosed with the <BODY> and </BODY> tags.

The head section of an HTML page contains information related to the document itself. You can place several tags in the header section, but the <TITLE> tag is the most widely used. The document title—whatever is enclosed with the <TITLE> and </TITLE> tags—appears in the title bar of a Web browser.

The body section of an HTML page contains most of the elements you see when viewing the page with a Web browser. This is where you enter all the elements you want people to see, such as text, graphics, links (URLs), lists, and tables.


NOTE:  The <TITLE> element identifies the name of your page. When someone makes a bookmark to the page, this is name that is used. Although HTML doesn’t limit the length of the <TITLE> element, you should consider giving the page a short, descriptive title that can easily be displayed. A good rule of thumb for the length of a title is no more than a single phrase and no longer than 60 characters.

Because the document title is displayed in a separate window and isn’t part of the document itself, the title text itself must be plain text and not have any hyperlinks or text formatting.



TIP:  One really nice thing about HTML source code is that you can look at it. Have you ever found an interesting page and wanted to know how it was done? Take a look! You can learn a lot by looking at other people’s source code.

Viewing the source code is usually done through a menu choice in your Web browser. For example, to see HTML source code for a page under Netscape, choose Document Source from the View menu.


Now that you’ve seen the basics of HTML (yes, that’s really it!), it’s time to learn about tags and how they’re used. Although there are many different tags, you’ll find that by mastering just a handful (and combining them in different ways), you can create excellent Web pages.

Using Basic HTML Elements

Basic HTML syntax consists of three components: tags, attributes, and URLs. These components, respectively, give the details of how items are to be formatted and displayed, the specifics of certain actions, and the locations of other files and documents.

Tags

The basic building blocks of HTML, tags are the part of HTML that tells a Web browser how to display text and graphics, along with other format information. As you may recall, tags are written between angle brackets (<tag_name>) and most tags also require an ending tag (</tag_name>) as well. As you may recall from Figure 32.1, you saw the <TITLE> tag used:


<TITLE>Hello Web!</TITLE>

This line tells your browser to format the text string Hello Web! as a <TITLE>. See the starting (<TITLE>) and ending (</TITLE>) tags? All of the elements within these tags—text, in this case—are displayed in the title bar of your Web browser window. Similarly, other tags only affect the elements they enclose.

Attributes

Sometimes, tags need to specify exact information, such as where a file is located. Attributes are used with tags to provide more detail about how the tag is to be implemented. For example, consider the following tag:


<IMG SRC=“example.gif”>

This tag is an <IMG> (image) tag that tells your Web browser to display a graphic image. But which image? That’s where the attribute comes in. In this example, the attribute field is SRC=“example.gif”, which gives detailed information about how the <IMG> tag is to be interpreted. In this case, the example.gif file is to be displayed as the image.


TIP:  Using the height and width attributes with the <IMG> tag helps your browser display the graphic more quickly. In Netscape, if the image is GIF or JPG format, you can open the image by itself. Then, from the View menu, choose View Document Info to see the size of the image.

URLs

Web resources are accessed by descriptive addresses known as uniform resource locators (URLs). Everything that you access on the Web has an URL. HTML uses URLs to specify the location of needed files or of other Web pages that are connected by hypertext links.

Understanding HTML Syntax

As you’ve seen, HTML breaks down into three basic components: tags, attributes, and URLs. Of these, the basic building block is the tag. Tags are used to give commands to a Web browser, whereas attributes and URLs are used to provide details about the commands.

Tags can be grouped into several categories, depending on their function. Some tags give information about the document as a whole, some are used for formatting text, and some are used for graphics and hypertext links to other documents.


ON THE WEB:  
For a listing of HTML tags and their attributes, look at the online version of Que’s HTML Quick Reference and Que’s Special Edition Using HTML at the following addresses (respectively):
http://www.mcp.com/que/developer_expert/htmlqr/toc.htm
http://www.mcp.com/que/et/se_html2/toc.htm


Previous Table of Contents Next