Professional Documents
Culture Documents
Chapter 1 HTML
Chapter 1 HTML
Introduction to HTML
Tim Berners-Lee , a British physicist
working at CERN labs in Switzerland
at the time (1989), is the inventor of
HTML, and is often also credited as
the inventor of www.
HTML is based on SGML (Standard
Generalized Markup Langauge),
which existed since 1940s, but
without the ability to link
Introduction to HTML
He suggested that you could actually
link the text in the files themselves,
through an agreed-upon mark-up
language
Markup languagesare designed
for the processing, definition and
presentation of text.
Introduction to HTML
Thelanguagespecifies code for
formatting, both the layout and style,
within a text file.
The code used to specify the formatting
are called tags.
HTML is a an example of a widely known
and usedmarkup language
What is HTML?
Hyper Text Markup Language
Hypertext refers to the way in
which Web pages (HTML documents)
are linked together. Thus, the link
available on a webpage is called
Hypertext.
What is HTML?
Hyper Text Markup Language
As its name suggests, HTML is a
Markup Language which means
you use HTML to simply "mark-up" a
text document with tags that tell a
Web browser how to structure it to
display
What is HTML?
HTML is a computer language that
is used to create documents on the
World Wide Web.
HTML is very simple, and logical. It
reads from left to right, top to bottom
and uses plain text
What is HTML?
HTML is NOT a programming
language, but a mark-up language
that uses <Tags> like this.
The websites you view on the
internet are actually text files that
consist of HTML Tags
Introduction to HTML
The only thing HTML does is it tells a
browser how to display the text
HTML is designed to work on a wide
variety of platforms
Graphical workstations
Network computers
TV sets etc
Advantages of HTML
It is simple
It is case insensitive
Flexible
Free of cost
Structural building up
Disadvantages
Dynamic web pages cannot be
created with HTML
HTML doesnt pass information to
pages
All the browsers may not support all
the tags of HTML
Output
Introduction to WWW
TheWorld Wide Web(WWW / W3) is
anopen sourceinformation
spacewhere documents and
otherweb resourcesare identified
byURLs, interlinked
byhypertextlinks, and can be
accessed via theInternet.
It has become known simply asthe
Web
Introduction to WWW
TheWWW includes few billions of
files i.e. text, images, audio, video,
animations or programs stored on
tens and thousands of computers
(Web servers) all over the world.
The web is the largest and most
diverse collection of information
grouped in one place
Introduction to W3C
W3C stands for the World Wide Web (W3)
Consortium.
W3C is working to make the web
accessible to all users
Today, the World Wide Web Consortium
(W3C) is an international consortium
(group) where member organizations, a
full-time staff, and the public work
together to develop Web standards.
Introduction to W3C
Tim Berners-Lee is the Director of the
W3C
Objective of W3C is To lead the
WWW to its full potential by
developing various protocols and
guidelines that may ensure long-term
growth of the web.
HTMLEditors
Write HTML Using Notepad or TextEdit
HTML can be edited by using
professional HTML editors like:
Microsoft WebMatrix
Sublime Text
HTML Documents
All HTML documents must start with
a type declaration:<!DOCTYPE
html>.
The HTML document itself begins
with<html>and ends
with</html>.
The visible part of the HTML
document is
Example
<!DOCTYPEhtml>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
HTML Tags
As told earlier, HTML is a markup
language and makes use of various
tags to format the content.
These tags are enclosed within angle
braces <Tag Name>.
Except few tags, most of the tags
have their corresponding closing tags.
For example, <html> has its closing
tag</html> and <body> tag has its
closing tag </body> tag etc.
HTML Tags
A completed tag is known as Element.
E.g. <Body> Hello All </Body>
Description
<!DOCTYPE...>
<html>
<head>
<title>
<body>
Tag
Description
<h1>
<p>
HTML Document
Structure
The <!DOCTYPE>
Declaration
The <!DOCTYPE> declaration tag is
used by the web browser to
understand the version of the HTML
used in the document.
Current version of HTML is 5 and it
makes use of the following
declaration:
<!DOCTYPE html>
HTML syntax
Tags
Instructions for the browser
<tag> Some text</tag>
Nesting
Close tags in the opposite order in which you
opened them.
<tag1> <tag2>Some text </tag2> </tag1>
Attributes
Specify attributes to use non-default behavior
<tag attribute=value>Text</tag>
The first part of the tag <tag name> turns the tag on
The ending part of the tag, </tag name>, contains the
"/" slash character.
This "/" slash tells a WWW browser to stop tagging
the text. Many HTML tags are paired this way.
If you forget the backslash, a WWW browser will
continue the tag for the rest of the text in your
document, producing undesirable results.
HTML Comments
Comments can be inserted in the
HTML code to make it more readable
and understandable.
Comments are ignored by the
browser and are not displayed.
An HTML comment begins with
"<!--",
And ends with "-->"
HTML Comments
Example
<!-- This is a comment -->
Multiline Comments:
Example:
<!-- This is a multiline comment
<br /> and can span through as
many as lines you like. -->
Heading Tags
Any document starts with a heading
You can use different sizes for your
headings
HTML also has six levels of
headings, which use the elements
<h1>, <h2>, <h3>, <h4>,
<h5>, and <h6>
Example : Output
HTML Paragraphs
HTML paragraphs are defined with
the <p> tag
Each paragraph of text should go in
between an opening <p> and
closing </p> tag
Example
<html>
<head>
<title> Paragraph</title>
</head>
<body>
<p>This is my first paragraph</p>
<p>Here is a second paragraph of
text.</p>
</body>
</html>
Line Breaks
Whenever you use the <br /> element,
anything following it starts on the next line.
This tag is an example of an empty
element, where you do not need opening
and closing tags, as there is nothing to go
in between them.
Note: The <br /> element has a space
between the characters br and the forward
slash
<center> Element
Centring Content - The <center>
Element:
You can use <center> tag to put any
content in the center of the page or
any table cell.
Example:
<p>This is not in the center.</p>
Preserve Formatting
<pre>
Sometimes, you want your text to
follow the exact format of how it is
written in the HTML document. In
these cases, you can use the
preformatted tag <pre>.
Any text between the opening
<pre> tag and the closing
</pre> tag will preserve the
formatting of the source
Preserve Formatting
<pre>
Preserve Formatting
Example
<!DOCTYPE html>
<html>
<head>
<title>Preserve Formatting Example</title>
</head>
<body>
<pre>
function testFunction( strText ){
alert (strText)
}
</pre>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<title>Nonbreaking Spaces
Example</title>
</head>
<body>
<p>An example of this technique appears
in the movie
"12 Angry Men."</p>
</body>
</html>
HTML ELEMENTS
An HTML element is defined by a
starting tag. If the element contains
other content, it ends with a closing
tag, where the element name is
preceded by a forward slash as
shown below with few tags:
HTML Attributes
HTML elements can have attributes
Attributes provide additional
information about the element
Attributes are always specified in the
start tag
Attributes come in name/value pairs
like:
name="value"
HTML Attributes
We have seen few HTML tags and
their usage like heading tags <h1>,
<h2>, paragraph tag <p> and
other tags.
We used them so far in their simplest
form, but most of the HTML tags can
also have attributes, which are extra
bits of information.
Example
<!DOCTYPE html>
<html>
<head>
<title>Align Attribute Example</title>
</head>
<body>
<p align="left">This is left aligned</p>
<p align="center">This is center aligned</p>
<p align="right">This is right aligned</p>
</body>
</html>
Core Attributes:
The four core attributes that can be used on
the majority of HTML elements
The id Attribute
The id attribute can be used to
uniquely identify any element
within a page ( or style sheet ).
The id Attribute:
If you have two elements of the same
name within a Web page (or style sheet),
you can use the id attribute to distinguish
between elements that have the same
name.
Example
<!DOCTYPE html>
<html>
<head>
<title>The title Attribute
Example</title>
</head>
<body>
<h3 title="Hello HTML!">Titled Heading
Tag Example</h3>
</body>
</html>
style="property:value;
Thepropertyis a CSS property.
Thevalueis a CSS value
<body> element
The : <body> element
<body>
<p>This is body tag</p>
</body>
The <body> element defines the body of
the HTML document
The element has a start tag <body> and
an end tag </body>
The element content is another HTML
element
bgcolor (color)
bgcolor (color)
Sets a color to be used as
background of the document.
Example:
<body bgcolor="green">
Example
<html>
<head>
<title>My First Web Page - HTML is simple!
</title>
</head>
<BODY BACKGROUND=index.jpeg TEXT=#ffffff>
Representation
Non-Breaking Space
"
"
< <
> >
& &
©
®
<ahref="http://www.w3schools
.com">This is a link </a>
Size Attributes
HTML images are defined with
the<img>tag
The filename of the source (src), and the
size of the image (widthandheight) are all
provided asattributes
<imgsrc="w3schools.jpg"width="104"h
eight="142">
The image size is specified in pixels:
width="104" means 104 screen pixels wide.
HTMLQuotation and
Citation Elements
<p>The<abbrtitle="World Health
Organization">WHO</abbr>was
founded in 1948.</p>
<address>
Written by Jon Doe.<br>
Visit us at:<br>
Example.com<br>
Box 564, Disneyland<br>
USA
</address>
HTMLComputer Code
Elements
Physical tags
Physical tags are used to indicate
exactly how specific characters are
to be formatted.
Logical Tags
Logical tags are used to indicate to
the visually impaired that there is
some emphasizes on the text.
Each browser has its own technique
as to how to indicate to its viewer
that the text between the tags are
different.
HTML Links
Links are found in nearly all web pages
Links allow users to click their way from page
to page
Local Links
A local link (link to the same web site)
is specified with a relative URL
(without http://www....)
Example
<ahref="html_images.asp">HTM
L Images</a>
Example
<style>
a:link{color:green;backgroun
d-color:transparent;textdecoration:none}
a:visited{color:pink;backgroun
d-color:transparent;textdecoration:none}
a:hover{color:red;background
-color:transparent;textdecoration:underline}
a:active{color:yellow;backgrou
<ahref="http://www.w3schools.
com/"target="_blank">Visit
W3Schools!</a>
Target
Value
Description
_blank
_self
_parent
_top
Example
1. First, create a bookmark with the id
attribute
HTMLLists
Item
Item
Item
Item
Ordered List:
1.
2.
3.
4.
First item
Second item
Third item
Fourth item
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Description
list-styletype:disc
list-styletype:circle
list-styletype:square
list-style-
Circle
<ulstyle="list-style-type:circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Description
type="1"
type="A"
type="a"
type="I"
type="i"
Uppercase Letters
<oltype="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Example
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Horizontal Lists
HTML lists can be styled in many
different ways with CSS.
One popular way, is to style a
list to be displayed horizontally
<!DOCTYPEhtml>
<html>
<head>
<style>
ul#menu li {
display:inline;
}
</style>
</head>
<body>
<h2>Horizontal List</h2>
<ulid="menu">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>PHP</li>
</ul>
</body>
</html>
Output
Output
Description
HTML Images
<imgsrc="url"alt="some_text">
Example
<!DOCTYPEhtml>
<html>
<body>
<h2>Spectacular Mountain</h2>
<imgsrc="pic_mountain.jpg"alt="Mountai
n
View"style="width:304px;height:228px;">
</body>
</html>
Example
<imgsrc="wrongname.gif"alt="HTM
L5
Icon"style="width:128px;height:128
px;">
<imgsrc="html5.gif"alt="HTML5
Icon"style="width:128px;height:12
8px;">
<imgsrc="http://www.w3schools.co
m/images/w3schools_green.jpg"alt=
"W3Schools.com">
Animated Images
The GIF standard allows animated
images
<imgsrc="programming.gif"alt="Co
mputer
Man"style="width:48px;height:48px;
">
Image Floating
Use the CSS float property to let the
image float.
The image can float to the right or to
the left of a text
<p>
<imgsrc="smiley.gif"alt="Smiley
face"style="float:right;width:42px;heig
ht:42px;">
The image will float to the right of the
text.
</p>
<p>
<imgsrc="smiley.gif"alt="Smiley
face"style="float:left;width:42px;height
:42px;">
The image will float to the left of the text.
</p>
Output
Image Maps
Use the <map> tag to define an imagemap. An image-map is an image with
clickable areas.
The name attribute of the <map> tag is
associated with the <img>'s usemap
attribute and creates a relationship
between the image and the map.
The <map> tag contains a number of
<area> tags, that defines the clickable
areas in the image-map
<imgsrc="planets.gif"alt="Planets"use
map="#planetmap"style="width:145p
x;height:126px;">
<mapname="planetmap">
<areashape="rect"coords="0,0,82,1
26"alt="Sun"href="sun.htm">
<areashape="circle"coords="90,58,
3"alt="Mercury"href="mercur.htm">
<areashape="circle"coords="124,5
8,8"alt="Venus"href="venus.htm">
</map>
Output