Building our First HTML Page
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”. 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 (
<p>) block tags, and the
<img> tag, which have not been covered. As has
been stated before, this text is not to be a text on learning HTML, CSS,
enough detail to allow a motivated intermediate programmer enough background to start that
research. A complete list of HTML tags can be found
at MDN Web Docs,
and many tutorials exist on how to use them in web pages. Readers
interested in more functionality of the tags can easily look them up on
Google. But it is expected that the readers of this text
are sufficiently advanced that they can research and learn the
implementation details of this type of material.
Enter Program 3 is entered into a file with a “
.html” extension. Note
that the file must have some form of a
.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 Microsoft Edge. You should get a page similar to figure shown below.
<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>
Program 3 – First HTML Web Page
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.
Quick Check - Test your Knowledge
- 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.