2.3: Document Structure Tags and A Simple Web Page
- Page ID
An HTML document is divided into two main sections, the head and the body. The reason for this division is that the head is to contain metadata, and the body is to contain the information to be displayed on the web page.
To understand this difference, it is important to understand the meaning of the term metadata. According to Dictionary.com, the meta prefix means: “a prefix added to the name of something that consciously references or comments upon its own subject of features” 6. Hence metaphysics is a physics about physics, a meta-analysis is a study of studies, etc.
Metadata is what its name implies, data about the data on a web page. It defines how the page is to interpret the data which it will process. For example, functions that are used in a web page are defined in the head. How to handle events and interpret the CSS tags are also defined in the head. Anything that is used to define the behavior of the page is in the head of the document.
As important as what is in the head is what is not in the head of the HTML document. The head should not output any information (or data) to be placed on the web page. Functions and other structures defined in the head should return strings to be printed in the body, and not printed to the page in the head. If the statement is defining something to be rendered on the page itself, it does not belong in the head.
This implies (correctly) that the body of an HTML document should contain anything that is rendered and placed on the web page. Any text to be displayed, images to be rendered, or forms to be processed belong in the body of the document. And again, the body should not contain any metadata such as functions, CSS, or code to handle events.
Nothing in HTML enforces this policy, but there are few good reasons to violate it. And when the data in the head and body are mixed, it generally shows that the programmer did not have a clear concept of what the page is to do.
In the Document Structure, the
<title> tag is shown as metadata. This is because the title is what appears on the tab in the browser, and not rendered on the page.
Program 3 is a simple HTML web page to illustrate the concepts covered so far. Note that the program uses the large heading (
<h1>), and paragraph (
Enter Program 3 is entered into a file with a “.html” extension. Note that the file must have some form of a .html (e.g. .htm, etc.) extension for the browser to recognize it as an html file. Place a jpeg picture (any picture) into a file named
dog.jpg, and open the file in a browser such as Chrome, Firefox, Safari, IE, or MS Edge 8. You should get a page similar to Figure 2-2.
Program 3 – First HTML Web Page <html> <!-- Author: Charles Kann Date: 5/17/2017 Purpose: A first example of an HTML program --> <head> <title>First HTML Web Page </title> </head> <body> <h1>First page</h1>
This is a first page of text, and shows how to insert a picture of a dog into a page. </p> </body> </html>
In this program, comments in html begin with a (<!--) tag and continue until a (-->) tag. There is a comment at the start of this document to provide a preamble comment for the file. The need for file preamble comments, and commenting code correctly, is stressed in every introductory programming course I have ever encountered. However, it seems as though students believe such commenting is not useful, only applies to introductory classes and/or the first language they learned. They throw out these lessons as soon as they think they can safely get away with it. That is why at every level student programs need to be graded on commenting, and a poorly commented program by a senior should be given an F, even if it works. Commenting is not something to be avoided. It is always good practice, and it will be good practice in web development also.
2.3.1 Quick Check
- What symbol is used to start an HTML tag. What symbol is used to end an HTML tag.
- What 4 tags should you use in all HTML documents?
- How do you close an HTML block tag? How do you close an empty tag?
- What is a tag? What is an attribute?
- What tags in the web page?
- What are document structure tags?
- What tags should be present in all web pages? What are they used for?
- Give some examples of tags that have attributes. What are the attributes?
- What happens to text that spans across multiple lines in the HTML source file?
- What do you think the < and > symbols do? What other symbols do you think are often specified this way in HTML.
7 In my experience, the best search engine by far for looking up information when programming is Google. Other search engines tend to assume a context for the terms and bring up a lot of noise pages not related to programming.