Chapter 2. Creating Your First HTML Page

Are you ready to begin creating a Web page? This chapter shows you how to get started with a basic HTML document.

Creating Your First HTML Page

Understanding HTML Document Structure 18

Start an HTML Document 20

Save an HTML Document 24

View an HTML Page 26

Add a Document Declaration 28

Add Metadata 30

Understanding HTML Document Structure

Although Web pages can differ widely in terms of content and layout, all pages have certain HTML tags that give them the same basic structure. Understanding this structure helps you begin to build your own HTML pages.

Understanding HTML Document Structure

HTML Tags

Document Type Declaration

The <HTML> and </HTML> tags at the beginning and end of a text document identify it as HTML code. When a browser encounters these tags, it knows that anything within the two tags defines a Web page. Older Web browsers expect to see the HTML tags; with the latest version of HTML and newer versions of browsers, the tags are not always necessary, but adding them is good form.

Understanding HTML Document Structure

You can add a DOCTYPE declaration to specify which tags a browser can expect to see in your HTML document. In HTML 4.01, there are three document types: HTML 4.01 Transitional, HTML 4.01 Strict, and HTML 4.01 Frameset. The transitional type is the most inclusive, incorporating both current tags and older tags that have been phased out, or deprecated. The strict type is more pared down and excludes deprecated tags. The frameset type is the same as the transitional type but includes all the tags necessary to make frames on a page. For more about frames, see Chapter 8.

Understanding HTML Document Structure

Document Header

You use the header of an HTML document to add descriptive and accessory information to your Web page. The document header tags, <HEAD> and </HEAD>, immediately follow the opening <HTML> tag. The document header contains information that does not appear in the browser window, including title information, metadata, scripts, and style sheets. For more about scripts, see Chapter 13. For more about style sheets, see Chapter 10.

Understanding HTML Document Structure

Document Title

You can add a title to your HTML document to help people and search engines identify your Web page. For example, if you are building a Web page for a business, you might want to include the company's name and specialization in the title. Most Web browsers display the title in the browser window's title bar. The <TITLE> and </TITLE> tags define a page title and appear inside the document header. It is good form to keep the title to fewer than 64 characters in length.

Understanding HTML Document Structure

Metadata

Metadata means "data about data." On a Web page, metadata can include author information, the type of editor used to create the page, a description of the content, relevant keywords, and copyright information. Search engines often use metadata when trying to categorize a page. You place metadata inside the document header.

Understanding HTML Document Structure

Body

The visible content that makes up your Web page, including paragraphs, lists, tables, and images, lives in the body of your HTML document. The body of the document is identified by the <BODY> and </BODY> tags. The body of a document comes after the header of a document. Most of the HTML tags covered in this book belong inside the body of the document and determine how its content is formatted. To learn how to begin formatting body text, see Chapter 3.

Understanding HTML Document Structure

Start an HTML Document

You can start an HTML document using a text editor, HTML editor, or word processing program. You use sets of HTML tags to define the basic structure of your page.

The <HTML>, <HEAD>, and <TITLE> tags are basic elements that appear at the beginning of all HTML documents.

Start an HTML Document

Start an HTML Document

1 Open an editor or word processing program.

Note

The examples in this book use both Windows Notepad and WordPad. See Chapter 1 to learn more about editors.

2 Type <HTML>.

This tag declares the document as HTML.

3 Press

Start an HTML Document

4 Type <HEAD>.

This tag defines where the title, metadata, and other descriptive information appear.

Note

For more about adding metadata to a Web page, see the section "Add Metadata."

5 Press

Start an HTML Document
Start an HTML Document

6 Type <TITLE>.

7 Type title text for your page.

Title text describes the contents of the page and appears in the title bar of the Web browser.

8 Type </TITLE>.

9 Press

Start an HTML Document

10 Type </HEAD>.

This tag completes the document header information for the page.

11 Press

Start an HTML Document

Note

You do not need to press

Start an HTML Document

Note

Browsers ignore extra white space in the code when rendering Web pages.

Start an HTML Document

Tip

Which should I add first to my HTML document, the HTML tags or the page content?

