An HTML document consists of nested “tags”, each tag representing a certain “structure” for its contents.
For instance we will see tags for lists, tables, headings and so on.
This is important:
HTML dictates the structure of the page’s content. It describes structure, semantics, not appearance. It is used to describe “what something is”, not “how it should look”. CSS is responsible for appearance.
This semantic information is important, as it is all that visually impaired users or tools like search engines will see.
There is entirely too much legacy information on HTML and various standards. We will be focusing on the current standard, usually termed HTML5. A number of old tags have been deprecated.
HTML5 is actually a collection of standards, some with very varying levels of adoption. The can-i-use site can tell you more information about the state of adoption of the particular technology you want to use.
What we will cover in this class is standard and widely adopted. We start with an overview of some key features:
- An HTML document is a tree structure consisting of nodes. Each node is either an element node or a text node. Element nodes are identified by pairs of tags, an open tag like
<html ...>
and a corresponding close tag</html>
. The content of the node is all the children elements that are found between the open and close tags.- The opening tag may also contain a number of attributes. These are key-value pairs where the value is always a string. Example:
<div id="myDiv" class="bold item">
.- There are a few elements that are self-closing:
<hr />
. These are roughly equivalent to open-close tags back-to-back.- Tags must be well-nested, namely this is not allowed:
<tag1><tag2></tag1></tag2>
. In other words, if an open tag is contained in a node, the corresponding close tag must also be contained in that node.
Let us define some key terms:
<!DOCTYPE html>
.
<html>
tag. Everything else will be nested inside this tag.
head
tag is the first thing inside the HTML document. It contains metadata information about the document (keywords, author, description, title etc), as well as links to CSS spreadsheets and fonts.
body
tag follows the head tag, and contains all the actual elements in the page.
<tag attr1="..." attr2="...">
. We will see examples later.
div
, section
, nav
, table
.
em
tag is used to indicate its content should be “emphasized”.
We will now describe in some detail some attributes and elements. We start with attributes:
class="hidden cartItem"
identifies this element as being a “cartItem” and also being “hidden”. (This does not actually mean it is hidden, it means that it appears however CSS has specified “hidden” elements should appear). We might have some Javascript code that does something to all elements with a class “cartItem”, or we might have some CSS instructions that say how all elements of class “hidden” should appear.
There are many more attributes, most more specialized to certain elements. You will encounter them as you find them.
Here are some of the most important tags/elements from standard HTML:
Here are some elements added in HTML5:
option
tags to form list of options for other input elements.
figcaption
. Its position is meant to not be part of the normal flow.
An example of an HTML document can be seen in the WebAppsTODO application page.
In-class activity. Think of the elements that this page contains.