Chapter 2 HTML Ibit Ip
Chapter 2 HTML Ibit Ip
Chapter 2
3 Semantic Markup
4 Structure of HTML
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:
• lowercase tag names,
• attributes always within quotes,
• and all elements must have a closing element (or be self-
closing).
HTML5
Three main aims
HTML SYNTAX
HTML Elements
• HTML documents are text files made up of HTML
elements. they are defined using HTML tags.
• HTML tags are used to mark-up HTML elements
• HTML tags are surrounded by the two characters
< and >
• The surrounding characters are called angle
brackets
HTML Tags:
▪ HTML tags normally come in pairs like <b> and
</b>
▪ The first tag is the start tag, <b>
<ol>Content Here</ol>
Displays an ordered list
Uses numbers for list items
<ul>Content Here</ul>
<li>Content Here</li>
Used in an unordered or ordered list to separate the items in
a list
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
<center>Content Here</center>
Centers content on a page
Tag Attributes
▪ Attributes can provide additional information about the
HTML elements on your page.
<head>
<meta name=“keywords” content=“lecture notes, html,
form, feedback”>
<meta name=“description” content = “this web site
describes …”>
</head>
Description of a page seen on searching
Section 4 of 6
STRUCTURE OF HTML
HTML Page Structure
doctype
html
head
body
HTML Page Structure
<!DOCTYPE...> This tag defines the document type and HTML
version.
The first tag in an HTML document , This tells the browser reading
<HTML> the page that the text that follows should be read as HTML
The head contains descriptive elements about the document
<BODY>
This is where you would include the text and
images on your Web page.
</BODY>
</HTML>
Here is how basic HTML code is structured …
A more complete document
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
1 DOCTYPE
(short for Document Type Definition)
Tells the browser (or any other client software that is reading this
HTML document) what type of document it is about to process.
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
HTML, Head, and Body
2 The <html> element is sometimes called the root element as it
contains all the other HTML elements in the document.
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
Head and Body
HTML pages are divided into two sections: the head and the body,
which correspond to the <head> and <body> elements.
3 The head contains descriptive elements about the document
4 The body contains content that will be displayed by the browser.
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
Inside the head
You will notice that the <head> element contains a variety of
additional elements.
5 The first of these is the <meta> element. Our example declares that
the character encoding for the document is UTF-8.
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
Inside the head
6 Our example specifies an external CSS style sheet file
that is used with this document.
7 It also references an external Javascript file.
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
Head Tags
Tag Description
<head> Defines information about the document
<title> Defines the document title
<base> Defines a base URL for all the links on a page
<link> Defines a resource reference
<meta> Defines meta information
<style> Defines a style in a document
<script> Defines a script, such as a JavaScript
Section 5 of 6
<h3>Reviews</h3>
6 <div> 7
<p>By Ricardo on <time>September 15, 2012</time></p>
<p>Easy on the HDR buddy.</p>
</div>
<div>
<p>By Susan on <time>October 1, 2012</time></p>
<p>I love Central Park.</p>
</div>
8
<body>
<h1>Level 1 Header</h1>
<h2>Level 2 header</h2>
<h3>Level 3 header</h3>
<h4>Level 4 header</h4>
<h5>Level 5 header</h5>
<h6>Level 6 header</h6>
</body>
</html>
Paragraphs <p></p>
Paragraphs are the most basic unit of text in an HTML document.
<html>
<body>
Paragraphs, <P> </P>
<HTML><HEAD>
<TITLE> Example Page</TITLE>
Heading 1
</HEAD> Paragraph 1,….
<BODY></H1> Heading 1 </H1>
<P> Paragraph 1, ….</P> Heading 2
<H2> Heading 2 </H2> Paragraph 2,….
<P> Paragraph 2, ….</P>
<H3> Heading 3 </H3> Heading 3
<P> Paragraph 3, ….</P> Paragraph 3,….
<H4> Heading 4 </H4>
<P> Paragraph 4, ….</P> Heading 4
<H5> Heading 5 </H5> Paragraph 4,….
<P> Paragraph 5, ….</P> Heading 5
<H6> Heading 6</H6>
Paragraph 5,….
<P> Paragraph 6, ….</P>
</BODY></HTML> Heading 6
Paragraph 6,….
Break, <BR>
▪ Line breaks allow you to decide where the
text will break on a line or continue to the
end of the window.
▪ A <BR> is an empty Element, meaning that it
may contain attributes but it does not contain
content.
▪ The <BR> element does not have a closing
tag.
38
Break, <BR>
<HTML>
<HEAD>
<TITLE> Example Page</TITLE>
</HEAD> Heading 1
<BODY>
Paragraph 1,….
<H1> Heading 1 </H1>
<P>Paragraph 1, <BR>
Line 2
Line 2 <BR> Line 3 <BR>…. Line 3
</P> ….
</BODY>
</HTML>
39
Horizontal Rule, <HR>
40
Horizontal Rule, <HR>
Attribute Description Default Value
Height of the rule in
SIZE 2 pixels
pixels
Width of the rule in
WIDTH pixels or percentage 100%
of screen width
Draw the rule with a Not set
NOSHADE flat look instead of a
3D look (3D look)
41
Horizontal Rule, <HR>
<HTML>
<HEAD>
<TITLE> Example Page</TITLE>
</HEAD>
<BODY> Heading 1
<H1> Heading 1 </H1> Paragraph 1,….
<P>Paragraph 1, <BR>
Line 2 <BR> Line 2
<HR>Line 3 <BR> _________________________
</P> __
</BODY>
Line 3
</HTML>
42
Divisions <div>
This <div> tag is also a container element and is used to
create a logical grouping of content
• div element
Generic container for any block-level content
Syntax: <div>
content
</div>
Links <a>
• Links are created using the <a> element (the “a” stands for
anchor).
• To create a link to another document by using the href
attribute
• A link has two main parts: the destination and the label.
<a href="http://www.centralpark.com">Central Park</a>
Label (image)
Links
Source
<p>Linking to Google:
<a href="http://www.google.com">
Google
</a>
</p>
Output
Linking to Google: Google
Linking Webpage
▪ One of the most important XHTML features
is the hyperlink
– Link to another resources, such as web page,
image, etc.
<body background=“image.gif”>
▪ To show an Image inside a page:
<img src=“image.gif” border=“0” height=“256”
width=“256” alt=“text description of the
image”/>
▪ We can create an image hyperlink
<a href=“page1.html”>
<img src=“image.gif” …/>
</a>
Will scale to this size to display
<body>
60
Bold, Italic and other Character Formatting
Elements
▪ <FONT SIZE=“+2”> Two sizes bigger</FONT>
▪ The size attribute can be set as an absolute value from 1 to 7 or
as a relative value using the “+” or “-” sign. Normal text size is 3
(from -2 to +4).
▪ <B> Bold </B>
▪ <I> Italic </I>
▪ <U> Underline </U>
▪ Color = “#RRGGBB” The COLOR attribute of the FONT element.
E.g., <FONT COLOR=“#RRGGBB”>this text has color</FONT>
▪ <PRE> Preformatted </PRE> Text enclosed by PRE tags is
displayed in a mono-spaced font. Spaces and line breaks are
supported without additional elements or special characters.
61
Bold, Italic and other Character Formatting
Elements
▪ <EM> Emphasis </EM> Browsers usually display this
as italics.
▪ <STRONG> STRONG </STRONG> Browsers display
this as bold.
▪ <TT> TELETYPE </TT> Text is displayed in a mono-
spaced font. A typewriter text, e.g. fixed-width font.
▪ <CITE> Citation </CITE> represents a document
citation (italics). For titles of books, films, etc.
Typically displayed in italics. (A Beginner's Guide to
HTML)
62
Bold, Italic and other Character Formatting
Elements
<P> <FONT SIZE=“+1”> One Size One Size Larger - Normal – One Size
Larger </FONT> - Normal – Smaller
<FONT SIZE=“-1”> One Size Smaller Bold - italics - Underlined -
</FONT> <BR> Colored
<B> Bold</B> - <I> italics</I> - <U> Emphasized - Strong - Tele Type
Underlined </U> -
<FONT COLOR=“#FF0000”> Colored
</FONT> <BR>
<EM> Emphasized</EM> -
<STRONG> Strong </STRONG> -
<TT> Tele Type </TT> <BR>
63
Alignment
64
Alignment
▪ <DIV ALIGN=“value”></DIV> Represents a
division in the document and can contain
most other element type. The alignment
attribute of the DIV element is well supported.
▪ <TABLE></TABLE> Inside a TABLE, alignment
can be set for each individual cell.
65
Special Characters & Symbols
▪ These Characters are recognized in HTML as they
begin with an ampersand and end with with a semi-
colon e.g. &value; The value will either be an entity
name or a standard ASCII character number. They are
called escape sequences.
▪ The next table represents some of the more
commonly used special characters. For a
comprehensive listing, visit the W3C’s section on
special characters at:
http://www.w3.org/MarkUp/HTMLPlus/htmlplus_13.html
66
Special Characters & Symbols
Special Entity Special Entity
Character Name Character Name
Ampersand & & Greater-than > >
sign
Asterisk ∗ Less-than sign < <
∗∗
Cent sign ¢ ¢ Non-breaking
space
Copyright © © Quotation mark " "
Fraction one ¼ Registration ® ®
qtr ¼ mark
Fraction one ½ Trademark sign ™
half ½ ™ 67
Special Characters & Symbols
▪ Additional escape sequences support accented
characters, such as:
▪ ö
– a lowercase o with an umlaut: ö
▪ ñ
– a lowercase n with a tilde: ñ
▪ È
– an uppercase E with a grave accent: È
NOTE: Unlike the rest of HTML, the escape sequences
are case sensitive. You cannot, for instance, use <
instead of <.
68
Additional Character Formatting Elements
69
Example
<P><STRIKE> strike-through text </STRIKE></BR>
70
background color is yellow
<body bgcolor = “#ffff00”>
<p><font face="courier" color="green" size=“24”>
This is a test.</font> horizontal ruler
<hr />
<font face="times" color="red" >
This is a test.</font> the backslash is only to
</p> improve readability
<p>
<font face="arial" color="red" size=“+1”>
See the This is a test.</font>
difference
<br />
between <p>
and <br>
<font face="times" color="#ff00ff" size=“+2”>
This is a test.</font>
</p>
<p align = center><font face="courier" size=“+3”>
This is a test.</font>
</p> the text is placed at the center
</body>
size = 24
default size
73
List Elements
▪ HTML supplies several list elements. Most list elements are
composed of one or more <LI> (List Item) elements.
▪ UL : Unordered List. Items in this list start with a list mark such
as a bullet. Browsers will usually change the list mark in
nested lists.
<UL>
<LI> List item …</LI>
<LI> List item …</LI>
</UL>
▪ List item …
▪ List item …
74
List Elements
▪ You have the choice of three bullet types: disc(default), circle,
square.
▪ These are controlled in Netscape Navigator by the “TYPE”
attribute for the <UL> element.
<UL TYPE=“square”>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
</UL>
▪ List item …
▪ List item …
▪ List item …
75
List Elements
▪ OL: Ordered List. Items in this list are numbered
automatically by the browser.
<OL>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
</OL>
1. List item …
2. List item …
3. List item
▪ You have the choice of setting the TYPE Attribute to one of
five numbering styles.
76
List Elements
77
List Elements
78
List Elements
i. List item …
ii. List item …
Text ….
79
List Elements
▪ DL: Definition List. This kind of list is different from the
others. Each item in a DL consists of one or more Definition
Terms (DT elements), followed by one or more Definition
Description (DD elements).
<DL>
<DT> HTML </DT>
<DD> Hyper Text Markup Language </DD>
<DT> DOG </DT>
<DD> A human’s best friend!</DD>
</DL>
HTML
Hyper Text Markup Language
DOG
A human’s best friend!
80
Nesting Lists
▪ You can nest lists by inserting a UL, OL, etc., inside a list item (LI).
EXample
<UL TYPE = “square”>
<LI> List item …</LI>
<LI> List item …
<OL TYPE=“i” START=“3”>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
</OL>
</LI>
<LI> List item …</LI>
</UL>
81
What will be the output?
3 Semantic Markup
4 Structure of HTML