HTML Lectures
HTML Lectures
Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
What is HTML?
HTML is a markup language for describing web documents (web pages).
• Markup language:
HTML Example
A small HTML document:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Example Explained
• The DOCTYPE declaration defines the document type to be HTML
• The text between <html> and </html> describes an HTML document
• The text between <head> and </head> provides information about the document
• The text between <title> and </title> provides a title for the document
• The text between <body> and </body> describes the visible page content
• The text between <h1> and </h1> describes a heading
• The text between <p> and </p> describes a paragraph
Using this description, a web browser can display a document with a heading and a paragraph.
HTML Tags
HTML tags are keywords (tag names) surrounded by angle brackets:
<tagname>content</tagname>
• HTML tags normally come in pairs like <p> and </p>
• The first tag in a pair is the start tag, the second tag is the end tag
• The end tag is written like the start tag, but with a slash before the tag name
The start tag is often called the opening tag. The end tag is often called the closing tag.
Web Browsers
The purpose of a web browser (Chrome, IE, Firefox, Safari) is to read HTML documents and
display them.
The browser does not display the HTML tags, but uses them to determine how to display the
document:
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
Only the <body> area (the white area) is displayed by the browser.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
The <!DOCTYPE> Declaration
The <!DOCTYPE> declaration helps the browser to display a web page correctly.
To display a document correctly, the browser must know both type and version.
The doctype declaration is not case sensitive. All cases are acceptable:
<!DOCTYPE html>
<!DOCTYPE HTML>
<!doctype html>
<!Doctype Html>
Common Declarations
HTML5
<!DOCTYPE html>
HTML 4.01
XHTML 1.0
HTML Versions
Since the early days of the web, there have been many versions of HTML:
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Version Year
HTML 1991
HTML 2.0 1995
HTML 3.2 1997
HTML 4.01 1999
XHTML 2000
HTML5 2014
HTML Editors
However, for learning HTML we recommend a text editor like Notepad (PC) or TextEdit (Mac).
Follow the 4 steps below to create your first web page with Notepad.
Click Start (bottom left on your screen). Click All Programs. Click Accessories. Click
Notepad.
Open the Start Screen (the window symbol at the bottom left on your screen). Type Notepad.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Step 2: Write Some HTML
Write or copy some HTML into Notepad.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Name the file "[Link]" or any other name ending with html or htm.
You can use either .htm or .html as file extension. There is no difference, it is up to you.
To open a file in a browser, double click on the file, or right-click, and choose open with.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
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 between <body> and </body>.
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
HTML Headings
HTML headings are defined with the <h1> to <h6> tags:
Example
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
HTML Paragraphs
HTML paragraphs are defined with the <p> tag:
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML Links
HTML links are defined with the <a> tag:
Example
<a href="[Link] is a link</a>
The source file (src), alternative text (alt), and size (width and height) are provided as
attributes:
Example
<img src=" [Link]" alt="[Link] " width="104" height="142">
HTML Elements
HTML elements are written with a start tag, with an end tag, with the content in between:
<tagname>content</tagname>
The HTML element is everything from the start tag to the end tag:
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<html>
<body>
</body>
</html>
The element content is two other HTML elements (<h1> and <p>).
<body>
</body>
Example
<html>
<body>
<p>This is a paragraph
<p>This is a paragraph
</body>
</html>
The example above works in all browsers, because the closing tag is considered optional.
Never rely on this. It might produce unexpected results and/or errors if you forget the end tag.
<br> is an empty element without a closing tag (the <br> tag defines a line break).
Empty elements can be "closed" in the opening tag like this: <br />.
HTML5 does not require empty elements to be closed. But if you want stricter validation, or you
need to make your document readable by XML parsers, you should close all HTML elements.
The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in
HTML4, and demands lowercase for stricter document types like XHTML.
HTML Attributes
HTML Attributes
• HTML elements can have attributes
• Attributes provide additional information about an element
• Attributes are always specified in the start tag
• Attributes come in name/value pairs like: name="value"
<!DOCTYPE html>
<html lang="en-US">
<body>
</body>
</html>
The first two letters specify the language (en). If there is a dialect, use two more letters (US).
In this example, the <p> element has a title attribute. The value of the attribute is "About ICE":
Example
<p title="About ICE">
ICE is one of the emerging department at Pabna University of Science and Technology.
It provides friendly environment for teachers and students. We are proud to be a part of it.
</p>
When you move the mouse over the element, the title will be displayed as a tooltip.
Example
<a href="http:// [Link] ">This is a link</a>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
You will learn more about links and the <a> tag later in this tutorial.
Size Attributes
HTML images are defined with the <img> tag.
The filename of the source (src), and the size of the image (width and height) are all provided as
attributes:
Example
<img src="[Link]" width="104" height="142">
The image size is specified in pixels: width="104" means 104 screen pixels wide.
You will learn more about images and the <img> tag later in this tutorial.
The value of the attribute can be read by "screen readers". This way, someone "listening" to the
webpage, i.e. a blind person, can "hear" the element.
Example
<img src=" [Link]" alt=" [Link]" width="104" height="142">
The title attribute can be written with upper or lower case like Title and/or TITLE.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
W3C recommends lowercase in HTML4, and demands lowercase for stricter document types
like XHTML.
Example
<a href=[Link]
W3C recommends quotes in HTML4, and demands quotes for stricter document types like
XHTML.
Sometimes it is necessary to use quotes. This will not display correctly, because it contains a
space:
Example
<p title=About ICE>
Using quotes are the most common. Omitting quotes can produce errors.
Or vice versa:
Chapter Summary
• All HTML elements can have attributes
• The HTML title attribute provides additional "tool-tip" information
• The HTML href attribute provides address information for links
• The HTML width and height attributes provide size information for images
• The HTML alt attribute provides text for screen readers
HTML Attributes
Below is an alphabetical list of some attributes often used in HTML:
Attribute Description
alt Specifies an alternative text for an image
disabled Specifies that an input element should be disabled
href Specifies the URL (web address) for a link
id Specifies a unique id for an element
src Specifies the URL (web address) for an image
style Specifies an inline CSS style for an element
title Specifies extra information about an element (displayed as a tool tip)
value Specifies the value (text content) for an input element.
A complete list of all attributes for each HTML element, is listed in our: HTML Tag Reference.
HTML Headings
HTML Headings
Headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important heading.
Example
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
Note: Browsers automatically add some empty space (a margin) before and after each heading.
Search engines use your headings to index the structure and content of your web pages.
Users skim your pages by its headings. It is important to use headings to show the document
structure.
h1 headings should be main headings, followed by h2 headings, then the less important h3, and
so on.
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<p>This is a paragraph.</p>
<hr>
<p>This is a paragraph.</p>
<hr>
<p>This is a paragraph.</p>
The HTML <head> element contains meta data. Meta data are not displayed.
The HTML <head> element is placed between the <html> tag and the <body> tag:
Example
<!DOCTYPE html>
<html>
<head>
<title>My First HTML</title>
<meta charset="UTF-8">
</head>
<body>
.
.
.
Meta data means data about data. HTML meta data is data about the HTML document.
The title will not be displayed in the document, but might be displayed in the browser tab.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
It can be used to define the character set, and other information about the HTML document.
The HTML <style> element is used to define internal CSS style sheets.
The HTML <link> element is used to define external CSS style sheets.
To find out, right-click in the page and select "View Page Source" (in Chrome) or "View Source"
(in IE), or similar in another browser. This will open a window containing the HTML code of the
page.
You will learn more about HTML tags and attributes in the next chapters of this tutorial.
Tag Description
<html> Defines an HTML document
<body> Defines the document's body
<head> Defines the document's head element
<h1> to <h6> Defines HTML headings
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<hr> Defines a horizontal line
HTML Paragraphs
HTML Paragraphs
The HTML <p> element defines a paragraph.
Example
<p>This is a paragraph</p>
<p>This is another paragraph</p>
HTML Display
You cannot be sure how HTML will be displayed.
Large or small screens, and resized windows will create different results.
With HTML, you cannot change the output by adding extra spaces or extra lines in your HTML
code.
The browser will remove extra spaces and extra lines when the page is displayed.
Any number of spaces, and any number of new lines, count as only one space.
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<p>
This paragraph
contains a lot of lines
in the source code,
but the browser
ignores it.
</p>
<p>
This paragraph
contains a lot of spaces
in the source code,
but the browser
ignores it.
</p>
Example
<p>This is a paragraph
<p>This is another paragraph
The example above will work in most browsers, but do not rely on it.
Stricter versions of HTML, like XHTML, do not allow you to skip the end tag.
Use <br> if you want a line break (a new line) without starting a new paragraph:
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Example
<p>This is<br>a para<br>graph with line breaks</p>
The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and it
preserves both spaces and line breaks:
Example
<pre>
My Bonnie lies over the ocean.
Tag Description
<p> Defines a paragraph
<br> Inserts a single line break
<pre> Defines pre-formatted text
HTML Styles
I am Red
I am Blue
HTML Styling
Every HTML element has a default style (background color is white and text color is black).
Changing the default style of an HTML element, can be done with the style attribute.
This example changes the default background color from white to lightgrey:
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<body style="background-color:lightgrey">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
The bgcolor attribute, supported in older versions of HTML, is not valid in HTML5.
style="property:value"
Example
<h1 style="color:blue">This is a heading</h1>
<p style="color:red">This is a paragraph.</p>
HTML Fonts
The font-family property defines the font to be used for an HTML element:
Example
<h1 style="font-family:verdana">This is a heading</h1>
<p style="font-family:courier">This is a paragraph.</p>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
The <font> tag, supported in older versions of HTML, is not valid in HTML5.
Example
<h1 style="font-size:300%">This is a heading</h1>
<p style="font-size:160%">This is a paragraph.</p>
Example
<h1 style="text-align:center">Centered Heading</h1>
<p>This is a paragraph.</p>
The <center> tag, supported in older versions of HTML, is not valid in HTML5.
Chapter Summary
• Use the style attribute for styling HTML elements
• Use background-color for background color
• Use color for text colors
• Use font-family for text fonts
• Use font-size for text sizes
• Use text-align for text alignment
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Text Formatting
This text is bold
This is superscript
HTML also defines special elements, for defining text with a special meaning.
HTML uses elements like <b> and <i> for formatting output, like bold or italic text.
• Bold text
• Important text
• Italic text
• Emphasized text
• Marked text
• Small text
• Deleted text
• Inserted text
• Subscripts
• Superscripts
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<p>This text is normal.</p>
The HTML <strong> element defines strong text, with added semantic "strong" importance.
Example
<p>This text is normal.</p>
Example
<p>This text is normal.</p>
The HTML <em> element defines emphasized text, with added semantic importance.
Example
<p>This text is normal.</p>
However, there is a difference in the meaning of these tags: <b> and <i> defines bold and
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
italic text,
but <strong> and <em> means that the text is "important".
Example
<h2>HTML <small>Small</small> Formatting</h2>
Example
<h2>HTML <mark>Marked</mark> Formatting</h2>
Example
<p>My favorite color is <del>blue</del> red.</p>
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<p>My favorite <ins>color</ins> is red.</p>
Example
<p>This is <sub>subscripted</sub> text.</p>
Example
<p>This is <sup>superscripted</sup> text.</p>
Quotation
Here is a quote from WWF's website:
For 50 years, WWF has been protecting the future of nature. The world's leading
conservation organization, WWF works in 100 countries and is supported by 1.2 million
members in the United States and close to 5 million globally.
Example
<p>WWF's goal is to: <q>Build a future where people live in harmony with nature.</q></p>
Example
<p>Here is a quote from WWF's website:</p>
<blockquote cite="[Link]
For 50 years, WWF has been protecting the future of nature.
The world's leading conservation organization,
WWF works in 100 countries and is supported by
1.2 million members in the United States and
close to 5 million globally.
</blockquote>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Marking abbreviations can give useful information to browsers, translation systems and search-
engines.
Example
<p>The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>
The <address> element is usually displayed in italic. Most browsers will add a line break before
and after the element.
Example
<address>
Written by Jon Doe.<br>
Visit us at:<br>
[Link]<br>
Box 564, Disneyland<br>
USA
</address>
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<p><cite>The Scream</cite> by Edward Munch. Painted in 1893.</p>
Example
<bdo dir="rtl">This text will be written from right to left</bdo>
The <kbd>, <samp>, and <code> elements all support fixed letter size and spacing.
Example
<p>To open a file, select:</p>
<p><kbd>File | Open...</kbd></p>
Example
<samp>
[Link] login: Apr 12 09:10:17
Linux 2.6.10-grsec+gg3+e+fhs6b+nfs+gr0501+++p3+c4a+gr2b-reslog-v6.189
</samp>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
HTML Code Formatting
The HTML <code> element defines programming code:
Example
<code>
var person = { firstName:"John", lastName:"Doe", age:50, eyeColor:"blue" }
</code>
The <code> element does not preserve extra whitespace and line-breaks:
Example
<p>Coding Example:</p>
<code>
var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"
}
</code>
Example
<p>Coding Example:</p>
<code>
<pre>
var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"
}
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
</pre>
</code>
Example
<p>Einstein wrote:</p>
<p><var>E = m c<sup>2</sup></var></p>
HTML Comments
Comment tags <!-- and --> are used to insert comments in HTML.
Comments are not displayed by the browser, but they can help document your HTML.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
With comments you can place notifications and reminders in your HTML:
Example
<!-- This is a comment -->
<p>This is a paragraph.</p>
Comments are also great for debugging HTML, because you can comment out HTML lines of
code, one at a time, to search for errors:
Example
<!-- Do not display this at the moment
<img border="0" src="pic_mountain.jpg" alt="Mountain">
-->
Conditional Comments
You might stumble upon conditional comments in HTML:
<!--[if IE 8]>
.... some HTML here ....
<![endif]-->
For example <!--webbot bot--> tags wrapped inside HTML comments by FrontPage and
Expression Web.
As a rule, let these tags stay, to help support the software that created them.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color:lightgray}
h1 {color:blue}
p {color:green}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS Syntax
CSS styling has the following syntax:
The element is an HTML element name. The property is a CSS property. The value is a CSS
value.
Example
<h1 style="color:blue">This is a Blue Heading</h1>
Internal styling is defined in the <head> section of an HTML page, using a <style> element:
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color:lightgrey}
h1 {color:blue}
p {color:green}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
With external style sheets, you can change the look of an entire web site by changing one file.
External styles are defined in an external CSS file, and then linked to in the <head> section of
an HTML page:
Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
CSS Fonts
The CSS color property defines the text color to be used for the HTML element.
The CSS font-family property defines the font to be used for the HTML element.
The CSS font-size property defines the text size to be used for the HTML element.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color:blue;
font-family:verdana;
font-size:300%;
}
p {
color:red;
font-family:courier;
font-size:160%;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The CSS border property defines a visible border around an HTML element:
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Example
p{
border:1px solid black;
}
The CSS padding property defines a padding (space) inside the border:
Example
p{
border:1px solid black;
padding:10px;
}
The CSS margin property defines a margin (space) outside the border:
Example
p{
border:1px solid black;
padding:10px;
margin:30px;
}
The id Attribute
All the examples above use CSS to style HTML elements in a general way.
To define a special style for one special element, first add an id attribute to the element:
Example
<p id="p01">I am different</p>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
then define a different style for the (identified) element:
Example
p#p01 {
color:blue;
}
Example
<p class="error">I am different</p>
Now you can define a different style for all elements with the specified class:
Example
[Link] {
color:red;
}
HTML Links
Links are found in nearly all web pages. Links allow users to click their way from page to page.
A hyperlink is a text or an image you can click on, and jump to another document.
Example
<a href="[Link] our HTML tutorial</a>
The link text is the visible part (Visit our HTML tutorial).
Clicking on the link text, will send you to the specified address.
The link text does not have to be text. It can be an HTML image or any other HTML
element.
Without a trailing slash on subfolder addresses, you might generate two requests to the
server. Many servers will automatically add a trailing slash to the address, and then create
a new request.
Local Links
The example above used an absolute URL (A full web address).
A local link (link to the same web site) is specified with a relative URL (without [Link]
Example
<a href="html_images.asp">HTML Images</a>
Example
<style>
a:link {color:green; background-color:transparent; text-decoration:none}
a:visited {color:pink; background-color:transparent; text-decoration:none}
a:hover {color:red; background-color:transparent; text-decoration:underline}
a:active {color:yellow; background-color:transparent; text-decoration:underline}
</style>
This example will open the linked document in a new browser window or in a new tab:
Example
<a href="[Link] target="_blank">Visit W3Schools!</a>
If your webpage is locked in a frame, you can use target="_top" to break out of the frame:
Example
<a href="[Link] target="_top">HTML5 tutorial!</a>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Example
<a href="[Link]">
<img src="[Link]" alt="HTML tutorial" style="width:42px;height:42px;border:0">
</a>
border:0 is added to prevent IE9 (and earlier) from displaying a border around the image.
To make a bookmark, you must first create the bookmark, and then add a link to it.
When the link is clicked, the page will scroll to the location with the bookmark.
Example
First, create a bookmark with the id attribute:
Then, add a link to the bookmark ("Useful Tips Section"), from within the same page:
Or, add a link to the bookmark ("Useful Tips Section"), from another page:
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<a href="html_tips.htm#tips">Visit the Useful Tips Section</a>
Chapter Summary
• Use the HTML <a> element to define a link
• Use the HTML href attribute to define the link address
• Use the HTML target attribute to define where to open the linked document
• Use the HTML <img> element (inside <a>) to use an image as a link
• Use the HTML id attribute (id="value") to define bookmarks in a page
• Use the HTML href attribute (href="#value") to link to the bookmark
HTML Images
Example
GIF Images
JPG Images
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
PNG Images
<!DOCTYPE html>
<html>
<body>
<h2>Spectacular Mountain</h2>
<img src="pic_mountain.jpg" alt="Mountain View" style="width:304px;height:228px;">
</body>
</html>
Always specify the width and height of an image. If width and height are not specified, the
page will flicker while the image loads.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
HTML Images Syntax
In HTML, images are defined with the <img> tag.
The <img> tag is empty, it contains attributes only, and does not have a closing tag.
The src attribute specifies the URL (web address) of the image:
The alt attribute provides alternative information for an image if a user for some reason cannot
view it (because of slow connection, an error in the src attribute, or if the user uses a screen
reader).
Example
<img src="[Link]" alt="HTML5 Icon" style="width:128px;height:128px;">
The alt attribute is required. A web page will not validate correctly without it.
Screen readers are useful to people who are blind, visually impaired, or learning disabled.
Example
<img src="[Link]" alt="HTML5 Icon" style="width:128px;height:128px;">
Alternatively, you can use width and height attributes. Here, the values are specified in pixels by
default:
Example
<img src="[Link]" alt="HTML5 Icon" width="128" height="128">
We suggest you use the style attribute. It prevents styles sheets from changing the original size of
images:
Example
<!DOCTYPE html>
<html>
<head>
<style>
img {
width:100%;
}
</style>
</head>
<body>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
</body>
</html>
However, it is common to store images in a sub-folder. You must then include the folder name in
the src attribute:
Example
<img src="/images/[Link]" alt="HTML5 Icon" style="width:128px;height:128px;">
Actually, you can access images from any web address in the world:
Example
<img src="[Link] alt="[Link]">
Animated Images
The GIF standard allows animated images:
Example
<img src="[Link]" alt="Computer Man" style="width:48px;height:48px;">
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Note that the syntax of inserting animated images is no different from non-animated images.
Example
<a href="[Link]">
<img src="[Link]" alt="HTML tutorial" style="width:42px;height:42px;border:0;">
</a>
Add "border:0;" to prevent IE9 (and earlier) from displaying a border around the image.
Image Floating
Use the CSS float property to let the image float.
Example
<p>
<img src="[Link]" alt="Smiley face" style="float:right;width:42px;height:42px;">
The image will float to the right of the text.
</p>
<p>
<img src="[Link]" alt="Smiley face" style="float:left;width:42px;height:42px;">
The image will float to the left of the text.
</p>
Image Maps
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Use the <map> tag to define an image-map. 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:
Example
<img src="[Link]" alt="Planets" usemap="#planetmap" style="width:145px;height:126px;">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="[Link]">
<area shape="circle" coords="90,58,3" alt="Mercury" href="[Link]">
<area shape="circle" coords="124,58,8" alt="Venus" href="[Link]">
</map>
Chapter Summary
• Use the HTML <img> element to define an image
• Use the HTML src attribute to define the URL of the image
• Use the HTML alt attribute to define an alternate text for an image, if it cannot be
displayed
• Use the HTML width and height attributes to define the size of the image
• Use the CSS width and height properties to define the size of the image (alternatively)
• Use the CSS float property to let the image float
• Use the HTML <map> element to define an image-map
• Use the HTML <area> element to define the clickable areas in the image-map
• Use the HTML <img>'s element usemap attribute to point to an image-map
Loading images takes time. Large images can slow down your page. Use images carefully.
HTML Tables
1
Example explained:
Tables are divided into table rows with the <tr> tag.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Table rows are divided into table data with the <td> tag.
A table row can also be divided into table headings with the <th> tag.
Example
<table border="1" style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
The border attribute is on its way out of the HTML standard! It is better to use CSS.
Example
table, th, td {
border: 1px solid black;
}
Remember to define borders for both the table and the table cells.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Example
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
If you do not specify a padding, the table cells will be displayed without padding.
Example
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
}
By default, all major browsers display table headings as bold and centered:
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Example
th {
text-align: left;
}
To set the border spacing for a table, use the CSS border-spacing property:
Example
table {
border-spacing: 5px;
}
Example
<table style="width:100%">
<tr>
<th>Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<td>555 77 855</td>
</tr>
</table>
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<table style="width:100%">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
The <caption> tag must be inserted immediately after the <table> tag.
Example
<table id="t01">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Chapter Summary
• Use the HTML <table> element to define a table
• Use the HTML <tr> element to define a table row
• Use the HTML <td> element to define a table data
• Use the HTML <th> element to define a table heading
• Use the HTML <caption> element to define a table caption
• Use the CSS border property to define a border
• Use the CSS border-collapse property to collapse cell borders
• Use the CSS padding property to add padding to cells
• Use the CSS text-align property to align cell text
• Use the CSS border-spacing property to set the spacing between cells
• Use the colspan attribute to make a cell span many columns
• Use the rowspan attribute to make a cell span many rows
• Use the id attribute to uniquely define one table
HTML Lists
Unordered lists and ordered lists are commonly used in
HTML:
Unordered List
Ordered List
The list items will be marked with bullets (small black circles):
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Style Description
list-style-type:disc The list items will be marked with bullets (default)
list-style-type:circle The list items will be marked with circles
list-style-type:square The list items will be marked with squares
list-style-type:none The list items will not be marked
Disc:
<ul style="list-style-type:disc">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Circle:
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Square:
<ul style="list-style-type:square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
None:
<ul style="list-style-type:none">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Type Description
type="1" The list items will be numbered with numbers (default)
type="A" The list items will be numbered with uppercase letters
type="a" The list items will be numbered with lowercase letters
type="I" The list items will be numbered with uppercase roman numbers
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
type="i" The list items will be numbered with lowercase roman numbers
Numbers:
<ol type="1">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Uppercase Letters:
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Lowercase Letters:
<ol type="a">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
The <dl> tag defines the description list, the <dt> tag defines the term (name), and the <dd> tag
describes each term:
Example
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Example
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
List items can contain new list, and other HTML elements, like images and links, etc.
Horizontal Lists
HTML lists can be styled in many different ways with CSS.
<head>
<style>
ul#menu li {
display:inline;
}
</style>
</head>
<body>
<h2>Horizontal List</h2>
<ul id="menu">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>PHP</li>
</ul>
</body>
</html>
With a little extra style, you can make it look like a menu:
Example
ul#menu {
padding: 0;
}
ul#menu li {
display: inline;
}
ul#menu li a {
background-color: black;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 4px 4px 0 0;
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
}
ul#menu li a:hover {
background-color: orange;
}
Chapter Summary
• Use the HTML <ul> element to define an unordered list
• Use the HTML style attribute to define the bullet style
• Use the HTML <ol> element to define an ordered list
• Use the HTML type attribute to define the numbering type
• Use the HTML <li> element to define a list item
• Use the HTML <dl> element to define a description list
• Use the HTML <dt> element to define the description term
• Use the HTML <dd> element to define the description data
• Lists can be nested inside lists
• List items can contain other HTML elements
• Use the CSS property display:inline to display a list horizontally
Every HTML element has a default display value depending on what type of element it is. The
default display value for most elements is block or inline.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Block-level Elements
A block-level element always starts on a new line and takes up the full width available (stretches
out to the left and right as far as it can).
• <div>
• <h1> - <h6>
• <p>
• <form>
Inline Elements
An inline element does not start on a new line and only takes up as much width as necessary.
• <span>
• <a>
• <img>
The <div> element has no required attributes, but style and class are common.
When used together with CSS, the <div> element can be used to style blocks of content:
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<div style="background-color:black; color:white; padding:20px;">
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
</div>
The <span> element has no required attributes, but style and class are common.
When used together with CSS, the <span> element can be used to style parts of the text:
Example
<h1>My <span style="color:red">Important</span> Heading</h1>
HTML Classes
London
London is the capital city of England. It is the most populous city in the United Kingdom, with a
metropolitan area of over 13 million inhabitants.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Standing on the River Thames, London has been a major settlement for two millennia, its history
going back to its founding by the Romans, who named it Londinium.
Paris
Paris is the capital and most populous city of France.
Situated on the Seine River, it is at the heart of the Île-de-France region, also known as the
région parisienne.
Within its metropolitan area is one of the largest population centers in Europe, with over 12
million inhabitants.
Tokyo
Tokyo is the capital of Japan, the center of the Greater Tokyo Area, and the most populous
metropolitan area in the world.
It is the seat of the Japanese government and the Imperial Palace, and the home of the Japanese
Imperial Family.
The Tokyo prefecture is part of the world's most populous metropolitan area with 38 million
people and the world's largest urban economy.
Example
<!DOCTYPE html>
<html>
<head>
<style>
[Link] {
background-color:black;
color:white;
margin:20px;
padding:20px;
}
</style>
</head>
<body>
<div class="cities">
<h2>London</h2>
<p>London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
</div>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<div class="cities">
<h2>Paris</h2>
<p>Paris is the capital and most populous city of France.</p>
</div>
<div class="cities">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,
and the most populous metropolitan area in the world.</p>
</div>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<style>
[Link] {font-size:120%;color:red;}
</style>
</head>
<body>
</body>
</html>
HTML Layouts
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
City Gallery
London
Paris
Tokyo
London
London is the capital city of England. It is the most populous city in the United Kingdom, with a
metropolitan area of over 13 million inhabitants.
Standing on the River Thames, London has been a major settlement for two millennia, its history
going back to its founding by the Romans, who named it Londinium.
Copyright © [Link]
Example
<body>
<div id="header">
<h1>City Gallery</h1>
</div>
<div id="nav">
London<br>
Paris<br>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Tokyo<br>
</div>
<div id="section">
<h1>London</h1>
<p>
London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</div>
<div id="footer">
Copyright © © [Link]
</div>
</body>
The CSS:
<style>
#header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:350px;
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
float:left;
padding:10px;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
This example uses <header>, <nav>, <section>, and <footer> to create a multiple column layout:
Example
<body>
<header>
<h1>City Gallery</h1>
</header>
<nav>
London<br>
Paris<br>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Tokyo<br>
</nav>
<section>
<h1>London</h1>
<p>
London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
</p>
<p>
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
</p>
</section>
<footer>
Copyright © [Link]
</footer>
</body>
The CSS
<style>
header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
section {
width:350px;
float:left;
padding:10px;
}
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
Layout can be achieved using the <table> element, because table elements can be styled with
CSS:
Example
<body>
<table class="lamp">
<tr>
<th>
<img src="/images/[Link]" alt="Note" style="height:32px;width:32px">
</th>
<td>
The table element was not designed to be a layout tool.
</td>
</tr>
</table>
</body>
The CSS
<style>
[Link] {
width:100%;
border:1px solid #d4d4d4;
}
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
[Link] th, td {
padding:10px;
}
[Link] th {
width:40px;
}
</style>
Example
<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
.city {
float: left;
margin: 5px;
padding: 15px;
width: 300px;
height: 300px;
border: 1px solid black;
}
</style>
</head>
<body>
<h1>W3Schools Demo</h1>
<h2>Resize this responsive page!</h2>
<div class="city">
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>It is the most populous city in the United Kingdom, with a metropolitan area of over 13
million inhabitants.</p>
</div>
<div class="city">
<h2>Paris</h2>
<p>Paris is the capital and most populous city of France.</p>
</div>
<div class="city">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area, and the most populous
metropolitan area in the world.</p>
</div>
</body>
</html>
Using [Link]
Another way to create a responsive design, is to use a responsive style sheet, like [Link]
[Link] makes it easy to develop sites that look nice at any size; desktop, laptop, tablet, or
phone:
[Link] Demo
Resize the page to see the responsivenes!
London
London is the capital city of England.
It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million
inhabitants.
Paris
Paris is the capital of France.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
The Paris area is one of the largest population centers in Europe, with more than 12 million
inhabitants.
Tokyo
Tokyo is the capital of Japan.
It is the center of the Greater Tokyo Area, and the most populous metropolitan area in the world.
Example
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="[Link]
<body>
<div class="w3-row-padding">
<div class="w3-third">
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>
</div>
<div class="w3-third">
<h2>Paris</h2>
<p>Paris is the capital of France.</p>
<p>The Paris area is one of the largest population centers in Europe,
with more than 12 million inhabitants.</p>
</div>
<div class="w3-third">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>
<p>It is the center of the Greater Tokyo Area,
and the most populous metropolitan area in the world.</p>
</div>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
</div>
</body>
</html>
HTML Iframes
Iframe Syntax
The syntax for adding an iframe is:
<iframe src="URL"></iframe>
The src attribute specifies the URL (web address) of the iframe page.
The attribute values are specified in pixels by default, but they can also be in percent (like
"80%").
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<iframe src="demo_iframe.htm" width="200" height="200"></iframe>
To remove the border, add the style attribute and use the CSS border property:
Example
<iframe src="demo_iframe.htm" style="border:none"></iframe>
With CSS, you can also change the size, style and color of the iframe's border:
Example
<iframe src="demo_iframe.htm" style="border:5px dotted red"></iframe>
The target attribute of the link must refer to the name attribute of the iframe:
Example
<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
<p><a href="[Link] target="iframe_a">[Link]</a></p>
HTML Colors
Colors in HTML can be specified by the following methods:
• Hexadecimal colors
• RGB colors
• Color names
Hexadecimal Colors
Hexadecimal color values are supported in all major browsers.
A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and BB
(blue) hexadecimal integers specify the components of the color. All values must be between 00
and FF.
For example, the #0000FF value is rendered as blue, because the blue component is set to its
highest value (FF) and the others are set to the lowest value (00).
RGB Colors
RGB color values are supported in all major browsers.
An RGB color value is specified with: rgb(red, green, blue). Each parameter (red, green, and
blue) defines the intensity of the color and can be an integer between 0 and 255.
For example, the rgb(0,0,255) value is rendered as blue, because the blue parameter is set to its
highest value (255) and the others are set to 0.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Color Names
All major browsers also support 140 standard color names.
Examples
Example
Color Color HEX Color RGB Color Name
#FF0000 rgb(255,0,0) Red
#00FF00 rgb(0,255,0) Green
#0000FF rgb(0,0,255) Blue
Shades of grey are often defined using equal values for all the 3 light sources:
Example
Color Color HEX Color RGB Color Name
#000000 rgb(0,0,0) Black
#808080 rgb(128,128,128) Gray
#FFFFFF rgb(255,255,255) White
Shades of Gray
Gray colors are displayed using an equal amount of power to all of the light sources.
To make it easy for you to select a gray color we have compiled a table of gray shades for you:
Most modern monitors are capable of displaying at least 16384 different colors.
If you look at the color table below, you will see the result of varying the red light from 0 to 255,
while keeping the green and blue light at zero.
To see a full list of color mixes when the red light varies from 0 to 255, click on one of the HEX
or RGB values below.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Red Light HEX RGB
#000000 rgb(0,0,0)
#080000 rgb(8,0,0)
#100000 rgb(16,0,0)
#180000 rgb(24,0,0)
#200000 rgb(32,0,0)
#280000 rgb(40,0,0)
#300000 rgb(48,0,0)
#380000 rgb(56,0,0)
#400000 rgb(64,0,0)
#480000 rgb(72,0,0)
#500000 rgb(80,0,0)
#580000 rgb(88,0,0)
#600000 rgb(96,0,0)
#680000 rgb(104,0,0)
#700000 rgb(112,0,0)
#780000 rgb(120,0,0)
#800000 rgb(128,0,0)
#880000 rgb(136,0,0)
#900000 rgb(144,0,0)
#980000 rgb(152,0,0)
#A00000 rgb(160,0,0)
#A80000 rgb(168,0,0)
#B00000 rgb(176,0,0)
#B80000 rgb(184,0,0)
#C00000 rgb(192,0,0)
#C80000 rgb(200,0,0)
#D00000 rgb(208,0,0)
#D80000 rgb(216,0,0)
#E00000 rgb(224,0,0)
#E80000 rgb(232,0,0)
#F00000 rgb(240,0,0)
#F80000 rgb(248,0,0)
#FF0000 rgb(255,0,0)
This is not important now, since most computers can display millions of different colors, but the
choice is left to you.
The 216 cross-browser color palette was created to ensure that all computers would display the
colors correctly when running a 256 color palette:
HTML Scripts
The <script> element either contains scripting statements or it points to an external script file
through the src attribute.
Common uses for JavaScript are image manipulation, form validation, and dynamic changes of
content.
The script below writes Hello JavaScript! into an HTML element with id="demo":
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
Example
<script>
[Link]("demo").innerHTML = "Hello JavaScript!";
</script>
The <noscript> element can contain all the elements that you can find inside the <body> element
of a normal HTML page.
The content inside the <noscript> element will only be displayed if scripts are not supported, or
are disabled in the user's browser:
Example
<script>
[Link]("demo").innerHTML = "Hello JavaScript!";
</script>
HTML Head
HTML metadata is data about the HTML document. Metadata is not displayed.
Metadata typically define document title, styles, links, scripts, and other meta information.
The following tags describe metadata: <title>, <style>, <meta>, <link>, <script>, and <base>.
Example
<!DOCTYPE html>
<title>Page Title</title>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
We do not recommend omitting the <html> and <body> tags.
The <html> element is the document root. It is the recommended place for specifying the page
language:
<!DOCTYPE html>
<html lang="en-US">
Declaring a language is important for accessibility applications (screen readers) and search
engines.
Omitting <head>
In the HTML5 standard, the <head> tag can also be omitted.
By default, browsers will add all elements before <body>, to a default <head> element.
You can reduce the complexity of HTML, by omitting the <head> tag:
Example
<!DOCTYPE html>
<html>
<title>Page Title</title>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<title>Page Title</title>
<body>
The content of the document......
</body>
</html>
Inside the <style> element you specify how HTML elements should render in a browser:
Example
<style>
body {background-color:yellow;}
p {color:blue;}
</style>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
The HTML <link> Element
The <link> element defines the page relationship to an external resource.
Example
<link rel="stylesheet" href="[Link]">
Metadata is used by browsers (how to display content), by search engines (keywords), and other
web services.
<meta charset="UTF-8">
Example
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta name="author" content="Hege Refsnes">
<meta charset="UTF-8">
The script below writes Hello JavaScript! into an HTML element with id="demo":
Example
<script>
function myFunction {
[Link]("demo").innerHTML = "Hello JavaScript!";
}
</script>
Example
<base href="[Link] target="_blank">
HTML Entities
HTML Entities
Some characters are reserved in HTML.
If you use the less than (<) or greater than (>) signs in your text, the browser might mix them
with tags.
&entity_name;
OR
&#entity_number;
The advantage of using an entity name, instead of a number, is that the name is easier to
remember.
The disadvantage is that browsers may not support all entity names, but the support for
numbers is good.
Non-breaking Space
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
A common character entity used in HTML is the non-breaking space ( ).
Remember that browsers will always truncate spaces in HTML pages. If you write 10 spaces in
your text, the browser will remove 9 of them. To add real spaces to your text, you can use the
character entity.
Some diacritical marks, like grave ( ̀) and acute ( ́) are called accents.
Diacritical marks can appear both above and below a letter, inside a letter, and between two
letters.
You will see more HTML symbols in the next chapter of this tutorial.
HTML Symbols
Many mathematical, technical, and currency symbols, are not present on a normal keyboard.
To add these symbols to an HTML page, you can use an HTML entity name.
If no entity name exists, you can use an entity number; a decimal (or hexadecimal) reference.
If you use an HTML entity name or a hexadecimal number, the character will always
display correctly.
This is independent of what character set (encoding) your page uses!
Example
<p>I will display €</p>
<p>I will display €</p>
<p>I will display €</p>
To display an HTML page correctly, a web browser must know the character set (character
encoding) to use.
ASCII supported numbers (0-9), English letters (A-Z), and some special characters like ! $ + - ( )
@ <> .
ANSI (Windows-1252) was the original Windows character set. It supported 256 different
character codes.
ISO-8859-1 was the default character set for HTML 4. It also supported 256 different character
codes.
Because ANSI and ISO were limited, the default character encoding was changed to UTF-8 in
HTML5.
UTF-8 (Unicode) covers almost all of the characters and symbols in the world.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
All HTML 4 processors also support UTF-8.
For HTML4:
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
For HTML5:
<meta charset="UTF-8">
UTF-
Numb ASCII ANSI 8859 Description
8
32 space
33 ! ! ! ! exclamation mark
34 " " " " quotation mark
35 # # # # number sign
36 $ $ $ $ dollar sign
37 % % % % percent sign
38 & & & & ampersand
39 ' ' ' ' apostrophe
40 ( ( ( ( left parenthesis
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
41 ) ) ) ) right parenthesis
42 * * * * asterisk
43 + + + + plus sign
44 , , , , comma
45 - - - - hyphen-minus
46 . . . . full stop
47 / / / / solidus
48 0 0 0 0 digit zero
49 1 1 1 1 digit one
50 2 2 2 2 digit two
51 3 3 3 3 digit three
52 4 4 4 4 digit four
53 5 5 5 5 digit five
54 6 6 6 6 digit six
55 7 7 7 7 digit seven
56 8 8 8 8 digit eight
57 9 9 9 9 digit nine
58 : : : : colon
59 ; ; ; ; semicolon
60 < < < < less-than sign
61 = = = = equals sign
62 > > > > greater-than sign
63 ? ? ? ? question mark
64 @ @ @ @ commercial at
65 A A A A Latin capital letter A
66 B B B B Latin capital letter B
67 C C C C Latin capital letter C
68 D D D D Latin capital letter D
69 E E E E Latin capital letter E
70 F F F F Latin capital letter F
71 G G G G Latin capital letter G
72 H H H H Latin capital letter H
73 I I I I Latin capital letter I
74 J J J J Latin capital letter J
75 K K K K Latin capital letter K
76 L L L L Latin capital letter L
77 M M M M Latin capital letter M
78 N N N N Latin capital letter N
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
79 O O O O Latin capital letter O
80 P P P P Latin capital letter P
81 Q Q Q Q Latin capital letter Q
82 R R R R Latin capital letter R
83 S S S S Latin capital letter S
84 T T T T Latin capital letter T
85 U U U U Latin capital letter U
86 V V V V Latin capital letter V
87 W W W W Latin capital letter W
88 X X X X Latin capital letter X
89 Y Y Y Y Latin capital letter Y
90 Z Z Z Z Latin capital letter Z
91 [ [ [ [ left square bracket
92 \ \ \ \ reverse solidus
93 ] ] ] ] right square bracket
94 ^ ^ ^ ^ circumflex accent
95 _ _ _ _ low line
96 ` ` ` ` grave accent
97 a a a a Latin small letter a
98 b b b b Latin small letter b
99 c c c c Latin small letter c
100 d d d d Latin small letter d
101 e e e e Latin small letter e
102 f f f f Latin small letter f
103 g g g g Latin small letter g
104 h h h h Latin small letter h
105 i i i i Latin small letter i
106 j j j j Latin small letter j
107 k k k k Latin small letter k
108 l l l l Latin small letter l
109 m m m m Latin small letter m
110 n n n n Latin small letter n
111 o o o o Latin small letter o
112 p p p p Latin small letter p
113 q q q q Latin small letter q
114 r r r r Latin small letter r
115 s s s s Latin small letter s
116 t t t t Latin small letter t
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
117 u u u u Latin small letter u
118 v v v v Latin small letter v
119 w w w w Latin small letter w
120 x x x x Latin small letter x
121 y y y y Latin small letter y
122 z z z z Latin small letter z
123 { { { { left curly bracket
124 | | | | vertical line
125 } } } } right curly bracket
126 ~ ~ ~ ~ tilde
127 DEL
128 € euro sign
129 • • • NOT USED
130 ‚ single low-9 quotation mark
131 ƒ Latin small letter f with hook
132 „ double low-9 quotation mark
133 … horizontal ellipsis
134 † dagger
135 ‡ double dagger
136 ˆ modifier letter circumflex accent
137 ‰ per mille sign
138 Š Latin capital letter S with caron
139 ‹ single left-pointing angle quotation mark
140 Œ Latin capital ligature OE
141 • • • NOT USED
142 Ž Latin capital letter Z with caron
143 • • • NOT USED
144 • • • NOT USED
145 ‘ left single quotation mark
146 ’ right single quotation mark
147 “ left double quotation mark
148 ” right double quotation mark
149 • bullet
150 – en dash
151 — em dash
152 ˜ small tilde
153 ™ trade mark sign
154 š Latin small letter s with caron
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
155 › single right-pointing angle quotation mark
156 œ Latin small ligature oe
157 • • • NOT USED
158 ž Latin small letter z with caron
159 Ÿ Latin capital letter Y with diaeresis
160 no-break space
161 ¡ ¡ ¡ inverted exclamation mark
162 ¢ ¢ ¢ cent sign
163 £ £ £ pound sign
164 ¤ ¤ ¤ currency sign
165 ¥ ¥ ¥ yen sign
166 ¦ ¦ ¦ broken bar
167 § § § section sign
168 ¨ ¨ ¨ diaeresis
169 © © © copyright sign
170 ª ª ª feminine ordinal indicator
171 « « « left-pointing double angle quotation mark
172 ¬ ¬ ¬ not sign
173 soft hyphen
174 ® ® ® registered sign
175 ¯ ¯ ¯ macron
176 ° ° ° degree sign
177 ± ± ± plus-minus sign
178 ² ² ² superscript two
179 ³ ³ ³ superscript three
180 ´ ´ ´ acute accent
181 µ µ µ micro sign
182 ¶ ¶ ¶ pilcrow sign
183 · · · middle dot
184 ¸ ¸ ¸ cedilla
185 ¹ ¹ ¹ superscript one
186 º º º masculine ordinal indicator
187 » » » right-pointing double angle quotation mark
188 ¼ ¼ ¼ vulgar fraction one quarter
189 ½ ½ ½ vulgar fraction one half
190 ¾ ¾ ¾ vulgar fraction three quarters
191 ¿ ¿ ¿ inverted question mark
192 À À À Latin capital letter A with grave
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
193 Á Á Á Latin capital letter A with acute
194 Â Â Â Latin capital letter A with circumflex
195 Ã Ã Ã Latin capital letter A with tilde
196 Ä Ä Ä Latin capital letter A with diaeresis
197 Å Å Å Latin capital letter A with ring above
198 Æ Æ Æ Latin capital letter AE
199 Ç Ç Ç Latin capital letter C with cedilla
200 È È È Latin capital letter E with grave
201 É É É Latin capital letter E with acute
202 Ê Ê Ê Latin capital letter E with circumflex
203 Ë Ë Ë Latin capital letter E with diaeresis
204 Ì Ì Ì Latin capital letter I with grave
205 Í Í Í Latin capital letter I with acute
206 Î Î Î Latin capital letter I with circumflex
207 Ï Ï Ï Latin capital letter I with diaeresis
208 Ð Ð Ð Latin capital letter Eth
209 Ñ Ñ Ñ Latin capital letter N with tilde
210 Ò Ò Ò Latin capital letter O with grave
211 Ó Ó Ó Latin capital letter O with acute
212 Ô Ô Ô Latin capital letter O with circumflex
213 Õ Õ Õ Latin capital letter O with tilde
214 Ö Ö Ö Latin capital letter O with diaeresis
215 × × × multiplication sign
216 Ø Ø Ø Latin capital letter O with stroke
217 Ù Ù Ù Latin capital letter U with grave
218 Ú Ú Ú Latin capital letter U with acute
219 Û Û Û Latin capital letter U with circumflex
220 Ü Ü Ü Latin capital letter U with diaeresis
221 Ý Ý Ý Latin capital letter Y with acute
222 Þ Þ Þ Latin capital letter Thorn
223 ß ß ß Latin small letter sharp s
224 à à à Latin small letter a with grave
225 á á á Latin small letter a with acute
226 â â â Latin small letter a with circumflex
227 ã ã ã Latin small letter a with tilde
228 ä ä ä Latin small letter a with diaeresis
229 å å å Latin small letter a with ring above
230 æ æ æ Latin small letter ae
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
231 ç ç ç Latin small letter c with cedilla
232 è è è Latin small letter e with grave
233 é é é Latin small letter e with acute
234 ê ê ê Latin small letter e with circumflex
235 ë ë ë Latin small letter e with diaeresis
236 ì ì ì Latin small letter i with grave
237 í í í Latin small letter i with acute
238 î î î Latin small letter i with circumflex
239 ï ï ï Latin small letter i with diaeresis
240 ð ð ð Latin small letter eth
241 ñ ñ ñ Latin small letter n with tilde
242 ò ò ò Latin small letter o with grave
243 ó ó ó Latin small letter o with acute
244 ô ô ô Latin small letter o with circumflex
245 õ õ õ Latin small letter o with tilde
246 ö ö ö Latin small letter o with diaeresis
247 ÷ ÷ ÷ division sign
248 ø ø ø Latin small letter o with stroke
249 ù ù ù Latin small letter u with grave
250 ú ú ú Latin small letter u with acute
251 û û û Latin small letter with circumflex
252 ü ü ü Latin small letter u with diaeresis
253 ý ý ý Latin small letter y with acute
254 þ þ þ Latin small letter thorn
255 ÿ ÿ ÿ Latin small letter y with diaeresis
ASCII uses the values from 32 to 126 for letters, digits, and symbols.
UTF-8 is identical to both ANSI and 8859-1 for the values from 160 to 255.
UTF-8 continues from the value 256 with more than 10 000 different characters.
For a closer look, study our Complete HTML Character Set Reference.
Most people enter the name when surfing, because names are easier to remember than numbers.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
URL - Uniform Resource Locator
Web browsers request pages from web servers by using a URL.
When you click on a link in an HTML page, an underlying <a> tag points to an address on the
web.
A Uniform Resource Locator (URL) is used to address a document (or other data) on the web.
scheme://[Link]:port/path/filename
Explanation:
URL Encoding
URLs can only be sent over the Internet using the ASCII character-set.
Since URLs often contain characters outside the ASCII set, the URL has to be converted into
ASCII.
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
URL encoding converts characters into a format that can be transmitted over the Internet.
URL encoding replaces non ASCII characters with a "%" followed by hexadecimal digits.
URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign, or
%20.
Try It Yourself
Hello Günter
If you click "Submit", the browser will URL encode the input before it is sent to the server.
What Is XHTML?
• XHTML stands for EXtensible HyperText Markup Language
• XHTML is almost identical to HTML
• XHTML is stricter than HTML
• XHTML is HTML defined as an XML application
• XHTML is supported by all major browsers
Why XHTML?
Many pages on the internet contain "bad" HTML.
This HTML code works fine in most browsers (even if it does not follow the HTML rules):
<html>
<head>
<title>This is bad HTML</title>
<body>
<h1>Bad HTML
<p>This is a paragraph
</body>
Today's market consists of different browser technologies. Some browsers run on computers, and
some browsers run on mobile phones or other small devices. Smaller devices often lack the
resources or power to interpret "bad" markup.
XML is a markup language where documents must be marked up correctly (be "well-formed").
XHTML Elements
XHTML Attributes
A complete list of all the XHTML Doctypes is found in our HTML Tags Reference.
The <html>, <head>, <title>, and <body> elements must also be present, and the xmlns attribute
in <html> must specify the xml namespace for the document.
<html xmlns="[Link]
<head>
<title>Title of document</title>
</head>
Dr. Md. Sarwar Hosain
Associate Professor
Dept. of ICE, PUST
<body>
some content
</body>
</html>
In XHTML, all elements must be properly nested within each other, like this:
<p>This is a paragraph
<p>This is another paragraph
This is correct:
<p>This is a paragraph</p>
<p>This is another paragraph</p>
A break: <br>
A horizontal rule: <hr>
An image: <img src="[Link]" alt="Happy face">
This is correct:
<BODY>
<P>This is a paragraph</P>
</BODY>
This is correct:
<body>
<p>This is a paragraph</p>
</body>
<table WIDTH="100%">
This is correct:
<table width="100%">
<table width=100%>
This is correct:
<table width="100%">
Wrong:
Correct:
[Link] w w .w [Link]/html/demo_xhtml.asp
<p>
<span>STUDIO X</span> is the best studio ever
</p>
CSS
p {
font-size:12px;
}
span {
font-size:16px;
font-weight:bold;
}