The HTML code, called the source code, that creates a web page is a way to mark up a document by labeling its logical parts. But, HTML (HyperText Markup Language) is not anywhere near to being a programming language!
You use tags to label the headings, normal paragraphs, lists, and special sections, like quotes, addresses, tables, hyperlinks, and forms.
A tag is made by writing the name of the tag between the angled brackets < and >, like <html> and <p>. Most tags come in pairs, an opening tag and a closing tag. The closing tag has a forward slash, like </html> and </p>. Some tags stand alone, like <br> for a line break and <hr> for a horizontal rule (a line across the page).
An element is the opening tag with its closing tag and everything in between them.
Example: <h2>This is a subtitle</h2> is an H2 element.
There are several standards (rules) for writing HTML. In these lessons, we will try to stick to the basics of the basics for HTML5.
HTML 4.01 was finished in 1999. It comes in three flavors - Strict, Transitional, and Frameset.
XHTML is a combination of HTML and XML. It stands along side HTML 4.01 and HTML 5, not in between them.
XML is a markup language similar to HTML but you define your own tags in XML. XML was designed to store and transport data. HTML was designed to display data. XML is used widely to transport data between different programs.
XHTML is very strict about its rules. Incorrect code will not be rendered at all. Everything is case-sensitive. All tags must be closed. XHTML keeps the white space instead of squishing it all together like HTML does.
There are advantages to having strict rules, but many web authors prefer to use HTML so that browsers can 'fix' their code mistakes and show something, even if it is not quite what they meant. Some companies and government agencies require that their own publications meet the XHTML standard.
HTML5 was finalized in late 2014. All major browsers support most of HTML5 but none fully support all of the new tags yet.
Let's look at the basic tags now. In the next lesson you will see what it looks like when the tags are put together with text to make a web page.
Use
lower case: Tags can be written in HTML with upper case, lower case, or even mixed
case but lower case is preferred. XHTML requires that all tags be
in lower case. In these lessons, examples of HTML code will use lower case,
like <body>. In a sentence about HTML, however,
tags will be referred to with uppercase. This makes it easier to tell that
the word is a tag. Compare: "The body tag is required." to "The BODY
tag is required."
It is smarter to stick to lower case when writing HTML code for three reasons.
When discussing a paired tag, it is usual to just use the opening tag in the
sentence and to drop the < and > symbols, like "The P tag is used for text
that is a paragraph."
Most HTML tags come in pairs, an opening tag and a closing tag. They surround and contain the part that they are labeling, like the following element:
<p>Here is a paragraph.</p>
The purpose is to tell what the logical function of that part is. A block element normally displays in the browser with a line break after the closing tag. An inline element does not.
Document structure tags:
There are many other structural parts, like numbered lists, bulleted lists, addresses, quoted material, tables, etc. Some of these will be discussed later.
Logical formatting
<em> </em> |
Emphasis: Most browsers show EM text as italic. |
<strong> </strong> |
Stronger emphasis than EM. Most browsers show STRONG text as bold. |
The tags <em>
and <strong>
are used to mark
words or phrases that should look different from regular text for a logical reason. For example, a new term might be marked this way. The browser will control exactly how these tags change the look of the text. Software
that reads text aloud knows to give vocal emphasis to words with these tags.
Character formatting - OBSOLETE
These tags let you change the look of your text. They have been replaced with Cascading Style Sheets (CSS). CSS used to be consider an advanced topic but nowadays web authors must learn to use it from the beginning!
A few tags do not have a closing tag in HTML. They stand alone.
A final forward slash / is required by XHTML, like <br /> but this is not required by HTML 4.01 or HTML5.
Some tags do not label parts of the document itself. They give important information to the browser. They do not do anything directly to the page that you see in your browser.
When a tag contains other tags, we say that the tags are nested.
First some definitions:
Block elements: Elements
that define sections of the document.
These generally start a new line.
This includes all the headings, the paragraph element, division element,
lists and list items, and tables.
Inline elements: Elements
that are not block elements.
These include the logical formatting and character
formatting tags and images.
Rules on Containment:
Block-level elements may contain both other block elements and also inline elements.
Inline elements can only contain data and other inline elements.
Most browsers try to guess what bad code should have been when there are containment errors. But, sometimes breaking the rules for nesting makes parts vanish from your page!
Example: To display the sentence - This is hard!
Correct: <p><b><i>This is hard!</i></b></p>
Block element P contains the inline elements B and I. Inline element B
contains inline element I. Since the opening order was P and then B and
then I, the closing order is the reverse, I and then B and then P.
Wrong: <b><i><p>This is hard!</p></i></b>
Containment error: Inline elements B and I contain block element
P.
Wrong: <p><b><i>This is hard!</b></i></p>
Nesting order error: The opening tag
for element B comes before the opening tag for element I. The closing
tag for I should come before the closing tag for B.