It is usually easier to start your HTML document by typing the basic structural tags, which include the <HTML>, <HEAD>, and <BODY> tags. These tags appear in all HTML documents, and typing them first helps ensure they have valid syntax and are in the correct order. After you add the basic structural tags, you can add the body content and additional HTML tags to format that content.

Start an HTML Document

Does it matter if I type my tags in uppercase, lowercase, or mixed case?

No. The current HTML standard allows for different cases in your HTML text. However, it is good form to format your HTML tags consistently. Also, typing tags in all uppercase letters can make it easier to distinguish HTML code from the page content and to identify errors in your code.

Start an HTML Document

You can use the body tags, <BODY> and </BODY>, to define the content in your Web page. Page content can include lines of text, bulleted and numbered lists, tables, forms, and more.

Start an HTML Document

12 Type <BODY>.

This tag marks the beginning of the actual content of your Web page.

13 Press

Start an HTML Document

14 Type the body text you want to appear on the page.

Body text is the content that appears in the browser window. For practice, you can type a simple paragraph for the body text.

15 Press

Start an HTML Document
Start an HTML Document

16 Type </BODY>.

This tag closes the body portion of the page.

17 Press

Start an HTML Document

18 Type </HTML>.

This tag ends the HTML code of your document.

You can save your document and view the page in a Web browser.

Note

To learn how to save a file, see the section "Save an HTML Document." To learn how to view the results of your HTML coding, see the section "View an HTML Page."

Start an HTML Document

Tip

How do I turn on WordPad's text wrapping?

It can be annoying when the HTML code in WordPad scrolls off the right side of the screen. You can turn on the text-wrapping feature to keep your code in view at all times.

1 In WordPad, click View.

2 Click Options.

The Options dialog box appears.

3 Click the Text tab.

