Chapter 2 HTML
Chapter 2 HTML
Chapter 2 HTML
Chapter 2
HTML : Overview
Web Programming
Objectives
Web Programming 1
HTML Syntax
HTML is defined as a markup language.
The term comes from the days of print, when editors would write
instructions on manuscript pages that might be revision instructions
to the author or copy editor.
Web Programming 1
Markup
At its simplest, markup is a way to indicate information about the content
The markup in the previous slide consists of the red text and the various
circles and arrows on the one page, and the little yellow sticky notes on the
other.
The W3C is the main standards organization for the World Wide Web.
In 1998, the W3C turned its attention to a new specification called XHTML
1.0, which was a version of HTML.
Web Programming 1
XHTML
The goal of XHTML with its strict rules was to make page rendering more
predictable by forcing web authors to create web pages without syntax errors.
The XML-based syntax rules for XHTML are pretty easy to follow.
The main rules are:
HTML5
By 2009, the W3C stopped work on XHTML 2.0 and instead adopted the work
done by WHATWG and named it HTML5.
HTML Syntax
Web Programming 2
Any elements contained within the child are said to be descendants of the
parent element; likewise, any given child element, may have a variety of
ancestors.
Web Programming 2
Hierarchy of elements
Web Programming 2
That is, a child’s ending tag must occur before its parent’s ending tag.
Web Programming 3
SEMANTIC MARKUP
Web Programming 3
SEMANTIC MARKUP
Over the past decade, a strong and broad consensus has grown around the
belief that HTML documents should only focus on the structure of the
document.
Information about how the content should look when it is displayed in the
browser is best left to CSS (Cascading Style Sheets).
That is, an HTML document should not describe how to visually present
content (semantic HTML), but only describe its content’s structural
semantics or meaning.
Web Programming 3
Structure
Structure is a vital way of communicating information in paper and
electronic documents.
All of the tags that we will examine in this presentation are used to
describe the basic structural information in a document, such as articles,
headings, lists, paragraphs, links, images, navigation, footers, and so on.
Web Programming 4
STRUCTURE OF HTML
Web Programming 4
The <title> element is used to provide a broad description of the content. The
title is not displayed within the browser window. Instead, the title is typically
displayed by the browser in its window and/or tab.
Web Programming 4
1.DOCTYPE
Tells the browser (or any other client software that is reading this HTML
document) what type of document it is about to process.
Notice that it does not indicate what version of HTML is contained within the
document: it only specifies that it contains HTML.
Web Programming 4
2. The <html> element is sometimes called the root element as it contains all
the other HTML elements in the document.
HTML pages are divided into two sections: the head and the body, which
correspond to the <head> and <body> elements.
5. The first of these is the <meta> element. Our example declares that the
character encoding for the document is UTF-8.
6. Our example specifies an external CSS style sheet file that is used with this
document.
Sample Document
Web Programming 5
1. Headings
HTML provides six levels of heading (h1, h2, h3,
…), with the higher heading number indicating a
heading of less importance.
1. Headings
1. Headings
In practice, specify a heading level that is semantically accurate.
•e.g., choosing <h3> because you want your text to be bold and 16pt
•e.g., choosing <h3> because it is a third level heading and not a primary
or secondary heading
Web Programming 5
2. Paragraphs <p>
Paragraphs are the most basic unit of text in an HTML document.
Notice that the <p> tag is a container and can contain HTML and other inline
HTML elements
6. Divisions <div>
This <div> tag is also a container element and is used to create a logical
grouping of content
If the URL does not include the “http://” then the browser will request the
current server for the file.
Web Programming 5
However, most real-world sites contain too many files to put them all within a
single directory.
For these situations, a relative pathname is required along with the filename.
The pathname tells the browser where to locate the file on the server.
Web Programming 5
Pathnames
Pathnames on the web follow Unix conventions.
Forward slashes (“/”) are used to separate directory names from each other
and from file names.
Images
While the <img> tag is the oldest method for displaying an image, it is not the
only way.
But when the images are content, such as in the images in a gallery or the
image of a product in a product details page, then the <img> tag is the
semantically appropriate approach.
Web Programming 5
Images
Web Programming 5
Lists
Unordered lists. Collections of items in no particular order; these are by
default rendered by the browser as a bulleted list.
Ordered lists. Collections of items that have a set order; these are by
default rendered by the browser as a numbered list.
Lists
Web Programming 5
Character Entities
These are special characters for symbols for which there is either no easy
way to type in via a keyboard (such as the copyright symbol or accented
characters) or which have a reserved meaning in HTML
(for instance, the “<” or “>” symbols).
They can be used in an HTML document by using the entity name or the
entity number.
most complex web sites are absolutely packed solid with <div> elements.
Unfortunately, all these <div> elements can make the resulting markup
confusing and hard to modify.
Developers typically try to bring some sense and order to the <div> chaos by
using id or class names that provide some clue as to their meaning.
Web Programming 6
Web Programming 6
Another way to help you decide whether or not to use the <section>
element is to ask yourself if it is appropriate for the element's contents to
be listed explicitly in the document's outline.
9. Aside <aside>
The <aside> element is similar to the <figure> element in that it is used for
marking up content that is separate from the main content on the page.
But while the <figure> element was used to indicate important information
whose location on the page is somewhat unimportant, the <aside> element
“represents a section of a page that consists of content that is tangentially
related to the content around the aside element.”
The <aside> element could thus be used for sidebars, pull quotes, groups of
advertising images, or any other grouping of non-essential elements.
Web Programming