4 Select the Wrap to window option (

Start an HTML Document

5 Click OK.

WordPad activates text wrapping.

Start an HTML Document

Save an HTML Document

You can save your Web page as an HTML file so that users can view it in a Web browser. When saving a Web page, you can use either the .html or .htm file extension.

When naming a Web page, it is best not to use spaces and to keep the characters limited to letters, numbers, hyphens (-), and underscores (_). If you are creating a home page for a Web site, it is common to name the page index.html or default.htm.

Save an HTML Document

Save an HTML Document

1 Click File.

Note

Your text editor may have a different command name for saving files. See your program's documentation for more information.

2 Click Save.

The Save As dialog box appears.

3 Click here to navigate to the folder or drive where you want to store the file.

4 Click here and select Text Document.

Save an HTML Document

5 Type a name for the file, followed by .html or .htm.

6 Click Save.

A dialog box may appear alerting you that all the formatting will be removed.

7 Click Yes.

The editor saves the file.

Save an HTML Document

Tip

What is the difference between the .html and .htm extensions?

The shorter .htm extension is left over from the early, pre-Windows days, when file names could have only three-character file extensions. Some Windows-based programs still default to the .htm extension. Today's computers can handle longer file names and extensions, so the three-character limit is no longer an issue. While Web browsers and servers can read either extension, you probably want to opt for .html because it is more universally used.

Save an HTML Document

What makes a good file name for a Web page?

When naming a file, it is a good idea to keep the name simple so that you can easily remember it and locate it again later. In addition, because you need to type file names when creating hyperlinks, it is best to use a name that relates to the pages you are designing. For example, if you are creating a page that lists contact information for your company, the file name for that page might be contact.html. It is also a good idea to keep your Web page files in one folder and give the folder a name that clearly identifies the content, such as My Web Pages.

Save an HTML Document

View an HTML Page

After you create and save an HTML document, you can view it in your Web browser. Your Web browser can view HTML pages that you have saved on your computer as well as pages on the Internet.

View an HTML Page

View an HTML Page

1 Open your Web browser.

This example uses the Internet Explorer browser.

2 Click File.

3 Click Open.

The Open dialog box appears.

4 Click Browse.

View an HTML Page

5 Click here to navigate to the folder or drive in which your HTML document is stored.

6 Click the file name.

7 Click Open.

• The Open dialog box displays the path and name of the file.

8 In the Open dialog box, click OK.

The Web browser displays the page.

• The title information appears here.

• The body information appears here.

• The location of the HTML file appears here.

If you make changes to the HTML of the page that is displayed in the browser, you can click

View an HTML Page
View an HTML Page

Tip

Does it matter what browser I use to view the pages I'm building?

No. All popular Web browsers are set up to view HTML pages that you have saved on your computer, also known as offline pages. You may need to follow a slightly different set of steps to open an offline HTML document in a browser other than Internet Explorer, such as Mozilla Firefox. Be sure to consult your browser's documentation for more information.

View an HTML Page

What happens if I cannot view my page?

If you do not see any content for your page, you need to double-check your HTML code for errors. Make sure your document uses correctly paired start and end tags, and proofread your HTML code to make sure everything is correct. Also make sure you named your page with an .html or .htm extension.

View an HTML Page

Add a Document Declaration

You can use a document declaration at the top of your Web page to declare which type of HTML tags the browser can expect to see. You can use one of three types: HTML 4.01 Transitional, HTML 4.01 Strict, or HTML 4.01 Frameset.

The transitional version of HTML is the most inclusive. It has all the standard structural elements as well as older tags that have been phased out of the current standard. The strict type includes only currently sanctioned tags. The frameset type is the same as the transitional type but includes additional tags for creating frames.

Add a Document Declaration

Add a Document Declaration

1 Open the HTML document you want to edit.

2 Position your cursor before the <HTML> tag and press

Add a Document Declaration

3 Type the DOCTYPE declaration.

• To specify HTML 4.01 Transitional, type:

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

You may need to press

Add a Document Declaration
Add a Document Declaration

• To specify HTML 4.01 Strict, type:

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

• To specify HTML 4.01 Frameset, type:

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

The declaration statement is complete.

Add a Document Declaration

Tip

Do I have to include a document declaration?

Most popular browsers can display your page without a DOCTYPE declaration. However, if you are using a validation tool to check your page for proper form, the tool may require that you include a declaration so that it knows what type of HTML it should validate your page against. Including a document declaration is also considered good form.

Add a Document Declaration

Which version of HTML should I use?

All Web browsers support HTML Transitional. However, professional developers are moving toward HTML Strict and using it with Cascading Style Sheets (CSS) to control page formatting. Many of the deprecated tags in HTML have been replaced by formatting rules that you apply with CSS. If your page uses frames, then you need to use HTML Frameset because it allows you to add frames to a page. Deciding which version to use really depends on what Web page elements you plan to use and what type of coding you are familiar with.

Add a Document Declaration

Add Metadata

You can add metadata to your page to include extra descriptive information that does not appear in the browser window. Metadata can include a page description, author and copyright information, keywords, and more. What you insert in metadata tags can help search engines categorize your page.

You define metadata in the document header using the <META> tag.

Add Metadata

Add Metadata

Add an Author Name

1 Click between the <HEAD> and </HEAD> tags and press

Add Metadata

In this example, the metadata appears below the <TITLE> tags.

2 Type <META NAME= "author" followed by a space.

3 Type CONTENT=" My Name ">, replacing My Name with your name.

4 Press

Add Metadata

Add a Page Description

5 Type <META NAME= "description" and a blank space.

6 Type CONTENT=" Page Description ">, replacing Page Description with your own page description.

7 Press

Add Metadata
Add Metadata

SPECIFY KEYWORDS

8 Type <META NAME= "keywords" and a space.

9 Type CONTENT="My Keywords">, replacing My Keywords with a keyword.

For multiple keywords, use a comma followed by a space to separate the keywords.

10 Press

Add Metadata

Add a Copyright

11 Type <META NAME= "copyright" and a space.

12 Type CONTENT=" 2008">, replacing 2008 with your own numbers or copyright information.

13 Press

Add Metadata

The metadata is now a part of the HTML document.

Add Metadata

Tip

How do I add the name of the program I used to design my page to the metadata information?

To specify an authoring program, type <META NAME="generator" CONTENT="Program Name">. Substitute the name of your program for the text Program Name.

Add Metadata

Who can view my metadata?

The only way users can see your metadata information is if they view the HTML code for the page. To view the HTML code of any page in your browser window, click View and then Source. This opens a text-editor window displaying the HTML used to create the page. Any metadata assigned to the document appears at the top inside the <HEAD> and </HEAD> tags.

Add Metadata
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.231.128