Htmlnotes 150323102005-conversion-gate01

314
Notes By Niraj Bharambe HTML Tutorial - (HTML5 Compliant) With HTML you can create your own Web site. This tutorial teaches you everything about HTML. HTML is easy to learn - You will enjoy it. Examples in Each Chapter This HTML tutorial contains hundreds of HTML examples. Example <!DOCTYPE html> <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> 1

Transcript of Htmlnotes 150323102005-conversion-gate01

Page 1: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Tutorial - (HTML5 Compliant)

With HTML you can create your own Web site.

This tutorial teaches you everything about HTML.

HTML is easy to learn - You will enjoy it.

Examples in Each Chapter

This HTML tutorial contains hundreds of HTML examples.

Example

<!DOCTYPE html><html><body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body></html>

HTML Introduction1

Page 2: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Example

<!DOCTYPE html><html><body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body></html>

Example Explained

The DOCTYPE declaration defines the document type The text between <html> and </html> describes the web page The text between <body> and </body> is the visible page content The text between <h1> and </h1> is displayed as a heading The text between <p> and </p> is displayed as a paragraph

The <!DOCTYPE html> declaration is the doctype for HTML5.

What is HTML?

HTML is a language for describing web pages.

HTML stands for Hyper Text Markup Language HTML is a markup language A markup language is a set of markup tags The tags describe document content HTML documents contain HTML tags and plain text HTML documents are also called web pages

HTML Tags

HTML markup tags are usually called HTML tags

2

Page 3: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML tags are keywords (tag names) surrounded by angle brackets like <html> HTML tags normally come in pairs like <b> and </b> 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, with a forward slash before the tag name Start and end tags are also called opening tags and closing tags

<tagname>content</tagname>

HTML Elements

"HTML tags" and "HTML elements" are often used to describe the same thing.

But strictly speaking, an HTML element is everything between the start tag and the end tag, including the tags:

HTML Element:

<p>This is a paragraph.</p>

Web Browsers

The purpose of a web browser (such as Google Chrome, Internet Explorer, Firefox, Safari) is to read HTML documents and display them as web pages.

The browser does not display the HTML tags, but uses the tags to determine how the content of the HTML page is to be presented/displayed to the user:

3

Page 4: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Page Structure

Below is a visualization of an HTML page structure:

<html>

<body>

<h1>This a heading</h1>

<p>This is a paragraph.</p>

<p>This is another paragraph.</p>

</body>

</html>

4

Page 5: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Versions

Since the early days of the web, there have been many versions of HTML:

Version Year

HTML 1991

HTML+ 1993

HTML 2.0 1995

HTML 3.2 1997

HTML 4.01 1999

XHTML 1.0 2000

HTML5 2012

XHTML5 2013

The <!DOCTYPE> Declaration

The <!DOCTYPE> declaration helps the browser to display a web page correctly.

There are many different documents on the web, and a browser can only display an HTML page 100% correctly if it knows the HTML type and version used.

Common DeclarationsHTML5<!DOCTYPE html>

HTML 4.01<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">

5

Page 6: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

XHTML 1.0<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

6

Page 7: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Editors

Writing HTML Using Notepad or TextEdit

HTML can be edited by using a professional HTML editor like:

Adobe Dreamweaver Microsoft Expression Web CoffeeCup HTML Editor

However, for learning HTML we recommend a text editor like Notepad (PC) or TextEdit (Mac). We believe using a simple text editor is a good way to learn HTML.

Follow the 4 steps below to create your first web page with Notepad.

Step 1: Start Notepad

To start Notepad go to:

Start    All Programs        Accessories            Notepad

Step 2: Edit Your HTML with Notepad

Type your HTML code into your Notepad:

7

Page 8: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Step 3: Save Your HTML

Select Save as.. in Notepad's file menu.

When you save an HTML file, you can use either the .htm or the .html file extension. There is no difference, it is entirely up to you.

Save the file in a folder that is easy to remember, like w3schools.

Step 4: Run the HTML in Your Browser

Start your web browser and open your html file from the File, Open menu, or just browse the folder and double-click your HTML file.

The result should look much like this:

8

Page 9: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Basic - 4 Examples

Don't worry if the examples use tags you have not learned.

You will learn about them in the next chapters.

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="http://www.w3schools.com">This is a link</a>

Note: The link address is specified in the href attribute.

(You will learn about attributes in a later chapter of this tutorial).

9

Page 10: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Images

HTML images are defined with the <img> tag.

Example

<img src="w3schools.jpg" width="104" height="142">

Note: The filename and the size of the image are provided as attributes.

10

Page 11: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Elements

HTML documents are defined by HTML elements.

HTML Elements

An HTML element is everything from the start tag to the end tag:

Start tag * Element content End tag *

<p> This is a paragraph </p>

<a href="default.htm"> This is a link </a>

<br>

* The start tag is often called the opening tag. The end tag is often called the closing tag.

HTML Element Syntax

An HTML element starts with a start tag / opening tag An HTML element ends with an end tag / closing tag The element content is everything between the start and the end tag Some HTML elements have empty content Empty elements are closed in the start tag Most HTML elements can have attributes

Tip: You will learn about attributes in the next chapter of this tutorial.

Nested HTML Elements

Most HTML elements can be nested (can contain other HTML elements).

HTML documents consist of nested HTML elements.

11

Page 12: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Document Example<!DOCTYPE html><html>

<body><p>This is my first paragraph.</p></body>

</html>

The example above contains 3 HTML elements.

HTML Example Explained

The <p> element:

<p>This is my first paragraph.</p>

The <p> element defines a paragraph in the HTML document.The element has a start tag <p> and an end tag </p>.The element content is: This is my first paragraph.

The <body> element:

<body><p>This is my first paragraph.</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 (a p element).

The <html> element:

<html>

<body><p>This is my first paragraph.</p></body>

</html>

The <html> element defines the whole HTML document.The element has a start tag <html> and an end tag </html>.The element content is another HTML element (the body element).

Don't Forget the End Tag12

Page 13: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Some HTML elements might display correctly even if you forget the end tag:

<p>This is a paragraph<p>This is a paragraph

The example above works in most browsers, because the closing tag is considered optional.

Never rely on this. Many HTML elements will produce unexpected results and/or errors if you forget the end tag .

Empty HTML Elements

HTML elements with no content are called empty elements.

<br> is an empty element without a closing tag (the <br> tag defines a line break).

Tip: In XHTML, all elements must be closed. Adding a slash inside the start tag, like <br />, is the proper way of closing empty elements in XHTML (and XML).

HTML Tip: Use Lowercase Tags

HTML tags are not case sensitive: <P> means the same as <p>. Many web sites use uppercase HTML tags.

W3Schools use lowercase tags because the World Wide Web Consortium (W3C) recommends lowercase in HTML 4, and demands lowercase tags in XHTML.

HTML Attributes

13

Page 14: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Attributes provide additional information about HTML elements.

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"

Attribute ExampleHTML links are defined with the <a> tag. The link address is specified in the href attribute:

Example

<a href="http://www.w3schools.com">This is a link</a>

Always Quote Attribute Values

Attribute values should always be enclosed in quotes.

Double style quotes are the most common, but single style quotes are also allowed.

Tip: In some rare situations, when the attribute value itself contains quotes, it is necessary to use single quotes: name='John "ShotGun" Nelson'

HTML Tip: Use Lowercase Attributes

Attribute names and attribute values are case-insensitive.

However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4 recommendation.

Newer versions of (X)HTML will demand lowercase attributes.

HTML Attributes Reference

A complete list of legal attributes for each HTML element is listed in our: HTML Tag Reference.

14

Page 15: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Below is a list of some attributes that can be used on any HTML element:

Attribute Description

class Specifies one or more classnames for an element (refers to a class in a style sheet)

id Specifies a unique id for an element

style Specifies an inline CSS style for an element

title Specifies extra information about an element (displayed as a tool tip)

For more information about global attributes: HTML Global Attributes Reference.

HTML Headings

15

Page 16: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Headings are important in HTML documents.

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.

Headings Are Important

Use HTML headings for headings only. Don't use headings to make text BIG or bold.

Search engines use your headings to index the structure and content of your web pages.

Since users may skim your pages by its headings, it is important to use headings to show the document structure.

H1 headings should be used as main headings, followed by H2 headings, then the less important H3 headings, and so on.

HTML Lines

The <hr>tag creates a horizontal line in an HTML page.

The hr element can be used to separate content:

Example

<p>This is a paragraph.</p><hr><p>This is a paragraph.</p><hr><p>This is a paragraph.</p>

16

Page 17: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Comments

Comments can be inserted into the HTML code to make it more readable and understandable. Comments are ignored by the browser and are not displayed.

Comments are written like this:

Example

<!-- This is a comment -->

Note: There is an exclamation point after the opening bracket, but not before the closing bracket.

HTML Tip - How to View HTML Source

Have you ever seen a Web page and wondered "Hey! How did they do that?"

To find out, right-click in the page and select "View Source" (IE) or "View Page Source" (Firefox), or similar for other browsers. This will open a window containing the HTML code of the page.

Examples From This Page

HeadingsHow to display headings in an HTML document.

Hidden commentsHow to insert comments in the HTML source code.

Horizontal linesHow to insert a horizontal line.

HTML Tag Reference

W3Schools' tag reference contains additional information about these tags and their attributes.

You will learn more about HTML tags and attributes in the next chapters of this tutorial.

17

Page 18: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Tag Description

<html> Defines an HTML document

<body> Defines the document's body

<h1> to <h6> Defines HTML headings

<hr> Defines a horizontal line

<!--> Defines a comment

HTML Paragraphs

HTML documents are divided into paragraphs.

18

Page 19: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Paragraphs

Paragraphs are defined with the <p> tag.

Example

<p>This is a paragraph</p><p>This is another paragraph</p>

Note: Browsers automatically add an empty line before and after a paragraph.

Don't Forget the End Tag

Most browsers will display HTML correctly even if you forget the end tag:

Example

<p>This is a paragraph<p>This is another paragraph

The example above will work in most browsers, but don't rely on it. Forgetting the end tag can produce unexpected results or errors.

Note: Future version of HTML will not allow you to skip end tags.

HTML Line Breaks

Use the <br> tag if you want a line break (a new line) without starting a new paragraph:

Example

<p>This is<br>a para<br>graph with line breaks</p>

The <br> element is an empty HTML element. It has no end tag.

HTML Output - Useful Tips

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.

19

Page 20: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The browser will remove extra spaces and extra lines when the page is displayed. Any number of lines count as one line, and any number of spaces count as one space.

Try it yourself

(The example demonstrates some HTML formatting problems)

Examples from this page

HTML paragraphsHow HTML paragraphs are displayed in a browser.

Line breaksThe use of line breaks in an HTML document.

Poem problemsSome problems with HTML formatting.

More Examples

More paragraphsThe default behaviors of paragraphs.

HTML Tag Reference

W3Schools' tag reference contains additional information about HTML elements and their attributes.

Tag Description

20

Page 21: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<p> Defines a paragraph

<br> Inserts a single line break

HTML Text Formatting

HTML Text Formatting

This text is bold

21

Page 22: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

This text is italic

This is computer output

This is subscript and superscript

HTML Formatting Tags

HTML uses tags like <b> and <i> for formatting output, like bold or italic text.

These HTML tags are called formatting tags (look at the bottom of this page for a complete reference).

Often <strong> renders as <b>, and <em> renders as <i>.

However, there is a difference in the meaning of these tags:

<b> or <i> defines bold or italic text only.

<strong> or <em> means that you want the text to be rendered in a way that the user understands as "important". Today, all major browsers render strong as bold and em as italics. However, if a browser one day wants to make a text highlighted with the strong feature, it might be cursive for example and not bold!

Try it Yourself - Examples

Text formattingHow to format text in an HTML document.

Preformatted textHow to control the line breaks and spaces with the pre tag.

"Computer output" tagsHow different "computer output" tags will be displayed.

AddressHow to define contact information for the author/owner of an HTML document.

Abbreviations and acronymsHow to handle abbreviations and acronyms.

22

Page 23: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Text directionHow to change the text direction.

QuotationsHow to handle long and short quotations.

Deleted and inserted textHow to mark deleted and inserted text.

Marked/Highlighted textHow to mark/highlight text.  

HTML Text Formatting TagsTag Description

<b> Defines bold text

<em> Defines emphasized text

<i> Defines a part of text in an alternate voice or mood

<small> Defines smaller text

<strong> Defines important text

<sub> Defines subscripted text

<sup> Defines superscripted text

<ins> Defines inserted text

<del> Defines deleted text

<mark> Defines marked/highlighted text

HTML "Computer Output" TagsTag Description

23

Page 24: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<code> Defines computer code text

<kbd> Defines keyboard text

<samp> Defines sample computer code

<var> Defines a variable

<pre> Defines preformatted text

HTML Citations, Quotations, and Definition TagsTag Description

<abbr> Defines an abbreviation or acronym

<address> Defines contact information for the author/owner of a document

<bdo> Defines the text direction

<blockquote> Defines a section that is quoted from another source

<q> Defines an inline (short) quotation

<cite> Defines the title of a work

<dfn> Defines a definition term

HTML Links

24

Page 25: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Links are found in nearly all Web pages. Links allow users to click their way from page to page.

Try it Yourself - Examples

HTML linksHow to create links in an HTML document.

(You can find more examples at the bottom of this page)

HTML Hyperlinks (Links)

The HTML <a> tag defines a hyperlink.

A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another document.

When you move the cursor over a link in a Web page, the arrow will turn into a little hand.

The most important attribute of the <a> element is the href attribute, which indicates the link’s destination.

By default, links will appear as follows in all browsers:

An unvisited link is underlined and blue A visited link is underlined and purple An active link is underlined and red

HTML Link Syntax

The HTML code for a link is simple. It looks like this:

<a href="url">Link text</a>

The href attribute specifies the destination of a link.

Example<a href="http://www.w3schools.com/">Visit W3Schools</a>

25

Page 26: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

which will display like this: Visit W3Schools

Clicking on this hyperlink will send the user to W3Schools' homepage.

Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element.

HTML Links - The target Attribute

The target attribute specifies where to open the linked document.

The example below will open the linked document in a new browser window or a new tab:

Example

<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>

HTML Links - The id Attribute

The id attribute can be used to create a bookmark inside an HTML document.

Tip: Bookmarks are not displayed in any special way. They are invisible to the reader.

Example

An anchor with an id inside an HTML document:

<a id="tips">Useful Tips Section</a>

Create a link to the "Useful Tips Section" inside the same document:

<a href="#tips">Visit the Useful Tips Section</a>

Or, create a link to the "Useful Tips Section" from another page:

<a href="http://www.w3schools.com/html_links.htm#tips">Visit the Useful Tips Section</a>

Basic Notes - Useful Tips

Note: Always add a trailing slash to subfolder references. If you link like this: href="http://www.w3schools.com/html", you will generate two requests to the server, the server will

26

Page 27: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

first add a slash to the address, and then create a new request like this: href="http://www.w3schools.com/html/".

More Examples

An image as a linkHow to use an image as a link.

Link to a location on the same pageHow to link to a bookmark.

Break out of a frameHow to break out of a frame (if your site is locked in a frame).

Create a mailto linkHow to link to a mail message (will only work if you have mail installed).

Create a mailto link 2Another mailto link.

HTML Link TagsTag Description

<a> Defines a hyperlink

HTML <head>

27

Page 28: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Try it Yourself - Examples

<title> - Define a title for an HTML documentUse the <title> tag to define a title for a document.

<base> - Default URL and target for all linksUse the <base> tag to specify a default URL and a default target for all links on a page.

<meta> - Provide metadata for an HTML documentUse <meta> elements to specify a description, keywords, author, and character set of a document.

The HTML <head> Element

The <head> element is a container for all the head elements. Elements inside <head> can include scripts, instruct the browser where to find style sheets, provide meta information, and more.

The following tags can be added to the head section: <title>, <style>, <meta>, <link>, <script>, <noscript>, and <base>.

The HTML <title> Element

The <title> tag defines the title of the document.

The <title> element is required in all HTML/XHTML documents.

The <title> element:

defines a title in the browser toolbar provides a title for the page when it is added to favorites displays a title for the page in search-engine results

A simplified HTML document:

<!DOCTYPE html><html><head><title>Title of the document</title></head>

<body>The content of the document......</body>

28

Page 29: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

</html>

The HTML <base> Element

The <base> tag specifies the base URL/target for all relative URLs in a page:

<head><base href="http://www.w3schools.com/images/" target="_blank"></head>

The HTML <link> Element

The <link> tag defines the relationship between a document and an external resource.

The <link> tag is most used to link to style sheets:

<head><link rel="stylesheet" type="text/css" href="mystyle.css"></head>

The HTML <style> Element

The <style> tag is used to define style information for an HTML document.

Inside the <style> element you specify how HTML elements should render in a browser:

<head><style type="text/css">body {background-color:yellow}p {color:blue}</style></head>

The HTML <meta> Element

Metadata is data (information) about data.

29

Page 30: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The <meta> tag provides metadata about the HTML document. Metadata will not be displayed on the page, but will be machine parsable.

Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata.

The metadata can be used by browsers (how to display content or reload page), search engines (keywords), or other web services.

<meta> tags always go inside the <head> element.

<meta> Tags - Examples of Use

Define keywords for search engines:

<meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript">

Define a description of your web page:

<meta name="description" content="Free Web tutorials on HTML and CSS">

Define the author of a page:

<meta name="author" content="Hege Refsnes">

Refresh document every 30 seconds:

<meta http-equiv="refresh" content="30">

The HTML <script> Element

The <script> tag is used to define a client-side script, such as a JavaScript.

The <script> element will be explained in a later chapter.

HTML head ElementsTag Description

30

Page 31: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<head> Defines information about the document

<title> Defines the title of a document

<base> Defines a default address or a default target for all links on a page

<link> Defines the relationship between a document and an external resource

<meta> Defines metadata about an HTML document

<script> Defines a client-side script

<style> Defines style information for a document

HTML Styles - CSS

31

Page 32: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

CSS (Cascading Style Sheets) is used to style HTML elements.

Look! Styles and colorsM a n i p u l a t e T e x tC o l o r s ,     B o x e sand more...

Try it Yourself - Examples

Using styles in HTMLHow to add style information inside the <head> section.

Link that is not underlinedHow to make a link that is not underlined, with the style attribute.

Link to an external style sheetHow to use the <link> tag to link to an external style sheet.

Styling HTML with CSS

CSS was introduced together with HTML 4, to provide a better way to style HTML elements.

CSS can be added to HTML in the following ways:

Inline - using the style attribute in HTML elements Internal - using the <style> element in the <head> section External - using an external CSS file

The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files.

However, in this HTML tutorial we will introduce you to CSS using the style attribute. This is done to simplify the examples. It also makes it easier for you to edit the code and try it yourself.

You can learn everything about CSS in our CSS Tutorial.

Inline Styles

An inline style can be used if a unique style is to be applied to one single occurrence of an element.

32

Page 33: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

To use inline styles, use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example below shows how to change the text color and the left margin of a paragraph:

<p style="color:blue;margin-left:20px;">This is a paragraph.</p>

To learn more about style sheets, visit our CSS tutorial.

HTML Style Example - Background Color

The background-color property defines the background color for an element:

Example

<!DOCTYPE html><html>

<body style="background-color:yellow;"><h2 style="background-color:red;">This is a heading</h2><p style="background-color:green;">This is a paragraph.</p></body>

</html>

The background-color property makes the "old" bgcolor attribute obsolete.

Try it yourself: Background color the old way

HTML Style Example - Font, Color and Size

The font-family, color, and font-size properties defines the font, color, and size of the text in an element:

Example

<!DOCTYPE html><html>

<body><h1 style="font-family:verdana;">A heading</h1><p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p></body>

</html>

The font-family, color, and font-size properties make the old <font> tag obsolete.

33

Page 34: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Style Example - Text Alignment

The text-align property specifies the horizontal alignment of text in an element:

Example

<!DOCTYPE html><html>

<body><h1 style="text-align:center;">Center-aligned heading</h1><p>This is a paragraph.</p></body>

</html>

The text-align property makes the old <center> tag obsolete.

Try it yourself: Centered heading the old way

Internal Style Sheet

An internal style sheet can be used if one single document has a unique style. Internal styles are defined in the <head> section of an HTML page, by using the <style> tag, like this:

<head><style type="text/css">body {background-color:yellow;}p {color:blue;}</style></head>

External Style Sheet

An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the <head> section:

<head><link rel="stylesheet" type="text/css" href="mystyle.css"></head>

HTML Style TagsTag Description

34

Page 35: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<style> Defines style information for a document

<link> Defines the relationship between a document and an external resource

Deprecated Tags and Attributes

In HTML 4, several tags and attributes were used to style documents. These tags are not supported in newer versions of HTML.

Avoid using the elements: <font>, <center>, and <strike>, and the attributes: color and bgcolor.

HTML Images

Example

35

Page 36: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Norwegian Mountain Trip

Try it Yourself - Examples

Insert imagesHow to insert images into an HTML document.

Insert images from different locationsHow to insert an image from another folder or another server.

(You can find more examples at the bottom of this page).

HTML Images - The <img> Tag and the Src Attribute

In HTML, images are defined with the <img> tag. 

The <img> tag is empty, which means that it contains attributes only, and has no closing tag.

To display an image on a page, you need to use the src attribute. Src stands for "source". The value of the src attribute is the URL of the image you want to display.

Syntax for defining an image:

<img src="url" alt="some_text">

36

Page 37: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The URL points to the location where the image is stored. An image named "boat.gif", located in the "images" directory on "www.w3schools.com" has the URL: http://www.w3schools.com/images/boat.gif.

The browser displays the image where the <img> tag occurs in the document. If you put an image tag between two paragraphs, the browser shows the first paragraph, then the image, and then the second paragraph.

HTML Images - The Alt Attribute

The required alt attribute specifies an alternate text for an image, if the image cannot be displayed.

The value of the alt attribute is an author-defined text:

<img src="boat.gif" alt="Big Boat">

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).

HTML Images - Set Height and Width of an Image

The height and width attributes are used to specify the height and width of an image.

The attribute values are specified in pixels by default:

<img src="pulpit.jpg" alt="Pulpit rock" width="304" height="228">

Tip: It is a good practice to specify both the height and width attributes for an image. If these attributes are set, the space required for the image is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the image. The effect will be that the page layout will change during loading (while the images load).

Basic Notes - Useful Tips

Note: If an HTML file contains ten images - eleven files are required to display the page right. Loading images takes time, so my best advice is: Use images carefully.

Note: When a web page is loaded, it is the browser, at that moment, that actually gets the image from a web server and inserts it into the page. Therefore, make sure that the images actually stay in the same spot in relation to the web page, otherwise your visitors will get a broken link icon. The broken link icon is shown if the browser cannot find the image.

37

Page 38: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

More Examples

Aligning imagesHow to align an image within the text.

Let an image float to the left and to the rightHow to let an image float to the left or right of a paragraph.

Make a hyperlink of an imageHow to use an image as a link.

Create an image mapHow to create an image map, with clickable regions. Each region is a hyperlink.

HTML Image TagsTag Description

<img> Defines an image

<map> Defines an image-map

<area> Defines a clickable area inside an image-map

HTML Tables

HTML Table Example:

38

Page 39: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

First Name Last Name Points

Jill Smith 50

Eve Jackson 94

John Doe 80

Adam Johnson 67

Try it Yourself - Examples

TablesHow to create tables in an HTML document.

(You can find more examples at the bottom of this page).

HTML Tables

Tables are defined with the <table> tag.

A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). td stands for "table data," and holds the content of a data cell. A <td> tag can contain text, links, images, lists, forms, other tables, etc.

Table Example<table border="1"><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>

39

Page 40: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

How the HTML code above looks in a browser:

row 1, cell 1 row 1, cell 2

row 2, cell 1 row 2, cell 2

HTML Tables and the Border Attribute

If you do not specify a border attribute, the table will be displayed without borders. Sometimes this can be useful, but most of the time, we want the borders to show.

To display a table with borders, specify the border attribute:

<table border="1"><tr><td>Row 1, cell 1</td><td>Row 1, cell 2</td></tr></table>

HTML Table Headers

Header information in a table are defined with the <th> tag.

All major browsers display the text in the <th> element as bold and centered.

<table border="1"><tr><th>Header 1</th><th>Header 2</th></tr><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table>

40

Page 41: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

How the HTML code above looks in your browser:

Header 1 Header 2

row 1, cell 1 row 1, cell 2

row 2, cell 1 row 2, cell 2

More Examples

Tables without bordersHow to create tables without borders.

Table headersHow to create table headers.

Table with a captionHow to add a caption to a table.

Table cells that span more than one row/columnHow to define table cells that span more than one row or one column.

Tags inside a tableHow to display elements inside other elements.

Cell paddingHow to use cellpadding to create more white space between the cell content and its borders.

Cell spacingHow to use cellspacing to increase the distance between the cells.

HTML Table TagsTag Description

<table> Defines a table

<th> Defines a header cell in a table

41

Page 42: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<tr> Defines a row in a table

<td> Defines a cell in a table

<caption> Defines a table caption

<colgroup> Specifies a group of one or more columns in a table for formatting

<col> Specifies column properties for each column within a <colgroup> element

<thead> Groups the header content in a table

<tbody> Groups the body content in a table

<tfoot> Groups the footer content in a table

HTML Lists

The most common HTML lists are ordered and unordered lists:

HTML Lists

42

Page 43: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

An ordered list:

1. The first list item2. The second list item3. The third list item

An unordered list:

List item List item List item

Try-It-Yourself Examples

Unordered listHow to create an unordered list in an HTML document.

Ordered listHow to create an ordered list in an HTML document.

(You can find more examples at the bottom of this page).

HTML Unordered Lists

An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.

The list items are marked with bullets (typically small black circles).

<ul><li>Coffee</li><li>Milk</li></ul>

How the HTML code above looks in a browser:

Coffee Milk

HTML Ordered Lists

An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.

The list items are marked with numbers.

<ol><li>Coffee</li>

43

Page 44: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<li>Milk</li></ol>

How the HTML code above looks in a browser:

1. Coffee2. Milk

HTML Description Lists

A description list is a list of terms/names, with a description of each term/name.

The <dl> tag defines a description list.

The <dl> tag is used in conjunction with <dt> (defines terms/names) and <dd> (describes each term/name):

<dl><dt>Coffee</dt><dd>- black hot drink</dd><dt>Milk</dt><dd>- white cold drink</dd></dl>

How the HTML code above looks in a browser:

Coffee

- black hot drink

Milk

- white cold drink

Basic Notes - Useful Tips

Tip: Inside a list item you can put text, line breaks, images, links, other lists, etc.

44

Page 45: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

More Examples

Different types of ordered listsDemonstrates different types of ordered lists.

Different types of unordered listsDemonstrates different types of unordered lists.

Nested listDemonstrates how you can nest lists.

Nested list 2Demonstrates a more complicated nested list.

Description listDemonstrates a definition list.

HTML List TagsTag Description

<ol> Defines an ordered list

<ul> Defines an unordered list

<li> Defines a list item

<dl> Defines a description list

<dt> Defines a term/name in a description list

<dd> Defines a description of a term/name in a description list

HTML <div> and <span>

HTML elements can be grouped together with <div> and <span>.

45

Page 46: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Block Elements

Most HTML elements are defined as block level elements or as inline elements.

Block level elements normally start (and end) with a new line when displayed in a browser.

Examples: <h1>, <p>, <ul>, <table>

HTML Inline Elements

Inline elements are normally displayed without starting a new line.

Examples: <b>, <td>, <a>, <img>

The HTML <div> Element

The HTML <div> element is a block level element that can be used as a container for grouping other HTML elements.

 The <div> element has no special meaning. Except that, because it is a block level element, the browser will display a line break before and after it.

When used together with CSS, the <div> element can be used to set style attributes to large blocks of content.

Another common use of the <div>element, is for document layout. It replaces the "old way" of defining layout using tables. Using <table> elements for layout is not the correct use of <table>. The purpose of the <table> element is to display tabular data.

The HTML <span> Element

The HTML <span> element is an inline element that can be used as a container for text.

The <span> element has no special meaning.

When used together with CSS, the <span> element can be used to set style attributes to parts of the text.

46

Page 47: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Grouping TagsTag Description

<div> Defines a section in a document (block-level)

<span> Defines a section in a document (inline)

HTML Layouts

Web page layout is very important to make your website look good.

47

Page 48: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Design your webpage layout very carefully.

Try it Yourself - Examples

Web page layout using <div> elementsHow to add layout using <div> elements.

Web page layout using <table> elementsHow to add layout using <table> elements.

Website Layouts

Most websites have put their content in multiple columns (formatted like a magazine or newspaper).

Multiple columns are created by using <div> or <table> elements. CSS are used to position elements, or to create backgrounds or colorful look for the pages.

Even though it is possible to create nice layouts with HTML tables, tables were designed for presenting tabular data - NOT as a layout tool!

HTML Layouts - Using <div> Elements

The div element is a block level element used for grouping HTML elements.

The following example uses five div elements to create a multiple column layout, creating the same result as in the previous example:

Example

<!DOCTYPE html><html><body>

<div id="container" style="width:500px">

48

Page 49: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<div id="header" style="background-color:#FFA500;"><h1 style="margin-bottom:0;">Main Title of Web Page</h1></div>

<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;"><b>Menu</b><br>HTML<br>CSS<br>JavaScript</div>

<div id="content" style="background-color:#EEEEEE;height:200px;width:400px;float:left;">Content goes here</div>

<div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">WEB PAGE DESIGN</div>

</div>

</body></html>

The HTML code above will produce the following result:

Main Title of Web PageMenuHTMLCSSJavaScript

Content goes here

WEB PAGE DESIGN

HTML Layouts - Using Tables

A simple way of creating layouts is by using the HTML <table> tag.

Multiple columns are created by using <div> or <table> elements. CSS are used to position elements, or to create backgrounds or colorful look for the pages.

49

Page 50: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Using <table> to create a nice layout is NOT the correct use of the element. The purpose of the <table> element is to display tabular data!

The following example uses a table with 3 rows and 2 columns - the first and last row spans both columns using the colspan attribute:

Example

<!DOCTYPE html><html><body>

<table width="500" border="0"><tr><td colspan="2" style="background-color:#FFA500;"><h1>Main Title of Web Page</h1></td></tr>

<tr><td style="background-color:#FFD700;width:100px;"><b>Menu</b><br>HTML<br>CSS<br>JavaScript</td><td style="background-color:#EEEEEE;height:200px;width:400px;">Content goes here</td></tr>

<tr><td colspan="2" style="background-color:#FFA500;text-align:center;">Copyright © W3Schools.com</td></tr></table>

</body></html>

The HTML code above will produce the following result:

Main Title of Web PageMenuHTMLCSS

Content goes here

50

Page 51: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

JavaScript

Copyright © W3Schools.com

HTML Layout - Useful Tips

Tip: The biggest advantage of using CSS is that, if you place the CSS code in an external style sheet, your site becomes MUCH EASIER to maintain. You can change the layout of all your pages by editing one file. To learn more about CSS, study our CSS tutorial.

Tip: Because advanced layouts take time to create, a quicker option is to use a template. Search Google for free website templates (these are pre-built website layouts you can use and customize).

HTML Layout TagsTag Description

<div> Defines a section in a document (block-level)

<span> Defines a section in a document (inline)

HTML Forms and Input

HTML Forms are used to select different kinds of user input.

51

Page 52: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Try it Yourself - Examples

Create text fieldsHow to create text fields. The user can write text in a text field.

Create password fieldHow to create a password field.

(You can find more examples at the bottom of this page)

HTML Forms

HTML forms are used to pass data to a server.

An HTML form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements.

The <form> tag is used to create an HTML form:

<form>.input elements.</form>

HTML Forms - The Input Element

The most important form element is the <input> element.

The <input> element is used to select user information.

An <input> element can vary in many ways, depending on the type attribute. An <input> element can be of type text field, checkbox, password, radio button, submit button, and more.

The most common input types are described below.

52

Page 53: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Text Fields

<input type="text"> defines a one-line input field that a user can enter text into:

<form>First name: <input type="text" name="firstname"><br>Last name: <input type="text" name="lastname"></form>

How the HTML code above looks in a browser:

First name: 

Last name: 

Note: The form itself is not visible. Also note that the default width of a text field is 20 characters. 

Password Field

<input type="password"> defines a password field:

<form>Password: <input type="password" name="pwd"></form>

How the HTML code above looks in a browser:

Password: 

Note: The characters in a password field are masked (shown as asterisks or circles).

Radio Buttons

<input type="radio"> defines a radio button. Radio buttons let a user select ONLY ONE of a limited number of choices:

<form><input type="radio" name="sex" value="male">Male<br><input type="radio" name="sex" value="female">Female</form>

How the HTML code above looks in a browser:

53

Page 54: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Male

Female

Checkboxes

<input type="checkbox"> defines a checkbox. Checkboxes let a user select ZERO or MORE options of a limited number of choices.

<form><input type="checkbox" name="vehicle" value="Bike">I have a bike<br><input type="checkbox" name="vehicle" value="Car">I have a car </form>

How the HTML code above looks in a browser:

I have a bike

I have a car

Submit Button

<input type="submit"> defines a submit button.

A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input:

<form name="input" action="html_form_action.asp" method="get">Username: <input type="text" name="user"><input type="submit" value="Submit"></form>

How the HTML code above looks in a browser:

Username: 

If you type some characters in the text field above, and click the "Submit" button, the browser will send your input to a page called "html_form_action.asp". The page will show you the received input.

54

Submit

Page 55: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

 More Input Examples

Radio buttonsHow to create radio buttons.

CheckboxesHow to create checkboxes. A user can select or unselect a checkbox.

Simple drop-down listHow to create a simple drop-down list.

Drop-down list with a pre-selected valueHow to create a drop-down list with a pre-selected value.

TextareaHow to create a multi-line text input control. In a text-area the user can write an unlimited number of characters.

Create a buttonHow to create a button.

 Form Examples

Fieldset around form-dataHow to create a border around elements in a form.

Form with text fields and a submit buttonHow to create a form with two text fields and a submit button.

Form with checkboxesHow to create a form with two checkboxes and a submit button.

Form with radio buttonsHow to create a form with two radio buttons, and a submit button.

Send e-mail from a formHow to send e-mail from a form.

HTML Form Tags

New : New tags in HTML5.

55

Page 56: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Tag Description

<form> Defines an HTML form for user input

<input> Defines an input control

<textarea> Defines a multiline input control (text area)

<label> Defines a label for an <input> element

<fieldset> Groups related elements in a form

<legend> Defines a caption for a <fieldset> element

<select> Defines a drop-down list

<optgroup> Defines a group of related options in a drop-down list

<option> Defines an option in a drop-down list

<button> Defines a clickable button

<datalist>New Specifies a list of pre-defined options for input controls

<keygen>New Defines a key-pair generator field (for forms)

<output>New Defines the result of a calculation

HTML Iframes

56

Page 57: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

An iframe is used to display a web page within a web page.

Syntax for adding an iframe:

<iframe src="URL"></iframe>

The URL points to the location of the separate page.

Iframe - Set Height and Width

The height and width attributes are used to specify the height and width of the iframe.

The attribute values are specified in pixels by default, but they can also be in percent (like "80%").

Example

<iframe src="demo_iframe.htm" width="200" height="200"></iframe>

Iframe - Remove the Border

The frameborder attribute specifies whether or not to display a border around the iframe.

Set the attribute value to "0" to remove the border:

Example

<iframe src="demo_iframe.htm" frameborder="0"></iframe>

Use iframe as a Target for a Link

An iframe can be used as the target frame for a link.

The target attribute of a link must refer to the name attribute of the iframe:

Example

57

Page 58: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<iframe src="demo_iframe.htm" name="iframe_a"></iframe><p><a href="http://www.w3schools.com" target="iframe_a">W3Schools.com</a></p>

HTML iframe TagTag Description

<iframe> Defines an inline frame

HTML Colors

58

Page 59: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Colors are displayed combining RED, GREEN, and BLUE light.

Color Values

HTML colors are defined using a hexadecimal notation (HEX) for the combination of Red, Green, and Blue color values (RGB).

The lowest value that can be given to one of the light sources is 0 (in HEX: 00). The highest value is 255 (in HEX: FF).

HEX values are specified as 3 pairs of two-digit numbers, starting with a # sign.

Color Values

Color Color HEX Color RGB

#000000 rgb(0,0,0)

#FF0000 rgb(255,0,0)

#00FF00 rgb(0,255,0)

#0000FF rgb(0,0,255)

#FFFF00 rgb(255,255,0)

#00FFFF rgb(0,255,255)

#FF00FF rgb(255,0,255)

#C0C0C0 rgb(192,192,192)

#FFFFFF rgb(255,255,255)

16 Million Different Colors

59

Page 60: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The combination of Red, Green, and Blue values from 0 to 255, gives more than 16 million different colors (256 x 256 x 256).

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 the full list of color mixes when RED varies from 0 to 255, click on one of the HEX or RGB values below.

Red Light Color HEX Color 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)

60

Page 61: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

#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)

61

Page 62: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Shades of Gray

Gray colors are created by using an equal amount of power to all of the light sources.

To make it easier for you to select the correct shade, we have created a table of gray shades for you:

Gray Shades Color HEX Color RGB

#000000 rgb(0,0,0)

#080808 rgb(8,8,8)

#101010 rgb(16,16,16)

#181818 rgb(24,24,24)

#202020 rgb(32,32,32)

#282828 rgb(40,40,40)

#303030 rgb(48,48,48)

#383838 rgb(56,56,56)

#404040 rgb(64,64,64)

#484848 rgb(72,72,72)

#505050 rgb(80,80,80)

#585858 rgb(88,88,88)

#606060 rgb(96,96,96)

#686868 rgb(104,104,104)

#707070 rgb(112,112,112)

#787878 rgb(120,120,120)

62

Page 63: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

#808080 rgb(128,128,128)

#888888 rgb(136,136,136)

#909090 rgb(144,144,144)

#989898 rgb(152,152,152)

#A0A0A0 rgb(160,160,160)

#A8A8A8 rgb(168,168,168)

#B0B0B0 rgb(176,176,176)

#B8B8B8 rgb(184,184,184)

#C0C0C0 rgb(192,192,192)

#C8C8C8 rgb(200,200,200)

#D0D0D0 rgb(208,208,208)

#D8D8D8 rgb(216,216,216)

#E0E0E0 rgb(224,224,224)

#E8E8E8 rgb(232,232,232)

#F0F0F0 rgb(240,240,240)

#F8F8F8 rgb(248,248,248)

#FFFFFF rgb(255,255,255)

Web Safe Colors?

63

Page 64: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Some years ago, when computers supported max 256 different colors, a list of 216 "Web Safe Colors" was suggested as a Web standard, reserving 40 fixed system colors.

The 216 cross-browser color palette was created to ensure that all computers would display the colors correctly when running a 256 color palette.

This is not important today, since most computers can display millions of different colors. Anyway, here is the list:

000000 000033 000066 000099 0000CC 0000FF

003300 003333 003366 003399 0033CC 0033FF

006600 006633 006666 006699 0066CC 0066FF

009900 009933 009966 009999 0099CC 0099FF

00CC00 00CC33 00CC66 00CC99 00CCCC 00CCFF

00FF00 00FF33 00FF66 00FF99 00FFCC 00FFFF

330000 330033 330066 330099 3300CC 3300FF

333300 333333 333366 333399 3333CC 3333FF

336600 336633 336666 336699 3366CC 3366FF

339900 339933 339966 339999 3399CC 3399FF

33CC00 33CC33 33CC66 33CC99 33CCCC 33CCFF

33FF00 33FF33 33FF66 33FF99 33FFCC 33FFFF

660000 660033 660066 660099 6600CC 6600FF

663300 663333 663366 663399 6633CC 6633FF

666600 666633 666666 666699 6666CC 6666FF

669900 669933 669966 669999 6699CC 6699FF

66CC00 66CC33 66CC66 66CC99 66CCCC 66CCFF

66FF00 66FF33 66FF66 66FF99 66FFCC 66FFFF

990000 990033 990066 990099 9900CC 9900FF

993300 993333 993366 993399 9933CC 9933FF

996600 996633 996666 996699 9966CC 9966FF

64

Page 65: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

999900 999933 999966 999999 9999CC 9999FF

99CC00 99CC33 99CC66 99CC99 99CCCC 99CCFF

99FF00 99FF33 99FF66 99FF99 99FFCC 99FFFF

CC0000 CC0033 CC0066 CC0099 CC00CC CC00FF

CC3300 CC3333 CC3366 CC3399 CC33CC CC33FF

CC6600 CC6633 CC6666 CC6699 CC66CC CC66FF

CC9900 CC9933 CC9966 CC9999 CC99CC CC99FF

CCCC00 CCCC33 CCCC66 CCCC99 CCCCCC CCCCFF

CCFF00 CCFF33 CCFF66 CCFF99 CCFFCC CCFFFF

FF0000 FF0033 FF0066 FF0099 FF00CC FF00FF

FF3300 FF3333 FF3366 FF3399 FF33CC FF33FF

FF6600 FF6633 FF6666 FF6699 FF66CC FF66FF

FF9900 FF9933 FF9966 FF9999 FF99CC FF99FF

FFCC00 FFCC33 FFCC66 FFCC99 FFCCCC FFCCFF

FFFF00 FFFF33 FFFF66 FFFF99 FFFFCC FFFFFF

HTML Color Names

Color Names Supported by All Browsers

65

Page 66: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

140 color names are defined in the HTML and CSS color specification (17 standard colors plus 123 more). The table below lists them all, along with their hexadecimal values.

 Tip: The 17 standard colors are: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow.

Click on a color name (or a hex value) to view the color as the background-color along with different text colors:

Sorted by Color Name

Same list sorted by hex values

Color Name HEX Color Shades Mix

AliceBlue #F0F8FF Shades Mix

AntiqueWhite #FAEBD7 Shades Mix

Aqua #00FFFF Shades Mix

Aquamarine #7FFFD4 Shades Mix

Azure #F0FFFF Shades Mix

Beige #F5F5DC Shades Mix

Bisque #FFE4C4 Shades Mix

Black #000000 Shades Mix

BlanchedAlmond #FFEBCD Shades Mix

Blue #0000FF Shades Mix

BlueViolet #8A2BE2 Shades Mix

Brown #A52A2A Shades Mix

66

Page 67: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

BurlyWood #DEB887 Shades Mix

CadetBlue #5F9EA0 Shades Mix

Chartreuse #7FFF00 Shades Mix

Chocolate #D2691E Shades Mix

Coral #FF7F50 Shades Mix

CornflowerBlue #6495ED Shades Mix

Cornsilk #FFF8DC Shades Mix

Crimson #DC143C Shades Mix

Cyan #00FFFF Shades Mix

DarkBlue #00008B Shades Mix

DarkCyan #008B8B Shades Mix

DarkGoldenRod #B8860B Shades Mix

DarkGray #A9A9A9 Shades Mix

DarkGreen #006400 Shades Mix

DarkKhaki #BDB76B Shades Mix

DarkMagenta #8B008B Shades Mix

DarkOliveGreen #556B2F Shades Mix

DarkOrange #FF8C00 Shades Mix

DarkOrchid #9932CC Shades Mix

67

Page 68: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

DarkRed #8B0000 Shades Mix

DarkSalmon #E9967A Shades Mix

DarkSeaGreen #8FBC8F Shades Mix

DarkSlateBlue #483D8B Shades Mix

DarkSlateGray #2F4F4F Shades Mix

DarkTurquoise #00CED1 Shades Mix

DarkViolet #9400D3 Shades Mix

DeepPink #FF1493 Shades Mix

DeepSkyBlue #00BFFF Shades Mix

DimGray #696969 Shades Mix

DodgerBlue #1E90FF Shades Mix

FireBrick #B22222 Shades Mix

FloralWhite #FFFAF0 Shades Mix

ForestGreen #228B22 Shades Mix

Fuchsia #FF00FF Shades Mix

Gainsboro #DCDCDC Shades Mix

GhostWhite #F8F8FF Shades Mix

Gold #FFD700 Shades Mix

GoldenRod #DAA520 Shades Mix

68

Page 69: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Gray #808080 Shades Mix

Green #008000 Shades Mix

GreenYellow #ADFF2F Shades Mix

HoneyDew #F0FFF0 Shades Mix

HotPink #FF69B4 Shades Mix

IndianRed #CD5C5C Shades Mix

Indigo #4B0082 Shades Mix

Ivory #FFFFF0 Shades Mix

Khaki #F0E68C Shades Mix

Lavender #E6E6FA Shades Mix

LavenderBlush #FFF0F5 Shades Mix

LawnGreen #7CFC00 Shades Mix

LemonChiffon #FFFACD Shades Mix

LightBlue #ADD8E6 Shades Mix

LightCoral #F08080 Shades Mix

LightCyan #E0FFFF Shades Mix

LightGoldenRodYellow #FAFAD2 Shades Mix

LightGray #D3D3D3 Shades Mix

LightGreen #90EE90 Shades Mix

69

Page 70: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

LightPink #FFB6C1 Shades Mix

LightSalmon #FFA07A Shades Mix

LightSeaGreen #20B2AA Shades Mix

LightSkyBlue #87CEFA Shades Mix

LightSlateGray #778899 Shades Mix

LightSteelBlue #B0C4DE Shades Mix

LightYellow #FFFFE0 Shades Mix

Lime #00FF00 Shades Mix

LimeGreen #32CD32 Shades Mix

Linen #FAF0E6 Shades Mix

Magenta #FF00FF Shades Mix

Maroon #800000 Shades Mix

MediumAquaMarine #66CDAA Shades Mix

MediumBlue #0000CD Shades Mix

MediumOrchid #BA55D3 Shades Mix

MediumPurple #9370DB Shades Mix

MediumSeaGreen #3CB371 Shades Mix

MediumSlateBlue #7B68EE Shades Mix

MediumSpringGreen #00FA9A Shades Mix

70

Page 71: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

MediumTurquoise #48D1CC Shades Mix

MediumVioletRed #C71585 Shades Mix

MidnightBlue #191970 Shades Mix

MintCream #F5FFFA Shades Mix

MistyRose #FFE4E1 Shades Mix

Moccasin #FFE4B5 Shades Mix

NavajoWhite #FFDEAD Shades Mix

Navy #000080 Shades Mix

OldLace #FDF5E6 Shades Mix

Olive #808000 Shades Mix

OliveDrab #6B8E23 Shades Mix

Orange #FFA500 Shades Mix

OrangeRed #FF4500 Shades Mix

Orchid #DA70D6 Shades Mix

PaleGoldenRod #EEE8AA Shades Mix

PaleGreen #98FB98 Shades Mix

PaleTurquoise #AFEEEE Shades Mix

PaleVioletRed #DB7093 Shades Mix

PapayaWhip #FFEFD5 Shades Mix

71

Page 72: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

PeachPuff #FFDAB9 Shades Mix

Peru #CD853F Shades Mix

Pink #FFC0CB Shades Mix

Plum #DDA0DD Shades Mix

PowderBlue #B0E0E6 Shades Mix

Purple #800080 Shades Mix

Red #FF0000 Shades Mix

RosyBrown #BC8F8F Shades Mix

RoyalBlue #4169E1 Shades Mix

SaddleBrown #8B4513 Shades Mix

Salmon #FA8072 Shades Mix

SandyBrown #F4A460 Shades Mix

SeaGreen #2E8B57 Shades Mix

SeaShell #FFF5EE Shades Mix

Sienna #A0522D Shades Mix

Silver #C0C0C0 Shades Mix

SkyBlue #87CEEB Shades Mix

SlateBlue #6A5ACD Shades Mix

SlateGray #708090 Shades Mix

72

Page 73: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Snow #FFFAFA Shades Mix

SpringGreen #00FF7F Shades Mix

SteelBlue #4682B4 Shades Mix

Tan #D2B48C Shades Mix

Teal #008080 Shades Mix

Thistle #D8BFD8 Shades Mix

Tomato #FF6347 Shades Mix

Turquoise #40E0D0 Shades Mix

Violet #EE82EE Shades Mix

Wheat #F5DEB3 Shades Mix

White #FFFFFF Shades Mix

WhiteSmoke #F5F5F5 Shades Mix

Yellow #FFFF00 Shades Mix

YellowGreen #9ACD32 Shades Mix

HTML Color Values

Sorted by Hex Value

73

Page 74: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Same list sorted by color name

Color Name HEX Color Shades Mix

Black #000000 Shades Mix

Navy #000080 Shades Mix

DarkBlue #00008B Shades Mix

MediumBlue #0000CD Shades Mix

Blue #0000FF Shades Mix

DarkGreen #006400 Shades Mix

Green #008000 Shades Mix

Teal #008080 Shades Mix

DarkCyan #008B8B Shades Mix

DeepSkyBlue #00BFFF Shades Mix

DarkTurquoise #00CED1 Shades Mix

MediumSpringGreen #00FA9A Shades Mix

Lime #00FF00 Shades Mix

SpringGreen #00FF7F Shades Mix

Aqua #00FFFF Shades Mix

Cyan #00FFFF Shades Mix

MidnightBlue #191970 Shades Mix

74

Page 75: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

DodgerBlue #1E90FF Shades Mix

LightSeaGreen #20B2AA Shades Mix

ForestGreen #228B22 Shades Mix

SeaGreen #2E8B57 Shades Mix

DarkSlateGray #2F4F4F Shades Mix

LimeGreen #32CD32 Shades Mix

MediumSeaGreen #3CB371 Shades Mix

Turquoise #40E0D0 Shades Mix

RoyalBlue #4169E1 Shades Mix

SteelBlue #4682B4 Shades Mix

DarkSlateBlue #483D8B Shades Mix

MediumTurquoise #48D1CC Shades Mix

Indigo #4B0082 Shades Mix

DarkOliveGreen #556B2F Shades Mix

CadetBlue #5F9EA0 Shades Mix

CornflowerBlue #6495ED Shades Mix

MediumAquaMarine #66CDAA Shades Mix

DimGray #696969 Shades Mix

SlateBlue #6A5ACD Shades Mix

75

Page 76: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

OliveDrab #6B8E23 Shades Mix

SlateGray #708090 Shades Mix

LightSlateGray #778899 Shades Mix

MediumSlateBlue #7B68EE Shades Mix

LawnGreen #7CFC00 Shades Mix

Chartreuse #7FFF00 Shades Mix

Aquamarine #7FFFD4 Shades Mix

Maroon #800000 Shades Mix

Purple #800080 Shades Mix

Olive #808000 Shades Mix

Gray #808080 Shades Mix

SkyBlue #87CEEB Shades Mix

LightSkyBlue #87CEFA Shades Mix

BlueViolet #8A2BE2 Shades Mix

DarkRed #8B0000 Shades Mix

DarkMagenta #8B008B Shades Mix

SaddleBrown #8B4513 Shades Mix

DarkSeaGreen #8FBC8F Shades Mix

LightGreen #90EE90 Shades Mix

76

Page 77: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

MediumPurple #9370DB Shades Mix

DarkViolet #9400D3 Shades Mix

PaleGreen #98FB98 Shades Mix

DarkOrchid #9932CC Shades Mix

YellowGreen #9ACD32 Shades Mix

Sienna #A0522D Shades Mix

Brown #A52A2A Shades Mix

DarkGray #A9A9A9 Shades Mix

LightBlue #ADD8E6 Shades Mix

GreenYellow #ADFF2F Shades Mix

PaleTurquoise #AFEEEE Shades Mix

LightSteelBlue #B0C4DE Shades Mix

PowderBlue #B0E0E6 Shades Mix

FireBrick #B22222 Shades Mix

DarkGoldenRod #B8860B Shades Mix

MediumOrchid #BA55D3 Shades Mix

RosyBrown #BC8F8F Shades Mix

DarkKhaki #BDB76B Shades Mix

Silver #C0C0C0 Shades Mix

77

Page 78: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

MediumVioletRed #C71585 Shades Mix

IndianRed #CD5C5C Shades Mix

Peru #CD853F Shades Mix

Chocolate #D2691E Shades Mix

Tan #D2B48C Shades Mix

LightGray #D3D3D3 Shades Mix

Thistle #D8BFD8 Shades Mix

Orchid #DA70D6 Shades Mix

GoldenRod #DAA520 Shades Mix

PaleVioletRed #DB7093 Shades Mix

Crimson #DC143C Shades Mix

Gainsboro #DCDCDC Shades Mix

Plum #DDA0DD Shades Mix

BurlyWood #DEB887 Shades Mix

LightCyan #E0FFFF Shades Mix

Lavender #E6E6FA Shades Mix

DarkSalmon #E9967A Shades Mix

Violet #EE82EE Shades Mix

PaleGoldenRod #EEE8AA Shades Mix

78

Page 79: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

LightCoral #F08080 Shades Mix

Khaki #F0E68C Shades Mix

AliceBlue #F0F8FF Shades Mix

HoneyDew #F0FFF0 Shades Mix

Azure #F0FFFF Shades Mix

SandyBrown #F4A460 Shades Mix

Wheat #F5DEB3 Shades Mix

Beige #F5F5DC Shades Mix

WhiteSmoke #F5F5F5 Shades Mix

MintCream #F5FFFA Shades Mix

GhostWhite #F8F8FF Shades Mix

Salmon #FA8072 Shades Mix

AntiqueWhite #FAEBD7 Shades Mix

Linen #FAF0E6 Shades Mix

LightGoldenRodYellow #FAFAD2 Shades Mix

OldLace #FDF5E6 Shades Mix

Red #FF0000 Shades Mix

Fuchsia #FF00FF Shades Mix

Magenta #FF00FF Shades Mix

79

Page 80: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

DeepPink #FF1493 Shades Mix

OrangeRed #FF4500 Shades Mix

Tomato #FF6347 Shades Mix

HotPink #FF69B4 Shades Mix

Coral #FF7F50 Shades Mix

DarkOrange #FF8C00 Shades Mix

LightSalmon #FFA07A Shades Mix

Orange #FFA500 Shades Mix

LightPink #FFB6C1 Shades Mix

Pink #FFC0CB Shades Mix

Gold #FFD700 Shades Mix

PeachPuff #FFDAB9 Shades Mix

NavajoWhite #FFDEAD Shades Mix

Moccasin #FFE4B5 Shades Mix

Bisque #FFE4C4 Shades Mix

MistyRose #FFE4E1 Shades Mix

BlanchedAlmond #FFEBCD Shades Mix

PapayaWhip #FFEFD5 Shades Mix

LavenderBlush #FFF0F5 Shades Mix

80

Page 81: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

SeaShell #FFF5EE Shades Mix

Cornsilk #FFF8DC Shades Mix

LemonChiffon #FFFACD Shades Mix

FloralWhite #FFFAF0 Shades Mix

Snow #FFFAFA Shades Mix

Yellow #FFFF00 Shades Mix

LightYellow #FFFFE0 Shades Mix

Ivory #FFFFF0 Shades Mix

White #FFFFFF Shades Mix

HTML Scripts

JavaScripts make HTML pages more dynamic and interactive.

81

Page 82: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Try it Yourself - Examples

Insert a scriptHow to insert a script into an HTML document.

Use of the <noscript> tagHow to handle browsers that do not support scripting, or have scripting disabled.

The HTML <script> Tag

The <script> tag is used to define a client-side script, such as a JavaScript.

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 World! to the HTML output:

Example

<script>document.write("Hello World!")</script>

Tip: To learn more about JavaScript, visit our JavaScript tutorial!

The HTML <noscript> Tag

The <noscript> tag is used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesn’t support client-side scripting.

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:

82

Page 83: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Example

<script>document.write("Hello World!")</script><noscript>Sorry, your browser does not support JavaScript!</noscript>

A Taste of JavaScript (From Our JavaScript Tutorial)

Here are some examples of what JavaScript can do:

JavaScript can write directly into the HTML output stream:

document.write("<p>This is a paragraph</p>");

JavaScript can react to events:

<button type="button" onclick="myFunction()">Click Me!</button>

JavaScript can manipulate HTML styles:

document.getElementById("demo").style.color="#ff0000";

HTML Script TagsTag Description

<script> Defines a client-side script

<noscript> Defines an alternate content for users that do not support client-side scripts

HTML Entities

Reserved characters in HTML must be replaced with character entities.

83

Page 84: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Entities

Some characters are reserved in HTML.

It is not possible to use the less than (<) or greater than (>) signs in your text, because the browser will mix them with tags.

To actually display reserved characters, we must use character entities in the HTML source code.

A character entity looks like this:

&entity_name;

OR

&#entity_number;

To display a less than sign we must write: &lt; or &#60;

Tip: The advantage of using an entity name, instead of a number, is that the name is easier to remember. However, the disadvantage is that browsers may not support all entity names (the support for entity numbers is very good).

Non-breaking Space

A common character entity used in HTML is the non-breaking space (&nbsp;).

Browsers will always truncate spaces in HTML pages. If you write 10 spaces in your text, the browser will remove 9 of them, before displaying the page. To add spaces to your text, you can use the &nbsp; character entity.

HTML Entities Example

Experiment with HTML character entities: Try it yourself

84

Page 85: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Useful Character Entities

Note: Entity names are case sensitive!

Result Description Entity Name Entity Number

non-breaking space &nbsp; &#160;

< less than &lt; &#60;

> greater than &gt; &#62;

& ampersand &amp; &#38;

¢ cent &cent; &#162;

£ pound &pound; &#163;

¥ yen &yen; &#165;

€ euro &euro; &#8364;

§ section &sect; &#167;

© copyright &copy; &#169;

® registered trademark &reg; &#174;

™ trademark &trade; &#8482;

For a complete reference of all character entities, visit our HTML Entities Reference.

HTML Uniform Resource Locators

A URL is another word for a web address.

85

Page 86: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

A URL can be composed of words, such as "w3schools.com", or an Internet Protocol (IP) address: 192.68.20.50. Most people enter the name of the website when surfing, because names are easier to remember than numbers.

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 world wide web.

A Uniform Resource Locator (URL) is used to address a document (or other data) on the world wide web.

A web address, like this: http://www.w3schools.com/html/default.asp follows these syntax rules:

scheme://host.domain:port/path/filename

Explanation:

scheme - defines the type of Internet service. The most common type is http host - defines the domain host (the default host for http is www) domain - defines the Internet domain name, like w3schools.com port - defines the port number at the host (the default port number for http is 80)  path - defines a path at the server (If omitted, the document must be stored at the root

directory of the web site) filename - defines the name of a document/resource

Common URL Schemes

The table below lists some common schemes:

Scheme Short for.... Which pages will the scheme be used for...

http HyperText Transfer Protocol Common web pages starts with http://. Not encrypted

https Secure HyperText Transfer Protocol

Secure web pages. All information exchanged are encrypted

ftp File Transfer Protocol For downloading or uploading files to a website. Useful for domain maintenance

file A file on your computer

86

Page 87: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

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 a valid ASCII format.

URL encoding converts characters into a format that can be transmitted over the Internet.

URL encoding replaces non ASCII characters with a "%" followed by two hexadecimal digits.

URLs cannot contain spaces. URL encoding normally replaces a space with a + sign.

Try It Yourself

If you click the "Submit" button below, the browser will URL encode the input before it is sent to the server. A page at the server will display the received input.

Try some other input and click Submit again.

URL Encoding ExamplesCharacter URL-encoding

€ %80

£ %A3

© %A9

® %AE

À %C0

Á %C1

 %C2

à %C3

Ä %C4

Å %C5

For a complete reference of all URL encodings, visit our URL Encoding Reference.

87

Hello Günter Submit

Page 88: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Quick List

HTML Quick List from W3Schools. Print it, fold it, and put it in your pocket.

HTML Basic Document

88

Page 89: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<!DOCTYPE html><html><head><title>Title of document goes here</title></head>

<body>Visible text goes here...</body>

</html>

Basic Tags<h1>Largest Heading</h1><h2> . . . </h2><h3> . . . </h3><h4> . . . </h4><h5> . . . </h5><h6>Smallest Heading</h6>

<p>This is a paragraph.</p><br> (line break)<hr> (horizontal rule)<!-- This is a comment -->

Formatting<b>Bold text</b><code>Computer code</code><em>Emphasized text</em><i>Italic text</i><kbd>Keyboard input</kbd> <pre>Preformatted text</pre><small>Smaller text</small><strong>Important text</strong>

<abbr> (abbreviation)<address> (contact information)<bdo> (text direction)<blockquote> (a section quoted from another source)<cite> (title of a work)<del> (deleted text)<ins> (inserted text)<sub> (subscripted text)<sup> (superscripted text)

LinksOrdinary link: <a href="http://www.example.com/">Link-text goes here</a>Image-link: <a href="http://www.example.com/"><img src="URL" alt="Alternate Text"></a>Mailto link: <a href="mailto:[email protected]">Send e-mail</a>

89

Page 90: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Bookmark:<a id="tips">Tips Section</a><a href="#tips">Jump to the Tips Section</a>

Images<img src="URL" alt="Alternate Text" height="42" width="42">

Styles/Sections<style type="text/css">  h1 {color:red;}  p {color:blue;}</style>

<div>A block-level section in a document</div><span>An inline section in a document</span>

Unordered list<ul>  <li>Item</li>  <li>Item</li></ul>

Ordered list<ol>  <li>First item</li>  <li>Second item</li></ol>

Definition list<dl>  <dt>Item 1</dt>    <dd>Describe item 1</dd>  <dt>Item 2</dt>    <dd>Describe item 2</dd></dl>

Tables

<table border="1">  <tr>    <th>table header</th>    <th>table header</th>  </tr>  <tr>    <td>table data</td>    <td>table data</td>

90

Page 91: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

  </tr></table>

Iframe

<iframe src="demo_iframe.htm"></iframe>

Forms<form action="demo_form.asp" method="post/get">

<input type="text" name="email" size="40" maxlength="50"><input type="password"><input type="checkbox" checked="checked"><input type="radio" checked="checked"><input type="submit" value="Send"><input type="reset"><input type="hidden"><select><option>Apples</option><option selected="selected">Bananas</option><option>Cherries</option></select>

<textarea name="comment" rows="60" cols="20"></textarea>

</form>

Entities&lt; is the same as <&gt; is the same as >&#169; is the same as ©

You Have Learned HTML, Now What?

HTML Summary

This tutorial has taught you how to use HTML to create your own web site.

HTML is the universal markup language for the Web. HTML lets you format text, add graphics, create links, input forms, frames and tables, etc., and save it all in a text file that any browser can read and display.

The key to HTML is the tags, which indicates what content is coming up.

91

Page 92: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

For more information on HTML, please take a look at our HTML examples and our HTML reference.

Now You Know HTML, What's Next?

Learn CSS

CSS is used to control the style and layout of multiple Web pages all at once.

With CSS, all formatting can be removed from the HTML document and stored in a separate file.

CSS gives you total control of the layout, without messing up the document content.

To learn how to create style sheets, please visit our CSS tutorial.

Learn JavaScript

JavaScript can make your web site more dynamic.

A static web site is nice when you just want to show flat content, but a dynamic web site can react to events and allow user interaction.

JavaScript is the most popular scripting language on the internet and it works with all major browsers.

If you want to learn more about JavaScript, please visit our JavaScript tutorial.

Hosting your own Web site

Hosting your web site on your own server is always an option. Here are some points to consider:

Hardware Expenses

To run a "real" web site, you will have to buy some powerful server hardware. Don't expect that a low cost PC will do the job. You will also need a permanent (24 hours a day ) high-speed connection.

Software Expenses

Remember that server-licenses often are higher than client-licenses. Also note that server-licenses might have limits on number of users.

92

Page 93: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Labor Expenses

Don't expect low labor expenses. You have to install your own hardware and software. You also have to deal with bugs and viruses, and keep your server constantly running in an environment where "everything could happen".

Using an Internet Service Provider

Renting a server from an Internet Service Provider (ISP) is a common option.

Most small companies store their web site on a server provided by an ISP. Here are some advantages:

Connection Speed

Most ISPs have very fast connections to the Internet.

Powerful Hardware

ISPs often have powerful web servers that can be shared by several companies. You can also expect them to have an effective load balancing, and necessary backup servers.

Security and Stability

ISPs are specialists on web hosting. Expect their servers to have more than 99% up time, the latest software patches, and the best virus protection.

Things to Consider with an ISP24-hour support

Make sure your ISP offers 24-hours support. Don't put yourself in a situation where you cannot fix critical problems without having to wait until the next working day. Toll-free phone could be vital if you don't want to pay for long distance calls.

Daily Backup

Make sure your ISP runs a daily backup routine, otherwise you may lose some valuable data.

93

Page 94: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Traffic Volume

Study the ISP's traffic volume restrictions. Make sure that you don't have to pay a fortune for unexpected high traffic if your web site becomes popular.

Bandwidth or Content Restrictions

Study the ISP's bandwidth and content restrictions. If you plan to publish pictures or broadcast video or sound, make sure that you can.

E-mail Capabilities

Make sure your ISP supports the e-mail capabilities you need.

Database Access

If you plan to use data from databases on your web site, make sure your ISP supports the database access you need.

HTML - XHTML

XHTML is HTML written as XML.

What Is XHTML?

XHTML stands for EXtensible HyperText Markup Language

94

Page 95: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

XHTML is almost identical to HTML 4.01 XHTML is a stricter and cleaner version of HTML 4.01 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.

The following HTML code will work fine if you view it in a browser (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>

XML is a markup language where documents must be marked up correctly and "well-formed".

If you want to study XML, please read our XML tutorial.

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 a "bad" markup language.

Therefore - by combining the strengths of HTML and XML, XHTML was developed. XHTML is HTML redesigned as XML.

The Most Important Differences from HTML:Document Structure

XHTML DOCTYPE is mandatory The XML namespace attribute in <html> is mandatory <html>, <head>, <title>, and <body> is mandatory

XHTML Elements

XHTML elements must be properly nested XHTML elements must always be closed

95

Page 96: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

XHTML elements must be in lowercase XHTML documents must have one root element

XHTML Attributes

Attribute names must be in lower case Attribute values must be quoted Attribute minimization is forbidden

<!DOCTYPE ....> Is Mandatory

An XHTML document must have an XHTML DOCTYPE declaration.

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.

The example below shows an XHTML document with a minimum of required tags:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head><title>Title of document</title></head>

<body>...... </body>

</html>

XHTML Elements Must Be Properly Nested

In HTML, some elements can be improperly nested within each other, like this:

<b><i>This text is bold and italic</b></i>

In XHTML, all elements must be properly nested within each other, like this:

96

Page 97: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<b><i>This text is bold and italic</i></b>

XHTML Elements Must Always Be Closed

This is wrong:

<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>

Empty Elements Must Also Be Closed

This is wrong:

A break: <br>A horizontal rule: <hr>An image: <img src="happy.gif" alt="Happy face">

This is correct:

A break: <br />A horizontal rule: <hr />An image: <img src="happy.gif" alt="Happy face" />

XHTML Elements Must Be In Lower Case

This is wrong:

<BODY><P>This is a paragraph</P></BODY>

97

Page 98: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

This is correct:

<body><p>This is a paragraph</p></body>

Attribute Names Must Be In Lower Case

This is wrong:

<table WIDTH="100%">

This is correct:

<table width="100%">

Attribute Values Must Be Quoted

This is wrong:

<table width=100%>

This is correct:

<table width="100%">

Attribute Minimization Is Forbidden

This is wrong:

<input checked><input readonly><input disabled><option selected>

This is correct:

98

Page 99: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<input checked="checked"><input readonly="readonly"><input disabled="disabled"><option selected="selected">

How to Convert from HTML to XHTML

1. Add an XHTML <!DOCTYPE> to the first line of every page2. Add an xmlns attribute to the html element of every page3. Change all element names to lowercase4. Close all empty elements5. Change all attribute names to lowercase6. Quote all attribute values

HTML5 Introduction

HTML5 is The New HTML Standard

HTML5

New Elements New Attributes Full CSS3 Support

99

Page 100: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Video and Audio 2D/3D Graphics Local Storage Local SQL Database Web Applications

Examples in Each Chapter

With our HTML editor, you can edit the HTML, and click on a button to view the result.

Example

<!DOCTYPE HTML><html><body>

<video width="320" height="240" controls>  <source src="movie.mp4" type="video/mp4">  <source src="movie.ogg" type="video/ogg">  Your browser does not support the video tag.</video>

</body></html>

What is HTML5?

HTML5 will be the new standard for HTML.

The previous version of HTML, HTML 4.01, came in 1999. The web has changed a lot since then.

HTML5 is still a work in progress. However, the major browsers support many of the new HTML5 elements and APIs.

How Did HTML5 Get Started?

HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG).

WHATWG was working with web forms and applications, and W3C was working with XHTML 2.0. In 2006, they decided to cooperate and create a new version of HTML.

Some rules for HTML5 were established:

New features should be based on HTML, CSS, DOM, and JavaScript Reduce the need for external plugins (like Flash) Better error handling

100

Page 101: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

More markup to replace scripting HTML5 should be device independent The development process should be visible to the public

The HTML5 <!DOCTYPE>

In HTML5 there is only one <!doctype> declaration, and it is very simple:

<!DOCTYPE html>

Minimum HTML5 Document

Below is a simple HTML5 document, with the minimum of required tags:

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Title of the document</title></head>

<body>Content of the document......</body>

</html>

HTML5 - New Features

Some of the most interesting new features in HTML5:

The <canvas> element for 2D drawing The <video> and <audio> elements for media playback Support for local storage New content-specific elements, like <article>, <footer>, <header>, <nav>, <section> New form controls, like calendar, date, time, email, url, search

Browser Support for HTML5

101

Page 102: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML5 is not yet an official standard, and no browsers have full HTML5 support.

But all major browsers (Safari, Chrome, Firefox, Opera, Internet Explorer) continue to add new HTML5 features to their latest versions.

HTML5 New Elements

New Elements in HTML5

The internet, and the use of the internet, has changed a lot since HTML 4.01 became a standard in 1999.

Today, several elements in HTML 4.01 are obsolete, never used, or not used the way they were intended. All those elements are removed or re-written in HTML5.

102

Page 103: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

To better handle today's internet use, HTML5 also includes new elements for drawing graphics, adding media content, better page structure, better form handling, and several APIs to drag/drop elements, find Geolocation, include web storage, application cache, web workers, etc.

The New <canvas> ElementTag Description

<canvas> Used to draw graphics, on the fly, via scripting (usually JavaScript)

New Media ElementsTag Description

<audio> Defines sound content

<video> Defines a video or movie

<source> Defines multiple media resources for <video> and <audio>

<embed> Defines a container for an external application or interactive content (a plug-in)

<track> Defines text tracks for <video> and <audio>

New Form ElementsTag Description

<datalist> Specifies a list of pre-defined options for input controls

<keygen> Defines a key-pair generator field (for forms)

<output> Defines the result of a calculation

New Semantic/Structural Elements

HTML5 offers new elements for better structure:

Tag Description

<article> Defines an article

<aside> Defines content aside from the page content

103

Page 104: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<bdi> Isolates a part of text that might be formatted in a different direction from other text outside it

<command> Defines a command button that a user can invoke

<details> Defines additional details that the user can view or hide

<dialog> Defines a dialog box or window

<summary> Defines a visible heading for a <details> element

<figure> Specifies self-contained content, like illustrations, diagrams, photos, code listings, etc.

<figcaption> Defines a caption for a <figure> element

<footer> Defines a footer for a document or section

<header> Defines a header for a document or section

<mark> Defines marked/highlighted text

<meter> Defines a scalar measurement within a known range (a gauge)

<nav> Defines navigation links

<progress> Represents the progress of a task

<ruby> Defines a ruby annotation (for East Asian typography)

<rt> Defines an explanation/pronunciation of characters (for East Asian typography)

<rp> Defines what to show in browsers that do not support ruby annotations

<section> Defines a section in a document

<time> Defines a date/time

<wbr> Defines a possible line-break

Removed Elements

The following HTML 4.01 elements are removed from HTML5:

<acronym> <applet> <basefont> <big> <center> <dir> <font> <frame>

104

Page 105: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<frameset> <noframes> <strike> <tt>

HTML5 Canvas

The <canvas> element is used to draw graphics, on the fly, on a web page.

Draw a red rectangle, a gradient rectangle, a multicolor rectangle, and some multicolor text onto the canvas:

 

What is Canvas?

105

Page 106: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The HTML5 <canvas> element is used to draw graphics, on the fly, via scripting (usually JavaScript).

The <canvas> element is only a container for graphics. You must use a script to actually draw the graphics.

Canvas has several methods for drawing paths, boxes, circles, characters, and adding images.

Browser Support

       

Internet Explorer 9+, Firefox, Opera, Chrome, and Safari support the <canvas> element.

Note: Internet Explorer 8 and earlier versions, do not support the <canvas> element.

Create a Canvas

A canvas is a rectangular area on an HTML page, and it is specified with the <canvas> element.

Note: By default, the <canvas> element has no border and no content.

The markup looks like this:

<canvas id="myCanvas" width="200" height="100"></canvas>

Note: Always specify an id attribute (to be referred to in a script), and a width and height attribute to define the size of the canvas.

Tip: You can have multiple <canvas> elements on one HTML page.

To add a border, use the style attribute:

Example

<canvas id="myCanvas" width="200" height="100"style="border:1px solid #000000;"></canvas>

Draw Onto The Canvas With JavaScript

All drawing on the canvas must be done inside a JavaScript:

Example

106

Page 107: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<script>var c=document.getElementById("myCanvas");var ctx=c.getContext("2d");ctx.fillStyle="#FF0000";ctx.fillRect(0,0,150,75);</script>

Example explained:

First, find the <canvas> element:

var c=document.getElementById("myCanvas");

Then, call its getContext() method (you must pass the string "2d" to the getContext() method):

var ctx=c.getContext("2d");

The getContext("2d") object is a built-in HTML5 object, with many properties and methods for drawing paths, boxes, circles, text, images, and more.

The next two lines draw a red rectangle:

ctx.fillStyle="#FF0000";ctx.fillRect(0,0,150,75);

The fillStyle property can be a CSS color, a gradient, or a pattern. The default fillStyle is #000000 (black).

The fillRect(x,y,width,height) method draws a rectangle filled with the current fill style.

Canvas Coordinates

The canvas is a two-dimensional grid.

The upper-left corner of the canvas has coordinate (0,0)

So, the fillRect() method above had the parameters (0,0,150,75).

This means: Start at the upper-left corner (0,0) and draw a 150x75 pixels rectangle.

Coordinates Example

Mouse over the rectangle below to see its x and y coordinates:

107

Page 108: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Canvas - Paths

To draw straight lines on a canvas, we will use the following two methods:

moveTo(x,y) defines the starting point of the line lineTo(x,y) defines the ending point of the line

To actually draw the line, we must use one of the "ink" methods, like stroke().

Example

Define a starting point in position (0,0), and an ending point in position (200,100). Then use the stroke() method to actually draw the line:

JavaScript:

var c=document.getElementById("myCanvas");var ctx=c.getContext("2d");ctx.moveTo(0,0);ctx.lineTo(200,100);ctx.stroke();

To draw a circle on a canvas, we will use the following method:

arc(x,y,r,start,stop)

To actually draw the circle, we must use one of the "ink" methods, like stroke() or fill().

108

Page 109: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Example

Create a circle with the arc() method:

JavaScript:

var c=document.getElementById("myCanvas");var ctx=c.getContext("2d");ctx.beginPath();ctx.arc(95,50,40,0,2*Math.PI);ctx.stroke();

Canvas - Text

To draw text on a canvas, the most important property and methods are:

font - defines the font properties for text fillText(text,x,y) - Draws "filled" text on the canvas strokeText(text,x,y) - Draws text on the canvas (no fill)

Using fillText():

Example

Write a 30px high filled text on the canvas, using the font "Arial":

JavaScript:

109

Page 110: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

var c=document.getElementById("myCanvas");var ctx=c.getContext("2d");ctx.font="30px Arial";ctx.fillText("Hello World",10,50);

Using strokeText():

Example

Write a 30px high text (no fill) on the canvas, using the font "Arial":

JavaScript:

var c=document.getElementById("myCanvas");var ctx=c.getContext("2d");ctx.font="30px Arial";ctx.strokeText("Hello World",10,50);

Canvas - Gradients

Gradients can be used to fill rectangles, circles, lines, text, etc. Shapes on the canvas are not limited to solid colors.

There are two different types of gradients:

createLinearGradient(x,y,x1,y1) - Creates a linear gradient createRadialGradient(x,y,r,x1,y1,r1) - Creates a radial/circular gradient

Once we have a gradient object, we must add two or more color stops.

The addColorStop() method specifies the color stops, and its position along the gradient. Gradient positions can be anywhere between 0 to 1.

To use the gradient, set the fillStyle or strokeStyle property to the gradient, and then draw the shape, like a rectangle, text, or a line.

Using createLinearGradient():

Example

Create a linear gradient. Fill rectangle with the gradient:

110

Page 111: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

JavaScript:

var c=document.getElementById("myCanvas");var ctx=c.getContext("2d");

// Create gradientvar grd=ctx.createLinearGradient(0,0,200,0);grd.addColorStop(0,"red");grd.addColorStop(1,"white");

// Fill with gradientctx.fillStyle=grd;ctx.fillRect(10,10,150,80);

Using createRadialGradient():

Example

Create a radial/circular gradient. Fill rectangle with the gradient:

JavaScript:

var c=document.getElementById("myCanvas");var ctx=c.getContext("2d");

// Create gradientvar grd=ctx.createRadialGradient(75,50,5,90,60,100);grd.addColorStop(0,"red");grd.addColorStop(1,"white");

// Fill with gradientctx.fillStyle=grd;ctx.fillRect(10,10,150,80);

Canvas - Images111

Page 112: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

To draw an image on a canvas, we will use the following method:

drawImage(image,x,y)

Image to use:

Example

Draw the image onto the canvas:

112

Page 113: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

JavaScript:

var c=document.getElementById("myCanvas");var ctx=c.getContext("2d");var img=document.getElementById("scream");ctx.drawImage(img,10,10);

HTML Canvas Reference

For a complete reference of all the properties and methods that can be used with the Canvas object (with try-it examples on every property and method), go to our Canvas Reference.

The HTML <canvas> TagTag Description

<canvas> Used to draw graphics, on the fly, via scripting (usually JavaScript)

HTML5 Inline SVG

113

Page 114: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML5 has support for inline SVG.

What is SVG?

SVG stands for Scalable Vector Graphics SVG is used to define vector-based graphics for the Web SVG defines the graphics in XML format SVG graphics do NOT lose any quality if they are zoomed or resized Every element and every attribute in SVG files can be animated SVG is a W3C recommendation

SVG Advantages

Advantages of using SVG over other image formats (like JPEG and GIF) are:

SVG images can be created and edited with any text editor SVG images can be searched, indexed, scripted, and compressed SVG images are scalable SVG images can be printed with high quality at any resolution SVG images are zoomable (and the image can be zoomed without degradation)

Browser Support

       

Internet Explorer 9+, Firefox, Opera, Chrome, and Safari support inline SVG.

Embed SVG Directly Into HTML Pages

In HTML5, you can embed SVG elements directly into your HTML page:

Example

<!DOCTYPE html><html><body>

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="190">  <polygon points="100,10 40,180 190,60 10,60 160,180"  style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;"></svg>

114

Page 115: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

</body></html>

Result:

To learn more about SVG, please read our SVG Tutorial.

Differences Between SVG and Canvas

SVG is a language for describing 2D graphics in XML.

Canvas draws 2D graphics, on the fly (with a JavaScript).

SVG is XML based, which means that every element is available within the SVG DOM. You can attach JavaScript event handlers for an element.

In SVG, each drawn shape is remembered as an object. If attributes of an SVG object are changed, the browser can automatically re-render the shape.

Canvas is rendered pixel by pixel. In canvas, once the graphic is drawn, it is forgotten by the browser. If its position should be changed, the entire scene needs to be redrawn, including any objects that might have been covered by the graphic.

Comparison of Canvas and SVG

The table below shows some important differences between Canvas and SVG:

Canvas SVG

Resolution dependent No support for event handlers Poor text rendering capabilities You can save the resulting image as .png or .jpg Well suited for graphic-intensive games

Resolution independent Support for event handlers Best suited for applications with large

rendering areas (Google Maps) Slow rendering if complex (anything

that uses the DOM a lot will be slow) Not suited for game applications

HTML5 Drag and Drop

115

Page 116: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Drag and drop is a part of the HTML5 standard.

Drag the W3Schools image into the rectangle.

Drag and Drop

Drag and drop is a very common feature. It is when you "grab" an object and drag it to a different location.

In HTML5, drag and drop is part of the standard, and any element can be draggable.

Browser Support

       

Internet Explorer 9+, Firefox, Opera, Chrome, and Safari support drag and drop.

Note: Drag and drop does not work in Safari 5.1.2.

HTML5 Drag and Drop Example

The example below is a simple drag and drop example:

Example

<!DOCTYPE HTML><html><head><script>function allowDrop(ev){ev.preventDefault();}

function drag(ev){ev.dataTransfer.setData("Text",ev.target.id);}

function drop(ev)

116

Page 117: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

{ev.preventDefault();var data=ev.dataTransfer.getData("Text");ev.target.appendChild(document.getElementById(data));}</script></head><body>

<div id="div1" ondrop="drop(event)"ondragover="allowDrop(event)"></div>

<img id="drag1" src="img_logo.gif" draggable="true"ondragstart="drag(event)" width="336" height="69">

</body></html>

It might seem complicated, but lets go through all the different parts of a drag and drop event.

Make an Element Draggable

First of all: To make an element draggable, set the draggable attribute to true:

<img draggable="true">

What to Drag - ondragstart and setData()

Then, specify what should happen when the element is dragged.

In the example above, the ondragstart attribute calls a function, drag(event), that specifies what data to be dragged.

The dataTransfer.setData() method sets the data type and the value of the dragged data:

function drag(ev){ev.dataTransfer.setData("Text",ev.target.id);}

In this case, the data type is "Text" and the value is the id of the draggable element ("drag1").

Where to Drop - ondragover

The ondragover event specifies where the dragged data can be dropped.

117

Page 118: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

By default, data/elements cannot be dropped in other elements. To allow a drop, we must prevent the default handling of the element.

This is done by calling the event.preventDefault() method for the ondragover event:

event.preventDefault()

Do the Drop - ondrop

When the dragged data is dropped, a drop event occurs.

In the example above, the ondrop attribute calls a function, drop(event):

function drop(ev){ev.preventDefault();var data=ev.dataTransfer.getData("Text");ev.target.appendChild(document.getElementById(data));}

Code explained:

Call preventDefault() to prevent the browser default handling of the data (default is open as link on drop)

Get the dragged data with the dataTransfer.getData("Text") method. This method will return any data that was set to the same type in the setData() method

The dragged data is the id of the dragged element ("drag1") Append the dragged element into the drop element

More Examples

Drag image back and forthHow to drag (and drop) an image back and forth between two <div> elements.

HTML5 Geolocation

118

Page 119: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML5 Geolocation is used to locate a user's position Try It

Locate the User's Position

The HTML5 Geolocation API is used to get the geographical position of a user.

Since this can compromise user privacy, the position is not available unless the user approves it.

Browser Support

       

Internet Explorer 9+, Firefox, Chrome, Safari and Opera support Geolocation.

Note: Geolocation is much more accurate for devices with GPS, like iPhone.

HTML5 - Using Geolocation

Use the getCurrentPosition() method to get the user's position.

The example below is a simple Geolocation example returning the latitude and longitude of the user's position:

Example

<script>var x=document.getElementById("demo");function getLocation()  {  if (navigator.geolocation)    {    navigator.geolocation.getCurrentPosition(showPosition);    }  else{x.innerHTML="Geolocation is not supported by this browser.";}  }function showPosition(position)  {  x.innerHTML="Latitude: " + position.coords.latitude +   "<br>Longitude: " + position.coords.longitude;   }</script>

Example explained:

119

Page 120: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Check if Geolocation is supported If supported, run the getCurrentPosition() method. If not, display a message to the user If the getCurrentPosition() method is successful, it returns a coordinates object to the function

specified in the parameter ( showPosition ) The showPosition() function gets the displays the Latitude and Longitude

The example above is a very basic Geolocation script, with no error handling.

Handling Errors and Rejections

The second parameter of the getCurrentPosition() method is used to handle errors. It specifies a function to run if it fails to get the user's location:

Example

function showError(error)  {  switch(error.code)     {    case error.PERMISSION_DENIED:      x.innerHTML="User denied the request for Geolocation."      break;    case error.POSITION_UNAVAILABLE:      x.innerHTML="Location information is unavailable."      break;    case error.TIMEOUT:      x.innerHTML="The request to get user location timed out."      break;    case error.UNKNOWN_ERROR:      x.innerHTML="An unknown error occurred."      break;    }  }

Error Codes:

Permission denied - The user did not allow Geolocation Position unavailable - It is not possible to get the current location Timeout - The operation timed out

Displaying the Result in a Map

To display the result in a map, you need access to a map service that can use latitude and longitude, like Google Maps:

120

Page 121: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Example

function showPosition(position){var latlon=position.coords.latitude+","+position.coords.longitude;

var img_url="http://maps.googleapis.com/maps/api/staticmap?center="+latlon+"&zoom=14&size=400x300&sensor=false";

document.getElementById("mapholder").innerHTML="<img src='"+img_url+"'>";}

In the example above we use the returned latitude and longitude data to show the location in a Google map (using a static image).

Google Map ScriptHow to use a script to show an interactive map with a marker, zoom and drag options.

Location-specific Information

This page demonstrated how to show a user's position on a map. However, Geolocation is also very useful for location-specific information.

Examples:

Up-to-date local information Showing Points-of-interest near the user Turn-by-turn navigation (GPS)

The getCurrentPosition() Method - Return Data

The getCurrentPosition() method returns an object if it is successful. The latitude, longitude and accuracy properties are always returned. The other properties below are returned if available.

Property Description

coords.latitude The latitude as a decimal number

coords.longitude The longitude as a decimal number

coords.accuracy The accuracy of position

coords.altitude The altitude in meters above the mean sea level

coords.altitudeAccuracy

The altitude accuracy of position

coords.heading The heading as degrees clockwise from North

121

Page 122: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

coords.speed The speed in meters per second

timestamp The date/time of the response

Geolocation object - Other interesting Methods

watchPosition() - Returns the current position of the user and continues to return updated position as the user moves (like the GPS in a car).

clearWatch() - Stops the watchPosition() method.

The example below shows the watchPosition() method. You need an accurate GPS device to test this (like iPhone):

Example

<script>var x=document.getElementById("demo");function getLocation()  {  if (navigator.geolocation)    {    navigator.geolocation.watchPosition(showPosition);    }  else{x.innerHTML="Geolocation is not supported by this browser.";}  }function showPosition(position)  {  x.innerHTML="Latitude: " + position.coords.latitude +   "<br>Longitude: " + position.coords.longitude;   }</script>

HTML5 Video

Many modern websites show videos. HTML5 provides a standard for showing them.

122

Page 123: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Check if your browser supports HTML5 video

Yeah! Full support!

Video on the Web

Until now, there has not been a standard for showing a video/movie on a web page.

Today, most videos are shown through a plug-in (like flash). However, different browsers may have different plug-ins.

HTML5 defines a new element which specifies a standard way to embed a video/movie on a web page: the <video> element.

Browser Support

       

Internet Explorer 9+, Firefox, Opera, Chrome, and Safari support the <video> element.

Note: Internet Explorer 8 and earlier versions, do not support the <video> element.

HTML5 Video - How It Works

To show a video in HTML5, this is all you need:

Example

<video width="320" height="240" controls>  <source src="movie.mp4" type="video/mp4">  <source src="movie.ogg" type="video/ogg">Your browser does not support the video tag.</video>

The control attribute adds video controls, like play, pause, and volume.

It is also a good idea to always include width and height attributes. If height and width are set, the space required for the video is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the video, and cannot reserve the appropriate space to it. The effect will be that the page layout will change during loading (while the video loads).

You should also insert text content between the <video> and </video> tags for browsers that do not support the <video> element.

123

Page 124: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The <video> element allows multiple <source> elements. <source> elements can link to different video files. The browser will use the first recognized format.

Video Formats and Browser Support

Currently, there are 3 supported video formats for the <video> element: MP4, WebM, and Ogg:

Browser MP4 WebM Ogg

Internet Explorer 9+ YES NO NO

Chrome 6+ YES YES YES

Firefox 3.6+ NO YES YES

Safari 5+ YES NO NO

Opera 10.6+ NO YES YES

MP4 = MPEG 4 files with H264 video codec and AAC audio codec WebM = WebM files with VP8 video codec and Vorbis audio codec Ogg = Ogg files with Theora video codec and Vorbis audio codec

MIME Types for Video FormatsFormat MIME-type

MP4 video/mp4

WebM video/webm

Ogg video/ogg

HTML5 <video> - DOM Methods and Properties

HTML5 has DOM methods, properties, and events for the <video> and <audio> elements.

These methods, properties, and events allow you to manipulate <video> and <audio> elements using JavaScript.

There are methods for playing, pausing, and loading, for example and there are properties (like duration and volume). There are also DOM events that can notify you when the <video> element begins to play, is paused, is ended, etc.

124

Page 125: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The example below illustrate, in a simple way, how to address a <video> element, read and set properties, and call methods.

Example 1

Create simple play/pause + resize controls for a video:

Play/Pause Big Small Normal 

Video courtesy of Big Buck Bunny.

The example above calls two methods: play() and pause(). It also uses two properties: paused and width.

For a full reference go to our HTML5 Audio/Video DOM Reference.

HTML5 Video TagsTag Description

<video> Defines a video or movie

125

Page 126: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<source> Defines multiple media resources for media elements, such as <video> and <audio>

<track> Defines text tracks in media players

HTML5 Audio

HTML5 provides a standard for playing audio files.

126

Page 127: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Audio on the Web

Until now, there has not been a standard for playing audio files on a web page.

Today, most audio files are played through a plug-in (like flash). However, different browsers may have different plug-ins.

HTML5 defines a new element which specifies a standard way to embed an audio file on a web page: the <audio> element.

Browser Support

Internet Explorer 9+, Firefox, Opera, Chrome, and Safari support the <audio> element.

Note: Internet Explorer 8 and earlier versions, do not support the <audio> element.

HTML5 Audio - How It Works

To play an audio file in HTML5, this is all you need:

Example

<audio controls>  <source src="horse.ogg" type="audio/ogg">  <source src="horse.mp3" type="audio/mpeg">Your browser does not support the audio element.</audio>

The control attribute adds audio controls, like play, pause, and volume.

You should also insert text content between the <audio> and </audio> tags for browsers that do not support the <audio> element.

The <audio> element allows multiple <source> elements. <source> elements can link to different audio files. The browser will use the first recognized format.

Audio Formats and Browser Support

127

Page 128: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Currently, there are 3 supported file formats for the <audio> element: MP3, Wav, and Ogg:

Browser MP3 Wav Ogg

Internet Explorer 9+ YES NO NO

Chrome 6+ YES YES YES

Firefox 3.6+ NO YES YES

Safari 5+ YES YES NO

Opera 10+ NO YES YES

MIME Types for Audio FormatsFormat MIME-type

MP3 audio/mpeg

Ogg audio/ogg

Wav audio/wav

HTML5 Audio TagsTag Description

<audio> Defines sound content

<source> Defines multiple media resources for media elements, such as <video> and

128

Page 129: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<audio>

HTML5 Input Types

HTML5 New Input Types

129

Page 130: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML5 has several new input types for forms. These new features allow better input control and validation.

This chapter covers the new input types:

color date datetime datetime-local email month number range search tel time url week

Note: Not all major browsers support all the new input types. However, you can already start using them; If they are not supported, they will behave as regular text fields.

Input Type: color

The color type is used for input fields that should contain a color.

Example

Select a color from a color picker:

Select your favorite color: <input type="color" name="favcolor">

Input Type: date

The date type allows the user to select a date.

Example

Define a date control:

Birthday: <input type="date" name="bday">

130

Page 131: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Input Type: datetime

The datetime type allows the user to select a date and time (with time zone).

Example

Define a date and time control (with time zone):

Birthday (date and time):<input type="datetime" name="bdaytime">

Input Type: datetime-local

The datetime-local type allows the user to select a date and time (no time zone).

Example

Define a date and time control (no time zone):

Birthday (date and time):<input type="datetime-local" name="bdaytime">

Input Type: email

The email type is used for input fields that should contain an e-mail address.

Example

Define a field for an e-mail address (will be automatically validated when submitted):

E-mail: <input type="email" name="email">

Tip: Safari on iPhone recognizes the email type, and changes the on-screen keyboard to match it (adds @ and .com options).

Input Type: month

The month type allows the user to select a month and year.

131

Page 132: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Example

Define a month and year control (no time zone):

Birthday (month and year):<input type="month" name="bdaymonth">

Input Type: number

The number type is used for input fields that should contain a numeric value.

You can also set restrictions on what numbers are accepted:

Example

Define a numeric field (with restrictions):

Quantity (between 1 and 5):<input type="number" name="quantity" min="1" max="5">

Use the following attributes to specify restrictions:

max  - specifies the maximum value allowed min  - specifies the minimum value allowed step  - specifies the legal number intervals value  - Specifies the default value

Try an example with all the restriction attributes: Try it yourself

Input Type: range

The range type is used for input fields that should contain a value from a range of numbers.

You can also set restrictions on what numbers are accepted.

Example

Define a control for entering a number whose exact value is not important (like a slider control):

<input type="range" name="points" min="1" max="10">

Use the following attributes to specify restrictions:

132

Page 133: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

max  - specifies the maximum value allowed min  - specifies the minimum value allowed step  - specifies the legal number intervals value  - Specifies the default value

Input Type: search

The search type is used for search fields (a search field behaves like a regular text field).

Example

Define a search field (like a site search, or Google search):

Search Google: <input type="search" name="googlesearch">

Input Type: tel

Example

Define a field for entering a telephone number:

Telephone: <input type="tel" name="usrtel">

Input Type: time

The time type allows the user to select a time.

Example

Define a control for entering a time (no time zone):

Select a time: <input type="time" name="usr_time">

Input Type: url

The url type is used for input fields that should contain a URL address.

The value of the url field is automatically validated when the form is submitted.

133

Page 134: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Example

Define a field for entering a URL:

Add your homepage: <input type="url" name="homepage">

Tip: Safari on iPhone recognizes the url input type, and changes the on-screen keyboard to match it (adds .com option).

Input Type: week

The week type allows the user to select a week and year.

Example

Define a week and year control (no time zone):

Select a week: <input type="week" name="week_year">

HTML5 <input> TagTag Description

<input> Defines an input control

HTML5 Form Elements

HTML5 New Form Elements

HTML5 has the following new form elements:

<datalist>

134

Page 135: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<keygen> <output>

Note: Not all major browsers support all the new form elements. However, you can already start using them; If they are not supported, they will behave as regular text fields.

HTML5 <datalist> Element

The <datalist> element specifies a list of pre-defined options for an <input> element.

The <datalist> element is used to provide an "autocomplete" feature on <input> elements. Users will see a drop-down list of pre-defined options as they input data.

Use the <input> element's list attribute to bind it together with a <datalist> element.

Example

An <input> element with pre-defined values in a <datalist>:

<input list="browsers">

<datalist id="browsers">  <option value="Internet Explorer">  <option value="Firefox">  <option value="Chrome">  <option value="Opera">  <option value="Safari"></datalist>

HTML5 <keygen> Element

The purpose of the <keygen> element is to provide a secure way to authenticate users.

The <keygen> tag specifies a key-pair generator field in a form.

When the form is submitted, two keys are generated, one private and one public.

The private key is stored locally, and the public key is sent to the server. The public key could be used to generate a client certificate to authenticate the user in the future.

Example

A form with a keygen field:

135

Page 136: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<form action="demo_keygen.asp" method="get">Username: <input type="text" name="usr_name">Encryption: <keygen name="security"><input type="submit"></form>

HTML5 <output> Element

The <output> element represents the result of a calculation (like one performed by a script).

Example

Perform a calculation and show the result in an <output> element:

<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">0<input type="range" id="a" value="50">100 +<input type="number" id="b" value="50">=<output name="x" for="a b"></output></form>

HTML5 New Form ElementsTag Description

<datalist> Specifies a list of pre-defined options for an <input> element

<keygen> Specifies a key-pair generator field in a form

<output> Represents the result of a calculation

HTML5 Form Attributes

HTML5 New Form Attributes

HTML5 has several new attributes for <form> and <input>.

136

Page 137: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

New attributes for <form>:

autocomplete novalidate

New attributes for <input>:

autocomplete autofocus form formaction formenctype formmethod formnovalidate formtarget height and width list min and max multiple pattern (regexp) placeholder required step

<form> / <input> autocomplete Attribute

The autocomplete attribute specifies whether a form or input field should have autocomplete on or off.

When autocomplete is on, the browser automatically complete values based on values that the user has entered before.

Tip: It is possible to have autocomplete "on" for the form, and "off" for specific input fields, or vice versa.

Note: The autocomplete attribute works with <form> and the following <input> types: text, search, url, tel, email, password, datepickers, range, and color.

Example

An HTML form with autocomplete on (and off for one input field):

<form action="demo_form.asp" autocomplete="on">  First name:<input type="text" name="fname"><br>  Last name: <input type="text" name="lname"><br>  E-mail: <input type="email" name="email" autocomplete="off"><br>  <input type="submit"></form>

137

Page 138: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Tip: In some browsers you may need to activate the autocomplete function for this to work.

<form> novalidate Attribute

The novalidate attribute is a boolean attribute.

When present, it specifies that the form-data (input) should not be validated when submitted.

Example

Indicates that the form is not to be validated on submit:

<form action="demo_form.asp" novalidate>  E-mail: <input type="email" name="user_email">  <input type="submit"></form>

<input> autofocus Attribute

The autofocus attribute is a boolean attribute.

When present, it specifies that an <input> element should automatically get focus when the page loads.

Example

Let the "First name" input field automatically get focus when the page loads:

First name:<input type="text" name="fname" autofocus>

<input> form Attribute

The form attribute specifies one or more forms an <input> element belongs to.

Tip: To refer to more than one form, use a space-separated list of form ids.

Example

An input field located outside the HTML form (but still a part of the form):

138

Page 139: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<form action="demo_form.asp" id="form1">  First name: <input type="text" name="fname"><br>  <input type="submit" value="Submit"></form>

Last name: <input type="text" name="lname" form="form1">

<input> formaction Attribute

The formaction attribute specifies the URL of a file that will process the input control when the form is submitted.

The formaction attribute overrides the action attribute of the <form> element.

Note: The formaction attribute is used with type="submit" and type="image".

Example

An HTML form with two submit buttons, with different actions:

<form action="demo_form.asp">  First name: <input type="text" name="fname"><br>  Last name: <input type="text" name="lname"><br>  <input type="submit" value="Submit"><br>  <input type="submit" formaction="demo_admin.asp"  value="Submit as admin"></form>

<input> formenctype Attribute

The formenctype attribute specifies how the form-data should be encoded when submitting it to the server (only for forms with method="post")

The formenctype attribute overrides the enctype attribute of the <form> element.

Note: The formenctype attribute is used with type="submit" and type="image".

Example

Send form-data that is default encoded (the first submit button), and encoded as "multipart/form-data" (the second submit button):

<form action="demo_post_enctype.asp" method="post">  First name: <input type="text" name="fname"><br>  <input type="submit" value="Submit">

139

Page 140: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

  <input type="submit" formenctype="multipart/form-data"  value="Submit as Multipart/form-data"></form>

<input> formmethod Attribute

The formmethod attribute defines the HTTP method for sending form-data to the action URL.

The formmethod attribute overrides the method attribute of the <form> element.

Note: The formmethod attribute can be used with type="submit" and type="image".

Example

The second submit button overrides the HTTP method of the form:

<form action="demo_form.asp" method="get">  First name: <input type="text" name="fname"><br>  Last name: <input type="text" name="lname"><br>  <input type="submit" value="Submit">  <input type="submit" formmethod="post" formaction="demo_post.asp"  value="Submit using POST"></form>

<input> formnovalidate Attribute

The novalidate attribute is a boolean attribute.

When present, it specifies that the <input> element should not be validated when submitted.

The formnovalidate attribute overrides the novalidate attribute of the <form> element.

Note: The formnovalidate attribute can be used with type="submit".

Example

A form with two submit buttons (with and without validation):

<form action="demo_form.asp">  E-mail: <input type="email" name="userid"><br>  <input type="submit" value="Submit"><br>  <input type="submit" formnovalidate value="Submit without validation"></form>

140

Page 141: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<input> formtarget Attribute

The formtarget attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form.

The formtarget attribute overrides the target attribute of the <form> element.

Note: The formtarget attribute can be used with type="submit" and type="image".

Example

A form with two submit buttons, with different target windows:

<form action="demo_form.asp">  First name: <input type="text" name="fname"><br>  Last name: <input type="text" name="lname"><br>  <input type="submit" value="Submit as normal">  <input type="submit" formtarget="_blank"  value="Submit to a new window"></form>

<input> height and width Attributes

The height and width attributes specify the height and width of an <input> element.

Note: The height and width attributes are only used with <input type="image">.

Tip: Always specify both the height and width attributes for images. If height and width are set, the space required for the image is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the image, and cannot reserve the appropriate space to it. The effect will be that the page layout will change during loading (while the images load).

Example

Define an image as the submit button, with height and width attributes:

<input type="image" src="img_submit.gif" alt="Submit" width="48" height="48">

<input> list Attribute

The list attribute refers to a <datalist> element that contains pre-defined options for an <input> element.

141

Page 142: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Example

An <input> element with pre-defined values in a <datalist>:

<input list="browsers">

<datalist id="browsers">  <option value="Internet Explorer">  <option value="Firefox">  <option value="Chrome">  <option value="Opera">  <option value="Safari"></datalist>

<input> min and max Attributes

The min and max attributes specify the minimum and maximum value for an <input> element.

Note: The min and max attributes works with the following input types: number, range, date, datetime, datetime-local, month, time and week.

Example

<input> elements with min and max values:

Enter a date before 1980-01-01:<input type="date" name="bday" max="1979-12-31">

Enter a date after 2000-01-01:<input type="date" name="bday" min="2000-01-02">

Quantity (between 1 and 5):<input type="number" name="quantity" min="1" max="5">

<input> multiple Attribute

The multiple attribute is a boolean attribute.

When present, it specifies that the user is allowed to enter more than one value in the <input> element.

Note: The multiple attribute works with the following input types: email, and file.

Example

142

Page 143: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

A file upload field that accepts multiple values:

Select images: <input type="file" name="img" multiple>

<input> pattern Attribute

The pattern attribute specifies a regular expression that the <input> element's value is checked against.

Note: The pattern attribute works with the following input types: text, search, url, tel, email, and password.

Tip: Use the global title attribute to describe the pattern to help the user.

Tip: Learn more about regular expressions in our JavaScript tutorial.

Example

An input field that can contain only three letters (no numbers or special characters):

Country code: <input type="text" name="country_code" pattern="[A-Za-z]{3}" title="Three letter country code">

<input> placeholder Attribute

The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format).

The short hint is displayed in the input field before the user enters a value.

Note: The placeholder attribute works with the following input types: text, search, url, tel, email, and password.

Example

An input field with a placeholder text:

<input type="text" name="fname" placeholder="First name">

<input> required Attribute

143

Page 144: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The required attribute is a boolean attribute.

When present, it specifies that an input field must be filled out before submitting the form.

Note: The required attribute works with the following input types: text, search, url, tel, email, password, date pickers, number, checkbox, radio, and file.

Example

A required input field:

Username: <input type="text" name="usrname" required>

<input> step Attribute

The step attribute specifies the legal number intervals for an <input> element.

Example: if step="3", legal numbers could be -3, 0, 3, 6, etc.

Tip: The step attribute can be used together with the max and min attributes to create a range of legal values.

Note: The step attribute works with the following input types: number, range, date, datetime, datetime-local, month, time and week.

Example

An input field with a specified legal number intervals:

<input type="number" name="points" step="3">

HTML5 <input> TagTag Description

<form> Defines an HTML form for user input

<input> Defines an input control

144

Page 145: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML5 Semantic Elements

Semantic = Meaning.

Semantic elements = Elements with meaning.

What are Semantic Elements?

145

Page 146: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

A semantic element clearly describes its meaning to both the browser and the developer.

Examples of non-semantic elements: <div> and <span> - Tells nothing about its content.

Examples of semantic elements: <form>, <table>, and <img> - Clearly defines its content.

Browser Support

       

Internet Explorer 9+, Firefox, Chrome, Safari and Opera supports the semantic elements described in this chapter.

Note: Internet Explorer 8 and earlier does not support these elements. However, there is a solution. Look at the end of this chapter.

New Semantic Elements in HTML5

Many of existing web sites today contains HTML code like this: <div id="nav">, <div class="header">, or <div id="footer">, to indicate navigation links, header, and footer.

HTML5 offers new semantic elements to clearly define different parts of a web page:

<header> <nav> <section> <article> <aside> <figcaption> <figure> <footer>

146

Page 147: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML5 <section> Element

The <section> element defines a section in a document.

According to W3C's HTML5 documentation: "A section is a thematic grouping of content, typically with a heading."

Example

<section>  <h1>WWF</h1>  <p>The World Wide Fund for Nature (WWF) is....</p></section>

HTML5 <article> Element

The <article> element specifies independent, self-contained content.

An article should make sense on its own and it should be possible to distribute it independently from the rest of the web site.

Examples of where an <article> element can be used:

Forum post Blog post News story Comment

147

Page 148: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Example

<article>  <h1>Internet Explorer 9</h1>  <p>Windows Internet Explorer 9 (abbreviated as IE9) was released to  the  public on March 14, 2011 at 21:00 PDT.....</p></article>

HTML5 <nav> Element

The <nav> element defines a set of navigation links.

The <nav> element is intended for large blocks of navigation links. However, not all links in a document should be inside a <nav> element!

Example

<nav><a href="/html/">HTML</a> |<a href="/css/">CSS</a> |<a href="/js/">JavaScript</a> |<a href="/jquery/">jQuery</a></nav>

HTML5 <aside> Element

The <aside> element defines some content aside from the content it is placed in (like a sidebar).

The aside content should be related to the surrounding content.

Example

<p>My family and I visited The Epcot center this summer.</p>

<aside>  <h4>Epcot Center</h4>  <p>The Epcot Center is a theme park in Disney World, Florida.</p></aside>

HTML5 <header> Element

The <header> element specifies a header for a document or section.

The <header> element should be used as a container for introductory content.

You can have several <header> elements in one document.

148

Page 149: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The following example defines a header for an article:

Example

<article>  <header>    <h1>Internet Explorer 9</h1>    <p><time pubdate datetime="2011-03-15"></time></p>  </header>  <p>Windows Internet Explorer 9 (abbreviated as IE9) was released to  the  public on March 14, 2011 at 21:00 PDT.....</p></article>

HTML5 <footer> Element

The <footer> element specifies a footer for a document or section.

A <footer> element should contain information about its containing element.

A footer typically contains the author of the document, copyright information, links to terms of use, contact information, etc.

You can have several <footer> elements in one document.

Example

<footer>  <p>Posted by: Hege Refsnes</p>  <p><time pubdate datetime="2012-03-01"></time></p></footer>

HTML5 <figure> and <figcaption> Elements

The <figure> tag specifies self-contained content, like illustrations, diagrams, photos, code listings, etc.

While the content of the <figure> element is related to the main flow, its position is independent of the main flow, and if removed it should not affect the flow of the document.

The <figcaption> tag defines a caption for a <figure> element.

The <figcaption> element can be placed as the first or last child of the <figure> element.

Example

<figure>  <img src="img_pulpit.jpg" alt="The Pulpit Rock" width="304" height="228">  <figcaption>Fig1. - The Pulpit Pock, Norway.</figcaption></figure>

149

Page 150: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Can We Start Using These Semantic Elements?

The elements explained above are all block elements (except <figcaption>).

To get these elements to work properly in all (older) major browsers, set the display property to block in your style sheet (this causes older browsers to render these elements correctly):

header, section, footer, aside, nav, article, figure{ display: block; }

Problem With Internet Explorer 8 And Earlier

IE8 and earlier does not know how to render CSS on elements that it doesn’t recognize. You cannot style <header>, <section>, <footer>, <aside>, <nav>, <article>, <figure>, or other new HTML5 elements.

Thankfully, Sjoerd Visscher has discovered a JavaScript workaround called HTML5 Shiv; to enable styling of HTML5 elements in versions of Internet Explorer prior to version 9.

You can download and read more about the HTML5 Shiv at: 

http://code.google.com/p/html5shiv/

To enable the HTML5 Shiv (after downloading), insert the following code into the <head> element:

<!--[if lt IE 9]><script src="html5shiv.js"></script><![endif]-->

That code above is a comment that only IE reads, for versions earlier than IE9. It must be placed in the <head> element because Internet Explorer needs to know about the elements before it renders them.

Semantic Elements in HTML5Tag Description

<article> Defines an article

<aside> Defines content aside from the page content

<figcaption> Defines a caption for a <figure> element

<figure> Specifies self-contained content, like illustrations, diagrams, photos, code listings, etc.

150

Page 151: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<footer> Defines a footer for a document or section

<header> Specifies a header for a document or section

<mark> Defines marked/highlighted text

<nav> Defines navigation links

<section> Defines a section in a document

<time> Defines a date/time

151

Page 152: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML5 Web Storage

HTML5 web storage, a better local storage than cookies.

What is HTML5 Web Storage?

With HTML5, web pages can store data locally within the user's browser.

Earlier, this was done with cookies. However, Web Storage is more secure and faster. The data is not included with every server request, but used ONLY when asked for. It is also possible to store large amounts of data, without affecting the website's performance.

The data is stored in key/value pairs, and a web page can only access data stored by itself.

Browser Support

       

Web storage is supported in Internet Explorer 8+, Firefox, Opera, Chrome, and Safari.

Note: Internet Explorer 7 and earlier versions, do not support web storage.

localStorage and sessionStorage 

There are two new objects for storing data on the client:

localStorage - stores data with no expiration date sessionStorage - stores data for one session

Before using web storage, check browser support for localStorage and sessionStorage:

if(typeof(Storage)!=="undefined")  {  // Yes! localStorage and sessionStorage support!  // Some code.....  }else  {  // Sorry! No web storage support..  }

152

Page 153: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The localStorage Object

The localStorage object stores the data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.

Example

localStorage.lastname="Smith";document.getElementById("result").innerHTML="Last name: "+ localStorage.lastname;

Example explained:

Create a localStorage key/value pair with key="lastname" and value="Smith" Retrieve the value of the "lastname" key and insert it into the element with id="result"

Tip: Key/value pairs are always stored as strings. Remember to convert them to another format when needed.

The following example counts the number of times a user has clicked a button. In this code the value string is converted to a number to be able to increase the counter:

Example

if (localStorage.clickcount)  {  localStorage.clickcount=Number(localStorage.clickcount)+1;  }else  {  localStorage.clickcount=1;  }document.getElementById("result").innerHTML="You have clicked the button " + localStorage.clickcount + " time(s).";

The sessionStorage Object

The sessionStorage object is equal to the localStorage object, except that it stores the data for only one session. The data is deleted when the user closes the browser window.

The following example counts the number of times a user has clicked a button, in the current session:

Example

if (sessionStorage.clickcount)  {  sessionStorage.clickcount=Number(sessionStorage.clickcount)+1;  }else

153

Page 154: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

  {  sessionStorage.clickcount=1;  }document.getElementById("result").innerHTML="You have clicked the button " + sessionStorage.clickcount + " time(s) in this session.";

154

Page 155: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML5 Application Cache

With HTML5 it is easy to make an offline version of a web application, by creating a cache manifest file.

What is Application Cache?

HTML5 introduces application cache, which means that a web application is cached, and accessible without an internet connection.

Application cache gives an application three advantages:

1. Offline browsing - users can use the application when they're offline2. Speed - cached resources load faster3. Reduced server load - the browser will only download updated/changed resources from the

server

Browser Support

       

Internet Explorer 10, Firefox, Chrome, Safari and Opera support Application cache.

HTML5 Cache Manifest Example

The example below shows an HTML document with a cache manifest (for offline browsing):

Example

<!DOCTYPE HTML><html manifest="demo.appcache">

<body>The content of the document......</body>

</html>

155

Page 156: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Cache Manifest Basics

To enable application cache, include the manifest attribute in the document's <html> tag:

<!DOCTYPE HTML><html manifest="demo.appcache">...</html>

Every page with the manifest attribute specified will be cached when the user visits it. If the manifest attribute is not specified, the page will not be cached (unless the page is specified directly in the manifest file).

The recommended file extension for manifest files is: ".appcache"

A manifest file needs to be served with the correct MIME-type, which is "text/cache-manifest". Must be configured on the web server.

The Manifest File

The manifest file is a simple text file, which tells the browser what to cache (and what to never cache).

The manifest file has three sections:

CACHE MANIFEST - Files listed under this header will be cached after they are downloaded for the first time

NETWORK - Files listed under this header require a connection to the server, and will never be cached

FALLBACK - Files listed under this header specifies fallback pages if a page is inaccessible

CACHE MANIFEST

The first line, CACHE MANIFEST, is required:

CACHE MANIFEST/theme.css/logo.gif/main.js

The manifest file above lists three resources: a CSS file, a GIF image, and a JavaScript file. When the manifest file is loaded, the browser will download the three files from the root directory of the web site. Then, whenever the user is not connected to the internet, the resources will still be available.

156

Page 157: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

NETWORK

The NETWORK section below specifies that the file "login.asp" should never be cached, and will not be available offline:

NETWORK:login.asp

An asterisk can be used to indicate that all other resources/files require an internet connection:

NETWORK:*

FALLBACK

The FALLBACK section below specifies that "offline.html" will be served in place of all files in the /html/ catalog, in case an internet connection cannot be established:

FALLBACK:/html/ /offline.html

Note: The first URI is the resource, the second is the fallback.

Updating the Cache

Once an application is cached, it remains cached until one of the following happens:

The user clears the browser's cache The manifest file is modified (see tip below) The application cache is programmatically updated

Example - Complete Cache Manifest FileCACHE MANIFEST# 2012-02-21 v1.0.0/theme.css/logo.gif/main.js

NETWORK:login.asp

FALLBACK:/html/ /offline.html

Tip: Lines starting with a "#" are comment lines, but can also serve another purpose. An application's cache is only updated when its manifest file changes. If you edit an image or change a

157

Page 158: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

JavaScript function, those changes will not be re-cached. Updating the date and version in a comment line is one way to make the browser re-cache your files.

Notes on Application Cache

Be careful with what you cache.

Once a file is cached, the browser will continue to show the cached version, even if you change the file on the server. To ensure the browser updates the cache, you need to change the manifest file.

Note: Browsers may have different size limits for cached data (some browsers have a 5MB limit per site).

158

Page 159: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML5 Web Workers

A web worker is a JavaScript running in the background, without affecting the performance of the page.

What is a Web Worker?

When executing scripts in an HTML page, the page becomes unresponsive until the script is finished.

A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to do whatever you want: clicking, selecting things, etc., while the web worker runs in the background.

Browser Support

       

Internet Explorer 10, Firefox, Chrome, Safari and Opera support Web workers.

HTML5 Web Workers Example

The example below creates a simple web worker that count numbers in the background:

Example

Count numbers:

Start Worker Stop Worker 

159

Page 160: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Check Web Worker Support

Before creating a web worker, check whether the user's browser supports it:

if(typeof(Worker)!=="undefined")  {  // Yes! Web worker support!  // Some code.....  }else  {  // Sorry! No Web Worker support..  }

Create a Web Worker File

Now, let's create our web worker in an external JavaScript.

Here, we create a script that counts. The script is stored in the "demo_workers.js" file:

var i=0;

function timedCount(){i=i+1;postMessage(i);setTimeout("timedCount()",500);}

timedCount();

The important part of the code above is the postMessage() method - which is used to posts a message back to the HTML page.

Note: Normally web workers are not used for such simple scripts, but for more CPU intensive tasks.

Create a Web Worker Object

Now that we have the web worker file, we need to call it from an HTML page.

The following lines checks if the worker already exists, if not - it creates a new web worker object and runs the code in "demo_workers.js":

if(typeof(w)=="undefined")  {  w=new Worker("demo_workers.js");  }

160

Page 161: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Then we can send and receive messages from the web worker.

Add an "onmessage" event listener to the web worker.

w.onmessage=function(event){document.getElementById("result").innerHTML=event.data;};

When the web worker posts a message, the code within the event listener is executed. The data from the web worker is stored in event.data.

Terminate a Web Worker

When a web worker object is created, it will continue to listen for messages (even after the external script is finished) until it is terminated.

To terminate a web worker, and free browser/computer resources, use the terminate() method:

w.terminate();

Full Web Worker Example Code

We have already seen the Worker code in the .js file. Below is the code for the HTML page:

Example

<!DOCTYPE html><html><body>

<p>Count numbers: <output id="result"></output></p><button onclick="startWorker()">Start Worker</button> <button onclick="stopWorker()">Stop Worker</button><br><br>

<script>var w;

function startWorker(){if(typeof(Worker)!=="undefined"){  if(typeof(w)=="undefined")    {    w=new Worker("demo_workers.js");    }  w.onmessage = function (event) {    document.getElementById("result").innerHTML=event.data;  };

161

Page 162: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

}else{document.getElementById("result").innerHTML="Sorry, your browser does not support Web Workers...";}}

function stopWorker(){ w.terminate();}</script>

</body></html>

Web Workers and the DOM

Since web workers are in external files, they do not have access to the following JavaScript objects:

The window object The document object The parent object

HTML5 Server-Sent Events

162

Page 163: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML5 Server-Sent Events allow a web page to get updates from a server.

Server-Sent Events - One Way Messaging

A server-sent event is when a web page automatically gets updates from a server.

This was also possible before, but the web page would have to ask if any updates were available. With server-sent events, the updates come automatically.

Examples: Facebook/Twitter updates, stock price updates, news feeds, sport results, etc.

Browser Support

       

Server-Sent Events are supported in all major browsers, except Internet Explorer.

Receive Server-Sent Event Notifications

The EventSource object is used to receive server-sent event notifications:

Example

var source=new EventSource("demo_sse.php");source.onmessage=function(event)  {  document.getElementById("result").innerHTML+=event.data + "<br>";  };

Example explained:

Create a new EventSource object, and specify the URL of the page sending the updates (in this example "demo_sse.php")

Each time an update is received, the onmessage event occurs When an onmessage event occurs, put the received data into the element with id="result"

Check Server-Sent Events Support

In the tryit example above there were some extra lines of code to check browser support for server-sent events:

163

Page 164: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

if(typeof(EventSource)!=="undefined")  {  // Yes! Server-sent events support!  // Some code.....  }else  {  // Sorry! No server-sent events support..  }

Server-Side Code Example

For the example above to work, you need a server capable of sending data updates (like PHP or ASP).

The server-side event stream syntax is simple. Set the "Content-Type" header to "text/event-stream". Now you can start sending event streams.

Code in PHP (demo_sse.php):

<?phpheader('Content-Type: text/event-stream');header('Cache-Control: no-cache');

$time = date('r');echo "data: The server time is: {$time}\n\n";flush();?>

Code in ASP (VB) (demo_sse.asp):

<%Response.ContentType="text/event-stream"Response.Expires=-1Response.Write("data: " & now())Response.Flush()%>

Code explained:

Set the "Content-Type" header to "text/event-stream" Specify that the page should not cache Output the data to send (Always start with "data: ") Flush the output data back to the web page

The EventSource Object

In the examples above we used the onmessage event to get messages. But other events are also available:

164

Page 165: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Events Description

onopen When a connection to the server is opened

onmessage When a message is received

onerror When an error occurs

HTML Multimedia

Multimedia on the web is sound, music, videos, and animations.

165

Page 166: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Modern web browsers have support for many multimedia formats.

What is Multimedia?

Multimedia comes in many different formats. It can be almost anything you can hear or see.

Examples: Pictures, music, sound, videos, records, films, animations, and more.

Modern Web pages have often embedded multimedia elements, and modern browsers have support for various multimedia formats.

In this tutorial you will learn about different multimedia formats.

Browser Support

The first Internet browsers had support for text only, and even the text support was limited to a single font in a single color. Then came browsers with support for colors, fonts and text styles, and support for pictures was added.

The support for sounds, animations, and videos is handled in different ways by various browsers. Some multimedia elements is supported, and some requires an extra helper program (a plug-in).

You will learn more about plug-ins in the next chapters.

Multimedia Formats

Multimedia elements (like sounds or videos) are stored in media files.

The most common way to discover the type of a file, is to look at the file extension. When a browser sees the file extension .htm or .html, it will treat the file as an HTML file. The .xml extension indicates an XML file, and the .css extension indicates a style sheet file. Pictures are recognized by extensions like .gif, .png and .jpg.

Multimedia files also have their own formats with different extensions like: .swf, .wav, .mp3, and .mp4.

Video Formats

166

Page 167: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

MP4 is the new and upcoming format for internet video. It is supported by YouTube, Flash players and HTML5.

Format File Description

AVI .avi AVI (Audio Video Interleave) was developed by Microsoft. AVI is supported by all computers running Windows, and by the most popular web browsers. It is a very common format on the Internet, but not always possible to play on non-Windows computers

WMV .wmv WMV (Windows Media Video) was developed by Microsoft. WMV is a common format on the Internet, but it cannot be played on non-Windows computer without an extra (free) component installed. Some later WMVs cannot play at all on non-Windows computers because no player is available

MPEG .mpg.mpeg

The MPEG (Moving Pictures Expert Group) format is the most popular format on the Internet. It is cross-platform, and supported by all major browsers

QuickTime

.mov QuickTime was developed by Apple. QuickTime is a common format on the Internet, but QuickTime movies cannot be played on a Windows computer without an extra (free) component installed.

RealVideo .rm.ram

RealVideo was developed by Real Media. RealVideo allows streaming of video (online video, Internet TV) with low bandwidths. Because of the low bandwidth priority, the quality is often reduced

Flash .swf.flv

Flash was developed by Macromedia. Flash requires an extra component to play. This component comes preinstalled with all major browsers

MP4 .mp4 Mpeg-4 (MP4) is the new format for the internet. YouTube recommends using MP4. YouTube accepts multiple formats, and then converts them all to .flv or .mp4 for distribution

Sound Formats

MP3 is the newest format for compressed recorded music. The term MP3 has become synonymous with digital music. If your website is about recorded music, the MP3 format is the choice.

Format File Description

167

Page 168: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

MIDI .mid.midi

MIDI (Musical Instrument Digital Interface) is a format for electronic music devices like synthesizers and PC sound cards. MIDI files do not contain sound, but digital musical instructions (notes) that can be played by electronics (like your PC's sound card).

Click here to play The Beatles.

Since MIDI files only contains instructions; they are extremely small. The example above is only 23K in size, but it plays for nearly 5 minutes. MIDI is supported by many software systems/platforms. MIDI is supported by all the most popular Internet browsers.

MP3 .mp3 MP3 files are actually the sound part of MPEG files. MPEG was originally developed for video by the Moving Pictures Experts Group. MP3 is the most popular format for music. The encoding system combines good compression (small files) with high quality

RealAudio

.rm

.ramRealAudio was developed Real Media. It allows streaming of audio (online music, Internet radio) with low bandwidths. Because of the low bandwidth priority, the quality is often reduced

WAV .wav WAVE (more known as WAV) was developed by IBM and Microsoft. WAVs are compatible with Windows, Macintosh, and Linux operating systems

WMA .wma WMA (Windows Media Audio), compares in quality to MP3, and is compatible with most players, except the iPod. WMA files can be delivered as a continuous flow of data, which makes it practical for use in Internet radio or on-line music.

HTML - The <object> Element

168

Page 169: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The purpose of the <object> element is to support HTML helpers (plug-ins).

HTML Helpers (Plug-ins)

A helper application is a small computer program that extends the standard functionality of the browser. Helper applications are also called plug-ins.

Plug-ins are often used by browsers to play audio and video.

Examples of well-known plug-ins are Adobe Flash Player and QuickTime.

Plug-ins can be added to Web pages through the <object> tag or the <embed> tag. 

Most plug-ins allow manual (or programmed) control over settings for volume, rewind, forward, pause, stop, and play.

What is The Best Way to Play Audio/Video in HTML?

For the best way to embed audio or video in your Web page, please read the next chapters.

QuickTime - Play WAV AudioExample

<object width="420" height="360"classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="liar.wav"><param name="controller" value="true"></object>

QuickTime - Play MP4 VideoExample

169

Page 170: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<object width="420" height="360"classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"><param name="src" value="movie.mp4"><param name="controller" value="true"></object>

Adobe Flash Player - Play SWF VideoExample

<object width="400" height="40"classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"><param name="SRC" value="bookmark.swf"><embed src="bookmark.swf" width="400" height="40"></embed></object>

Windows Media Player - Play WMV Movie

The example below shows the suggested code used to display a Windows Media file.

Example

<object width="100%" height="100%"type="video/x-ms-asf" url="3d.wmv" data="3d.wmv"classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"><param name="url" value="3d.wmv"><param name="filename" value="3d.wmv"><param name="autostart" value="1"><param name="uiMode" value="full"><param name="autosize" value="1"><param name="playcount" value="1"> <embed type="application/x-mplayer2" src="3d.wmv" width="100%" height="100%" autostart="true" showcontrols="true" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"></embed></object>

Plug-ins

170

Page 171: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Plug-ins can be used for many purposes: to display maps, scan for viruses, verify your bank id, and much more. The restrictions are few.

HTML Audio

171

Page 172: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Sounds can be played in HTML by many different methods.

Problems, Problems, and Solutions

Playing audio in HTML is not easy!

You must know a lot of tricks to make sure your audio files will play in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac , iPad, iPhone).

Using Plug-ins

A plug-in is a small computer program that extends the standard functionality of the browser.

Plug-ins can be added to HTML pages using the <object> tag or the <embed> tag. 

These tags define containers for resources (normally non-HTML resources), which, depending on the type, will either be displayed by the browsers, or by an external plug-in.

Using The<embed> Element

The <embed> tag defines a container for external (non-HTML) content.

The following code fragment should play an MP3 file embedded in a web page:

Example

<embed height="50" width="100" src="horse.mp3">

Problems:

Different browsers support different audio formats If a browser does not support the file format, the audio will not play without a plug-in If the plug-in is not installed on the users' computer, the audio will not play If you convert the file to another format, it will still not play in all browsers

Using The<object> Element

The <object tag> tag can also define a container for external (non-HTML) content.

The following code fragment should play an MP3 file embedded in a web page:

172

Page 173: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Example

<object height="50" width="100" data="horse.mp3"></object>

Problems:

Different browsers support different audio formats If a browser does not support the file format, the audio will not play without a plug-in If the plug-in is not installed on the users' computer, the audio will not play If you convert the file to another format, it will still not play in all browsers

Using the HTML5 <audio> Element

The HTML5 <audio> tag defines sound, such as music or other audio streams.

The <audio> element works in all modern browsers.

The following example uses the <audio> tag, and specifies one MP3 file (for Internet Explorer, Chrome, and Safari), and one OGG file (for Firefox and Opera). If anything fails it displays a text:

Example

<audio controls>  <source src="horse.mp3" type="audio/mpeg">  <source src="horse.ogg" type="audio/ogg">  Your browser does not support this audio format.</audio>

Problems:

You must convert the audio files into different formats The <audio> element does not work in older browsers

The Best HTML Solution

The example below uses the HTML5 <audio> element and tries to play the audio either as MP3 or OGG. If it fails, the code "falls back" to try the <embed> element:

Example

<audio controls height="100" width="100">  <source src="horse.mp3" type="audio/mpeg">  <source src="horse.ogg" type="audio/ogg">  <embed height="50" width="100" src="horse.mp3"></audio>

173

Page 174: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Problems:

You must convert the audio files into different formats The <embed> element cannot "fall-back" to display an error message

Yahoo Media Player - An Easy Way to Add Audio to Your Site

The FREE Yahoo Media Player is definitely a favorite: You simply let Yahoo do the job of playing your songs.

It plays MP3 and a lot of other formats. You can add it to your page (or blog) with a single line of code, and easily turn your HTML page into a professional playlist:

Example

<a href="horse.mp3">Play Sound</a>

<script src="http://mediaplayer.yahoo.com/latest"></script>

To use it, insert the following JavaScript at the bottom of your web page:

<script src="http://mediaplayer.yahoo.com/latest"></script>

Then, simply link to your audio files in your HTML, and the JavaScript code automatically creates a play button for each song:

<a href="song1.mp3">Play Song 1</a><a href="song2.wav">Play Song 2</a>...

...

The Yahoo Media Player presents your readers with a small play button instead of a full player. However, when you click the button, a full player pops up. Note that the player is always docked and ready at the bottom of the window. Just click on it to slide it out.

Using A Hyperlink

If a web page includes a hyperlink to a media file, most browsers will use a "helper application" to play the file.

174

Page 175: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The following code fragment displays a link to an MP3 file. If a user clicks on the link, the browser will launch a helper application to play the file:

Example

<a href="horse.mp3">Play the sound</a>

A Note About Inline Sounds

When sound is included in a web page, or as part of a web page, it is called inline sound.

If you plan to use inline sounds, be aware that many people will find it annoying. Also note that some users might have turned off the inline sound option in their browser.

Our best advice is to include inline sounds only in pages where the user expects to hear sounds. An example of this is a page which opens after the user has clicked on a link to hear a recording.

HTML Multimedia Tag

New : New tags in HTML5.

Tag Description

<embed> Defines an embedded object

<object> Defines an embedded object

<param> Defines a parameter for an object

<audio>New Defines sound content

<video>New Defines a video or movie

<source>New Defines multiple media resources for media elements (<video> and <audio>)

<track>New Defines text tracks for media elements (<video> and <audio>)

175

Page 176: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Videos

Videos can be played in HTML by many different methods.

Playing Videos in HTML

176

Page 177: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Example

<video width="320" height="240" controls>  <source src="movie.mp4" type="video/mp4">  <source src="movie.ogg" type="video/ogg">  <source src="movie.webm" type="video/webm">  <object data="movie.mp4" width="320" height="240">    <embed src="movie.swf" width="320" height="240">  </object> </video>

Problems, Problems, and Solutions

Displaying videos in HTML is not easy!

You must add a lot of tricks to make sure your video will play in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac , iPad, iPhone).

In this chapter W3Schools summarizes the problems and the solutions.

The <embed> Element

The purpose of the <embed> tag is to embed multimedia elements in HTML pages.

The following HTML fragment displays a Flash video embedded in a web page:

Example

<embed src="intro.swf" height="200" width="200">

Problems

If the browser does not support Flash, the video will not play iPad and iPhone do not support Flash videos If you convert the video to another format, it will still not play in all browsers

Using The<object> Element

The purpose of the <object> tag is to embed multimedia elements in HTML pages.

The following HTML fragment displays a Flash video embedded in a web page:

Example

<object data="intro.swf" height="200" width="200"></object>

177

Page 178: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Problems:

If the browser does not support Flash, the video will not play iPad and iPhone do not support Flash videos If you convert the video to another format, it will still not play in all browsers

Using the HTML5 <video> Element

The HTML5 <video> tag defines a video or movie.

The <video> element works in all modern browsers.

The following HTML fragment displays a video in OGG, MP4, or WEBM format:

Example

<video width="320" height="240" controls>  <source src="movie.mp4" type="video/mp4">  <source src="movie.ogg" type="video/ogg">  <source src="movie.webm" type="video/webm">Your browser does not support the video tag.</video>

Problems:

You must convert your videos to many different formats The <video> element does not work in older browsers

The Best HTML Solution

The example below uses 4 different video formats. The HTML 5 <video> element tries to play the video either in MP4, OGG, or WEBM format. If this fails, the code "falls back" to try the <object> element. If this also fails, it "falls back" to the <embed> element:

HTML 5 + <object> + <embed>

<video width="320" height="240" controls>  <source src="movie.mp4" type="video/mp4">  <source src="movie.ogg" type="video/ogg">  <source src="movie.webm" type="video/webm">  <object data="movie.mp4" width="320" height="240">    <embed src="movie.swf" width="320" height="240">  </object> </video>

Problems:

178

Page 179: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

You must convert your videos to many different formats

The YouTube Solution

The easiest way to display videos in HTML is to use YouTube (see next chapter)!

Using A Hyperlink

If a web page includes a hyperlink to a media file, most browsers will use a "helper application" to play the file.

The following code fragment displays a link to a Flash video. If a user clicks on the link, the browser will launch a helper application to play the file:

Example

<a href="intro.swf">Play a video file</a>

A Note About Inline Videos

When a video is included in a web page it is called inline video.

If you plan to use inline videos, be aware that many people find it annoying. Also note that some users might have turned off the inline video option in their browser.

Our best advice is to include inline videos only in pages where the user expects to see a video. An example of this is a page which opens after the user has clicked on a link to see the video.

HTML Multimedia Tags

New : New tags in HTML5.

Tag Description

<embed> Defines an embedded object

<object> Defines an embedded object

<param> Defines a parameter for an object

179

Page 180: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<audio>New Defines sound content

<video>New Defines a video or movie

<source>New Defines multiple media resources for media elements (<video> and <audio>)

<track>New Defines text tracks for media elements (<video> and <audio>)

HTML - YouTube Videos

The easiest way to play videos (others or your own) in HTML is to use YouTube.

Playing a YouTube Video in HTML

180

Page 181: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

If you want to play a video in a web page, you can upload the video to YouTube and insert the proper HTML code to display the video:

Example - YouTube iFrame

<iframe width="420" height="345"src="http://www.youtube.com/embed/XGSy3_Czz8k"></iframe>

Example - YouTube Embedded

<embed>width="420" height="345"src="http://www.youtube.com/v/XGSy3_Czz8k"type="application/x-shockwave-flash"></embed>

HTML Reference - (HTML5 Compliant)

Ordered Alphabetically

New : New tags in HTML5.

Tag Description

181

Page 182: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<!--...--> Defines a comment

<!DOCTYPE> Defines the document type

<a> Defines a hyperlink

<abbr> Defines an abbreviation

<acronym> Not supported in HTML5. Defines an acronym

<address> Defines contact information for the author/owner of a document

<applet> Not supported in HTML5. Deprecated in HTML 4.01. Defines an embedded applet

<area> Defines an area inside an image-map

<article>New Defines an article

<aside>New Defines content aside from the page content

<audio>New Defines sound content

<b> Defines bold text

<base> Specifies the base URL/target for all relative URLs in a document

<basefont> Not supported in HTML5. Deprecated in HTML 4.01. Specifies a default color, size, and font for all text in a document

<bdi>New Isolates a part of text that might be formatted in a different direction from other text outside it

<bdo> Overrides the current text direction

<big> Not supported in HTML5. Defines big text

182

Page 183: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<blockquote> Defines a section that is quoted from another source

<body> Defines the document's body

<br> Defines a single line break

<button> Defines a clickable button

<canvas>New Used to draw graphics, on the fly, via scripting (usually JavaScript)

<caption> Defines a table caption

<center> Not supported in HTML5. Deprecated in HTML 4.01. Defines centered text

<cite> Defines the title of a work

<code> Defines a piece of computer code

<col> Specifies column properties for each column within a <colgroup> element

<colgroup> Specifies a group of one or more columns in a table for formatting

<command>New Defines a command button that a user can invoke

<datalist>New Specifies a list of pre-defined options for input controls

<dd> Defines a description/value of a term in a description list

<del> Defines text that has been deleted from a document

<details>New Defines additional details that the user can view or hide

<dfn> Defines a definition term

<dialog>New Defines a dialog box or window

<dir> Not supported in HTML5. Deprecated in HTML 4.01. Defines a directory

183

Page 184: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

list

<div> Defines a section in a document

<dl> Defines a description list

<dt> Defines a term/name in a description list

<em> Defines emphasized text

<embed>New Defines a container for an external (non-HTML) application

<fieldset> Groups related elements in a form

<figcaption>New Defines a caption for a <figure> element

<figure>New Specifies self-contained content

<font> Not supported in HTML5. Deprecated in HTML 4.01. Defines font, color, and size for text

<footer>New Defines a footer for a document or section

<form> Defines an HTML form for user input

<frame> Not supported in HTML5. Defines a window (a frame) in a frameset

<frameset> Not supported in HTML5. Defines a set of frames

<h1> to <h6> Defines HTML headings

<head> Defines information about the document

<header>New Defines a header for a document or section

<hr> Defines a thematic change in the content

<html> Defines the root of an HTML document

184

Page 185: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<i> Defines a part of text in an alternate voice or mood

<iframe> Defines an inline frame

<img> Defines an image

<input> Defines an input control

<ins> Defines a text that has been inserted into a document

<kbd> Defines keyboard input

<keygen>New Defines a key-pair generator field (for forms)

<label> Defines a label for an <input> element

<legend> Defines a caption for a <fieldset> element

<li> Defines a list item

<link> Defines the relationship between a document and an external resource (most used to link to style sheets)

<map> Defines a client-side image-map

<mark>New Defines marked/highlighted text

<menu> Defines a list/menu of commands

<meta> Defines metadata about an HTML document

<meter>New Defines a scalar measurement within a known range (a gauge)

<nav>New Defines navigation links

<noframes> Not supported in HTML5. Defines an alternate content for users that do not support frames

<noscript> Defines an alternate content for users that do not support client-side

185

Page 186: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

scripts

<object> Defines an embedded object

<ol> Defines an ordered list

<optgroup> Defines a group of related options in a drop-down list

<option> Defines an option in a drop-down list

<output>New Defines the result of a calculation

<p> Defines a paragraph

<param> Defines a parameter for an object

<pre> Defines preformatted text

<progress>New Represents the progress of a task

<q> Defines a short quotation

<rp>New Defines what to show in browsers that do not support ruby annotations

<rt>New Defines an explanation/pronunciation of characters (for East Asian typography)

<ruby>New Defines a ruby annotation (for East Asian typography)

<s> Defines text that is no longer correct

<samp> Defines sample output from a computer program

<script> Defines a client-side script

<section>New Defines a section in a document

<select> Defines a drop-down list

186

Page 187: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<small> Defines smaller text

<source>New Defines multiple media resources for media elements (<video> and <audio>)

<span> Defines a section in a document

<strike> Not supported in HTML5. Deprecated in HTML 4.01. Defines strikethrough text

<strong> Defines important text

<style> Defines style information for a document

<sub> Defines subscripted text

<summary>New Defines a visible heading for a <details> element

<sup> Defines superscripted text

<table> Defines a table

<tbody> Groups the body content in a table

<td> Defines a cell in a table

<textarea> Defines a multiline input control (text area)

<tfoot> Groups the footer content in a table

<th> Defines a header cell in a table

<thead> Groups the header content in a table

<time>New Defines a date/time

<title> Defines a title for the document

<tr> Defines a row in a table

187

Page 188: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<track>New Defines text tracks for media elements (<video> and <audio>)

<tt> Not supported in HTML5. Defines teletype text

<u> Defines text that should be stylistically different from normal text

<ul> Defines an unordered list

<var> Defines a variable

<video>New Defines a video or movie

<wbr>New Defines a possible line-break

HTML Reference - (HTML5 Compliant)

Ordered by Function

New : New tags in HTML5.

188

Page 189: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Tag Description

Basic

<!DOCTYPE> Defines the document type

<html> Defines an HTML document

<title> Defines a title for the document

<body> Defines the document's body

<h1> to <h6> Defines HTML headings

<p> Defines a paragraph

<br> Inserts a single line break

<hr> Defines a thematic change in the content

<!--...--> Defines a comment

Formatting

<acronym> Not supported in HTML5. Defines an acronym

<abbr> Defines an abbreviation

<address> Defines contact information for the author/owner of a document/article

<b> Defines bold text

<bdi>New Isolates a part of text that might be formatted in a different direction from other text outside it

<bdo> Overrides the current text direction

<big> Not supported in HTML5. Defines big text

189

Page 190: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<blockquote> Defines a section that is quoted from another source

<center> Not supported in HTML5. Deprecated in HTML 4.01. Defines centered text

<cite> Defines the title of a work

<code> Defines a piece of computer code

<del> Defines text that has been deleted from a document

<dfn> Defines a definition term

<em> Defines emphasized text

<font> Not supported in HTML5. Deprecated in HTML 4.01. Defines font, color, and size for text

<i> Defines a part of text in an alternate voice or mood

<ins> Defines a text that has been inserted into a document

<kbd> Defines keyboard input

<mark>New Defines marked/highlighted text

<meter>New Defines a scalar measurement within a known range (a gauge)

<pre> Defines preformatted text

<progress>New Represents the progress of a task

<q> Defines a short quotation

<rp>New Defines what to show in browsers that do not support ruby annotations

<rt>New Defines an explanation/pronunciation of characters (for East Asian typography)

190

Page 191: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<ruby>New Defines a ruby annotation (for East Asian typography)

<s> Defines text that is no longer correct

<samp> Defines sample output from a computer program

<small> Defines smaller text

<strike> Not supported in HTML5. Deprecated in HTML 4.01. Defines strikethrough text

<strong> Defines important text

<sub> Defines subscripted text

<sup> Defines superscripted text

<time>New Defines a date/time

<tt> Not supported in HTML5. Defines teletype text

<u> Defines text that should be stylistically different from normal text

<var> Defines a variable

<wbr>New Defines a possible line-break

Forms

<form> Defines an HTML form for user input

<input> Defines an input control

<textarea> Defines a multiline input control (text area)

<button> Defines a clickable button

<select> Defines a drop-down list

191

Page 192: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<optgroup> Defines a group of related options in a drop-down list

<option> Defines an option in a drop-down list

<label> Defines a label for an <input> element

<fieldset> Groups related elements in a form

<legend> Defines a caption for a <fieldset> element

<datalist>New Specifies a list of pre-defined options for input controls

<keygen>New Defines a key-pair generator field (for forms)

<output>New Defines the result of a calculation

Frames

<frame> Not supported in HTML5. Defines a window (a frame) in a frameset

<frameset> Not supported in HTML5. Defines a set of frames

<noframes> Not supported in HTML5. Defines an alternate content for users that do not support frames

<iframe> Defines an inline frame

Images

<img> Defines an image

<map> Defines a client-side image-map

<area> Defines an area inside an image-map

<canvas>New Used to draw graphics, on the fly, via scripting (usually JavaScript)

<figcaption>New Defines a caption for a <figure> element

192

Page 193: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<figure>New Specifies self-contained content

Audio/Video

<audio>New Defines sound content

<source>New Defines multiple media resources for media elements (<video> and <audio>)

<track>New Defines text tracks for media elements (<video> and <audio>)

<video>New Defines a video or movie

Links

<a> Defines a hyperlink

<link> Defines the relationship between a document and an external resource (most used to link to style sheets)

<nav>New Defines navigation links

Lists

<ul> Defines an unordered list

<ol> Defines an ordered list

<li> Defines a list item

<dir> Not supported in HTML5. Deprecated in HTML 4.01. Defines a directory list

<dl> Defines a description list

<dt> Defines a term/name in a description list

<dd> Defines a description of a term/name in a description list

193

Page 194: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<menu> Defines a list/menu of commands

<command>New Defines a command button that a user can invoke

Tables

<table> Defines a table

<caption> Defines a table caption

<th> Defines a header cell in a table

<tr> Defines a row in a table

<td> Defines a cell in a table

<thead> Groups the header content in a table

<tbody> Groups the body content in a table

<tfoot> Groups the footer content in a table

<col> Specifies column properties for each column within a <colgroup> element

<colgroup> Specifies a group of one or more columns in a table for formatting

Style/Sections

<style> Defines style information for a document

<div> Defines a section in a document

<span> Defines a section in a document

<header>New Defines a header for a document or section

<footer>New Defines a footer for a document or section

194

Page 195: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<section>New Defines a section in a document

<article>New Defines an article

<aside>New Defines content aside from the page content

<details>New Defines additional details that the user can view or hide

<dialog>New Defines a dialog box or window

<summary>New Defines a visible heading for a <details> element

Meta Info

<head> Defines information about the document

<meta> Defines metadata about an HTML document

<base> Specifies the base URL/target for all relative URLs in a document

<basefont> Not supported in HTML5. Deprecated in HTML 4.01. Specifies a default color, size, and font for all text in a document

Programming

<script> Defines a client-side script

<noscript> Defines an alternate content for users that do not support client-side scripts

<applet> Not supported in HTML5. Deprecated in HTML 4.01. Defines an embedded applet

<embed>New Defines a container for an external (non-HTML) application

<object> Defines an embedded object

<param> Defines a parameter for an object

195

Page 196: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Global Attributes

HTML attributes give elements meaning and context.

The global attributes below can be used on any HTML element.

HTML Global Attributes

New : New global attributes in HTML5.

196

Page 197: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Attribute Description

accesskey Specifies a shortcut key to activate/focus an element

class Specifies one or more classnames for an element (refers to a class in a style sheet)

contenteditableNew Specifies whether the content of an element is editable or not

contextmenuNew Specifies a context menu for an element. The context menu appears when a user right-clicks on the element

dir Specifies the text direction for the content in an element

draggableNew Specifies whether an element is draggable or not

dropzoneNew Specifies whether the dragged data is copied, moved, or linked, when dropped

hiddenNew Specifies that an element is not yet, or is no longer, relevant

id Specifies a unique id for an element

lang Specifies the language of the element's content

spellcheckNew Specifies whether the element is to have its spelling and grammar checked or not

style Specifies an inline CSS style for an element

tabindex Specifies the tabbing order of an element

title Specifies extra information about an element

translateNew Specifies whether an element's value are to be translated when the page is localized, or not.

197

Page 198: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Event Attributes

Global Event Attributes

HTML 4 added the ability to let events trigger actions in a browser, like starting a JavaScript when a user clicks on an element.

To learn more about programming events, please visit our JavaScript tutorial.

Below are the global event attributes that can be added to HTML elements to define event actions.

New : New event attributes in HTML5.

198

Page 199: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Window Event Attributes

Events triggered for the window object (applies to the <body> tag):

Attribute Value

Description

onafterprintNew script Script to be run after the document is printed

onbeforeprintNew script Script to be run before the document is printed

onbeforeunloadNew script Script to be run before the document is unloaded

onerrorNew script Script to be run when an error occur

onhaschangeNew script Script to be run when the document has changed

onload script Fires after the page is finished loading

onmessageNew script Script to be run when the message is triggered

onofflineNew script Script to be run when the document goes offline

ononlineNew script Script to be run when the document comes online

onpagehideNew script Script to be run when the window is hidden

onpageshowNew script Script to be run when the window becomes visible

onpopstateNew script Script to be run when the window's history changes

onredoNew script Script to be run when the document performs a redo

onresizeNew script Fires when the browser window is resized

onstorageNew script Script to be run when a Web Storage area is updated

onundoNew script Script to be run when the document performs an undo

199

Page 200: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

onunload script Fires once a page has unloaded (or the browser window has been closed)

Form Events

Events triggered by actions inside a HTML form (applies to almost all HTML elements, but is most used in form elements):

Attribute Value Description

onblur script Fires the moment that the element loses focus

onchange script Fires the moment when the value of the element is changed

oncontextmenuNew script Script to be run when a context menu is triggered

onfocus script Fires the moment when the element gets focus

onformchangeNew script Script to be run when a form changes

onforminputNew script Script to be run when a form gets user input

oninputNew script Script to be run when an element gets user input

oninvalidNew script Script to be run when an element is invalid

onreset script Fires when the Reset button in a form is clickedNot supported in HTML5

onselect script Fires after some text has been selected in an element

onsubmit script Fires when a form is submitted

Keyboard Events

200

Page 201: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Attribute Value Description

onkeydown script Fires when a user is pressing a key

onkeypress script Fires when a user presses a key

onkeyup script Fires when a user releases a key

Mouse Events

Events triggered by a mouse, or similar user actions:

Attribute Value Description

onclick script Fires on a mouse click on the element

ondblclick script Fires on a mouse double-click on the element

ondragNew script Script to be run when an element is dragged

ondragendNew script Script to be run at the end of a drag operation

ondragenterNew script Script to be run when an element has been dragged to a valid drop target

ondragleaveNew script Script to be run when an element leaves a valid drop target

ondragoverNew script Script to be run when an element is being dragged over a valid drop target

ondragstartNew script Script to be run at the start of a drag operation

ondropNew script Script to be run when dragged element is being dropped

onmousedown script Fires when a mouse button is pressed down on an element

onmousemove script Fires when the mouse pointer moves over an element

201

Page 202: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

onmouseout script Fires when the mouse pointer moves out of an element

onmouseover script Fires when the mouse pointer moves over an element

onmouseup script Fires when a mouse button is released over an element

onmousewheelNew script Script to be run when the mouse wheel is being rotated

onscrollNew script Script to be run when an element's scrollbar is being scrolled

Media Events

Events triggered by medias like videos, images and audio (applies to all HTML elements, but is most common in media elements, like <audio>, <embed>, <img>, <object>, and <video>):

Attribute Value Description

onabort script Script to be run on abort

oncanplayNew script Script to be run when a file is ready to start playing (when it has buffered enough to begin)

oncanplaythroughNew script Script to be run when a file can be played all the way to the end without pausing for buffering

ondurationchangeNew script Script to be run when the length of the media changes

onemptiedNew script Script to be run when something bad happens and the file is suddenly unavailable (like unexpectedly disconnects)

onendedNew script Script to be run when the media has reach the end (a useful event for messages like "thanks for listening")

onerrorNew script Script to be run when an error occurs when the file is being loaded

onloadeddataNew script Script to be run when media data is loaded

202

Page 203: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

onloadedmetadataNew script Script to be run when meta data (like dimensions and duration) are loaded

onloadstartNew script Script to be run just as the file begins to load before anything is actually loaded

onpauseNew script Script to be run when the media is paused either by the user or programmatically

onplayNew script Script to be run when the media is ready to start playing

onplayingNew script Script to be run when the media actually has started playing

onprogressNew script Script to be run when the browser is in the process of getting the media data

onratechangeNew script Script to be run each time the playback rate changes (like when a user switches to a slow motion or fast forward mode)

onreadystatechangeNew

script Script to be run each time the ready state changes (the ready state tracks the state of the media data)

onseekedNew script Script to be run when the seeking attribute is set to false indicating that seeking has ended

onseekingNew script Script to be run when the seeking attribute is set to true indicating that seeking is active

onstalledNew script Script to be run when the browser is unable to fetch the media data for whatever reason

onsuspendNew script Script to be run when fetching the media data is stopped before it is completely loaded for whatever reason

ontimeupdateNew script Script to be run when the playing position has changed (like when the user fast forwards to a different point in the media)

onvolumechangeNew script Script to be run each time the volume is changed which (includes setting the volume to "mute")

onwaitingNew script Script to be run when the media has paused but is expected to

203

Page 204: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

resume (like when the media pauses to buffer more data)

HTML Canvas Reference

Description

The HTML5 <canvas> tag is used to draw graphics, on the fly, via scripting (usually JavaScript).

However, the <canvas> element has no drawing abilities of its own (it is only a container for graphics) - you must use a script to actually draw the graphics.

The getContext() method returns an object that provides methods and properties for drawing on the canvas.

This reference will cover the properties and methods of the getContext("2d") object, which can be used to draw text, lines, boxes, circles, and more - on the canvas.

Browser Support

204

Page 205: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

       

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support <canvas> and its properties and methods.

Note: Internet Explorer 8 and earlier versions, do not support the <canvas> element.

Colors, Styles, and ShadowsProperty Description

fillStyle Sets or returns the color, gradient, or pattern used to fill the drawing

strokeStyle Sets or returns the color, gradient, or pattern used for strokes

shadowColor Sets or returns the color to use for shadows

shadowBlur Sets or returns the blur level for shadows

shadowOffsetX Sets or returns the horizontal distance of the shadow from the shape

shadowOffsetY Sets or returns the vertical distance of the shadow from the shape

Method Description

createLinearGradient() Creates a linear gradient (to use on canvas content)

createPattern() Repeats a specified element in the specified direction

createRadialGradient() Creates a radial/circular gradient (to use on canvas content)

addColorStop() Specifies the colors and stop positions in a gradient object

Line StylesProperty Description

205

Page 206: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

lineCap Sets or returns the style of the end caps for a line

lineJoin Sets or returns the type of corner created, when two lines meet

lineWidth Sets or returns the current line width

miterLimit Sets or returns the maximum miter length

RectanglesMethod Description

rect() Creates a rectangle

fillRect() Draws a "filled" rectangle

strokeRect() Draws a rectangle (no fill)

clearRect() Clears the specified pixels within a given rectangle

PathsMethod Description

fill() Fills the current drawing (path)

stroke() Actually draws the path you have defined

beginPath() Begins a path, or resets the current path

moveTo() Moves the path to the specified point in the canvas, without creating a line

closePath() Creates a path from the current point back to the starting point

lineTo() Adds a new point and creates a line from that point to the last specified point in the canvas

206

Page 207: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

clip() Clips a region of any shape and size from the original canvas

quadraticCurveTo() Creates a quadratic Bézier curve

bezierCurveTo() Creates a cubic Bézier curve

arc() Creates an arc/curve (used to create circles, or parts of circles)

arcTo() Creates an arc/curve between two tangents

isPointInPath() Returns true if the specified point is in the current path, otherwise false

TransformationsMethod Description

scale() Scales the current drawing bigger or smaller

rotate() Rotates the current drawing

translate() Remaps the (0,0) position on the canvas

transform() Replaces the current transformation matrix for the drawing

setTransform() Resets the current transform to the identity matrix. Then runs transform()

TextProperty Description

font Sets or returns the current font properties for text content

textAlign Sets or returns the current alignment for text content

textBaseline Sets or returns the current text baseline used when drawing text

Method Description

207

Page 208: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

fillText() Draws "filled" text on the canvas

strokeText() Draws text on the canvas (no fill)

measureText() Returns an object that contains the width of the specified text

Image DrawingMethod Description

drawImage() Draws an image, canvas, or video onto the canvas

Pixel ManipulationProperty Description

width Returns the width of an ImageData object

height Returns the height of an ImageData object

data Returns an object that contains image data of a specified ImageData object

Method Description

createImageData() Creates a new, blank ImageData object

getImageData() Returns an ImageData object that copies the pixel data for the specified rectangle on a canvas

putImageData() Puts the image data (from a specified ImageData object) back onto the canvas

CompositingProperty Description

208

Page 209: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

globalAlpha Sets or returns the current alpha or transparency value of the drawing

globalCompositeOperation Sets or returns how a new image are drawn onto an existing image

OtherMethod Description

save() Saves the state of the current context

restore() Returns previously saved path state and attributes

createEvent()

getContext()

toDataURL()

HTML Audio/Video DOM Reference

« Previous

Next Reference »

HTML Audio and Video DOM Reference

The HTML5 DOM has methods, properties, and events for the <audio> and <video> elements.

These methods, properties, and events allow you to manipulate <audio> and <video> elements using JavaScript.

HTML Audio/Video MethodsMethod Description

209

Page 210: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

addTextTrack() Adds a new text track to the audio/video

canPlayType() Checks if the browser can play the specified audio/video type

load() Re-loads the audio/video element

play() Starts playing the audio/video

pause() Pauses the currently playing audio/video

HTML Audio/Video PropertiesProperty Description

audioTracks Returns an AudioTrackList object representing available audio tracks

autoplay Sets or returns if the audio/video should start playing as soon as it is loaded

buffered Returns a TimeRanges object representing the buffered parts of the audio/video

controller Returns the MediaController object representing the current media controller of the audio/video

controls Sets or returns if the audio/video should display controls (like play/pause etc.)

crossOrigin Sets or returns the CORS settings of the audio/video

currentSrc Returns the URL of the current audio/video

currentTime Sets or returns the current playback position in the audio/video (in seconds)

defaultMuted Sets or returns if the audio/video is muted by default

defaultPlaybackRate Sets or returns the default speed of the audio/video playback

duration Returns the length of the current audio/video (in seconds)

ended Returns if the playback of the audio/video has ended or not

210

Page 211: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

error Returns a MediaError object representing the error state of the audio/video

loop Sets or returns if the audio/video should start over again when finished

mediaGroup Sets or returns a the group the audio/video belongs to (used to link multiple audio/video elements)

muted Sets or returns if the audio/video is muted or not

networkState Returns the current network state of the audio/video

paused Sets or returns if the audio/video is paused or not

playbackRate Sets or returns the speed of the audio/video playback

played Returns a TimeRanges object representing the played parts of the audio/video

preload Sets or returns if the audio/video should be loaded when the page loads

readyState Returns the current ready state of the audio/video

seekable Returns a TimeRanges object representing the seekable parts of the audio/video

seeking Returns if the user is currently seeking in the audio/video

src Sets or returns the current source of the audio/video element

startDate Returns a Date object representing the current time offset

textTracks Returns a TextTrackList object representing the available text tracks

videoTracks Returns a VideoTrackList object representing the available video tracks

volume Sets or returns the volume of the audio/video

HTML Audio/Video EventsEvent Description

211

Page 212: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

abort Fires when the loading of an audio/video is aborted

canplay Fires when the browser can start playing the audio/video

canplaythrough Fires when the browser can play through the audio/video without stopping for buffering

durationchange Fires when the duration of the audio/video is changed

emptied Fires when the current playlist is empty

ended Fires when the current playlist is ended

error Fires when an error occurred during the loading of an audio/video

loadeddata Fires when the browser has loaded the current frame of the audio/video

loadedmetadata Fires when the browser has loaded meta data for the audio/video

loadstart Fires when the browser starts looking for the audio/video

pause Fires when the audio/video has been paused

play Fires when the audio/video has been started or is no longer paused

playing Fires when the audio/video is ready to play after having been paused or stopped for buffering

progress Fires when the browser is downloading the audio/video

ratechange Fires when the playing speed of the audio/video is changed

seeked Fires when the user is finished moving/skipping to a new position in the audio/video

seeking Fires when the user starts moving/skipping to a new position in the audio/video

stalled Fires when the browser is trying to get media data, but data is not available

suspend Fires when the browser is intentionally not getting media data

212

Page 213: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

timeupdate Fires when the current playback position has changed

volumechange Fires when the volume has been changed

waiting Fires when the video stops because it needs to buffer the next frame

HTML Elements and Valid DOCTYPES

« Previous

Next Reference »

HTML Elements - Valid DOCTYPES

The table below lists all HTML elements, and shows what !DOCTYPE each element appears in.

HTML 4.01 / XHTML 1.0

Tag HTML5 Transitional Strict Frameset XHTML 1.1

<a> Yes Yes Yes Yes Yes

<abbr> Yes Yes Yes Yes Yes

<acronym> No Yes Yes Yes Yes

<address> Yes Yes Yes Yes Yes

<applet> No Yes No Yes No

<area> Yes Yes Yes Yes No

<article> Yes No No No No

<aside> Yes No No No No

<audio> Yes No No No No

213

Page 214: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<b> Yes Yes Yes Yes Yes

<base> Yes Yes Yes Yes Yes

<basefont> No Yes No Yes No

<bdi> Yes No No No No

<bdo> Yes Yes Yes Yes No

<big> No Yes Yes Yes Yes

<blockquote> Yes Yes Yes Yes Yes

<body> Yes Yes Yes Yes Yes

<br> Yes Yes Yes Yes Yes

<button> Yes Yes Yes Yes Yes

<canvas> Yes No No No No

<caption> Yes Yes Yes Yes Yes

<center> No Yes No Yes No

<cite> Yes Yes Yes Yes Yes

<code> Yes Yes Yes Yes Yes

<col> Yes Yes Yes Yes No

<colgroup> Yes Yes Yes Yes No

<command> Yes No No No No

<datalist> Yes No No No No

214

Page 216: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<head> Yes Yes Yes Yes Yes

<header> Yes No No No No

<hgroup> Yes No No No No

<hr> Yes Yes Yes Yes Yes

<html> Yes Yes Yes Yes Yes

<i> Yes Yes Yes Yes Yes

<iframe> Yes Yes No Yes No

<img> Yes Yes Yes Yes Yes

<input> Yes Yes Yes Yes Yes

<ins> Yes Yes Yes Yes No

<kbd> Yes Yes Yes Yes Yes

<keygen> Yes No No No No

<label> Yes Yes Yes Yes Yes

<legend> Yes Yes Yes Yes Yes

<li> Yes Yes Yes Yes Yes

<link> Yes Yes Yes Yes Yes

<map> Yes Yes Yes Yes No

<mark> Yes No No No No

<menu> Yes Yes No Yes No

216

Page 217: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<meta> Yes Yes Yes Yes Yes

<meter> Yes No No No No

<nav> Yes No No No No

<noframes> No Yes No Yes No

<noscript> Yes Yes Yes Yes Yes

<object> Yes Yes Yes Yes Yes

<ol> Yes Yes Yes Yes Yes

<optgroup> Yes Yes Yes Yes Yes

<option> Yes Yes Yes Yes Yes

<output> Yes No No No No

<p> Yes Yes Yes Yes Yes

<param> Yes Yes Yes Yes Yes

<pre> Yes Yes Yes Yes Yes

<progress> Yes No No No No

<q> Yes Yes Yes Yes Yes

<rp> Yes No No No No

<rt> Yes No No No No

<ruby> Yes No No No No

<s> Yes Yes No Yes No

217

Page 218: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<samp> Yes Yes Yes Yes Yes

<script> Yes Yes Yes Yes Yes

<section> Yes No No No No

<select> Yes Yes Yes Yes Yes

<small> Yes Yes Yes Yes Yes

<source> Yes No No No No

<span> Yes Yes Yes Yes Yes

<strike> No Yes No Yes No

<strong> Yes Yes Yes Yes Yes

<style> Yes Yes Yes Yes Yes

<sub> Yes Yes Yes Yes Yes

<summary> Yes No No No No

<sup> Yes Yes Yes Yes Yes

<table> Yes Yes Yes Yes Yes

<tbody> Yes Yes Yes Yes No

<td> Yes Yes Yes Yes Yes

<textarea> Yes Yes Yes Yes Yes

<tfoot> Yes Yes Yes Yes No

<th> Yes Yes Yes Yes Yes

218

Page 219: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<thead> Yes Yes Yes Yes No

<time> Yes No No No No

<title> Yes Yes Yes Yes Yes

<tr> Yes Yes Yes Yes Yes

<track> Yes No No No No

<tt> No Yes Yes Yes Yes

<u> No Yes No Yes No

<ul> Yes Yes Yes Yes Yes

<var> Yes Yes Yes Yes Yes

<video> Yes No No No No

<wbr> Yes No No No No

219

Page 220: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML Color Names

Color Names Supported by All Browsers

140 color names are defined in the HTML and CSS color specification (17 standard colors plus 123 more). The table below lists them all, along with their hexadecimal values.

 Tip: The 17 standard colors are: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple, red, silver, teal, white, and yellow.

Click on a color name (or a hex value) to view the color as the background-color along with different text colors:

Color Name HEX Color Shades Mix

AliceBlue #F0F8FF Shades Mix

AntiqueWhite #FAEBD7 Shades Mix

Aqua #00FFFF Shades Mix

Aquamarine #7FFFD4 Shades Mix

220

Page 221: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Azure #F0FFFF Shades Mix

Beige #F5F5DC Shades Mix

Bisque #FFE4C4 Shades Mix

Black #000000 Shades Mix

BlanchedAlmond #FFEBCD Shades Mix

Blue #0000FF Shades Mix

BlueViolet #8A2BE2 Shades Mix

Brown #A52A2A Shades Mix

BurlyWood #DEB887 Shades Mix

CadetBlue #5F9EA0 Shades Mix

Chartreuse #7FFF00 Shades Mix

Chocolate #D2691E Shades Mix

Coral #FF7F50 Shades Mix

CornflowerBlue #6495ED Shades Mix

Cornsilk #FFF8DC Shades Mix

Crimson #DC143C Shades Mix

Cyan #00FFFF Shades Mix

DarkBlue #00008B Shades Mix

DarkCyan #008B8B Shades Mix

221

Page 222: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

DarkGoldenRod #B8860B Shades Mix

DarkGray #A9A9A9 Shades Mix

DarkGreen #006400 Shades Mix

DarkKhaki #BDB76B Shades Mix

DarkMagenta #8B008B Shades Mix

DarkOliveGreen #556B2F Shades Mix

DarkOrange #FF8C00 Shades Mix

DarkOrchid #9932CC Shades Mix

DarkRed #8B0000 Shades Mix

DarkSalmon #E9967A Shades Mix

DarkSeaGreen #8FBC8F Shades Mix

DarkSlateBlue #483D8B Shades Mix

DarkSlateGray #2F4F4F Shades Mix

DarkTurquoise #00CED1 Shades Mix

DarkViolet #9400D3 Shades Mix

DeepPink #FF1493 Shades Mix

DeepSkyBlue #00BFFF Shades Mix

DimGray #696969 Shades Mix

DodgerBlue #1E90FF Shades Mix

222

Page 223: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

FireBrick #B22222 Shades Mix

FloralWhite #FFFAF0 Shades Mix

ForestGreen #228B22 Shades Mix

Fuchsia #FF00FF Shades Mix

Gainsboro #DCDCDC Shades Mix

GhostWhite #F8F8FF Shades Mix

Gold #FFD700 Shades Mix

GoldenRod #DAA520 Shades Mix

Gray #808080 Shades Mix

Green #008000 Shades Mix

GreenYellow #ADFF2F Shades Mix

HoneyDew #F0FFF0 Shades Mix

HotPink #FF69B4 Shades Mix

IndianRed #CD5C5C Shades Mix

Indigo #4B0082 Shades Mix

Ivory #FFFFF0 Shades Mix

Khaki #F0E68C Shades Mix

Lavender #E6E6FA Shades Mix

LavenderBlush #FFF0F5 Shades Mix

223

Page 224: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

LawnGreen #7CFC00 Shades Mix

LemonChiffon #FFFACD Shades Mix

LightBlue #ADD8E6 Shades Mix

LightCoral #F08080 Shades Mix

LightCyan #E0FFFF Shades Mix

LightGoldenRodYellow #FAFAD2 Shades Mix

LightGray #D3D3D3 Shades Mix

LightGreen #90EE90 Shades Mix

LightPink #FFB6C1 Shades Mix

LightSalmon #FFA07A Shades Mix

LightSeaGreen #20B2AA Shades Mix

LightSkyBlue #87CEFA Shades Mix

LightSlateGray #778899 Shades Mix

LightSteelBlue #B0C4DE Shades Mix

LightYellow #FFFFE0 Shades Mix

Lime #00FF00 Shades Mix

LimeGreen #32CD32 Shades Mix

Linen #FAF0E6 Shades Mix

Magenta #FF00FF Shades Mix

224

Page 225: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Maroon #800000 Shades Mix

MediumAquaMarine #66CDAA Shades Mix

MediumBlue #0000CD Shades Mix

MediumOrchid #BA55D3 Shades Mix

MediumPurple #9370DB Shades Mix

MediumSeaGreen #3CB371 Shades Mix

MediumSlateBlue #7B68EE Shades Mix

MediumSpringGreen #00FA9A Shades Mix

MediumTurquoise #48D1CC Shades Mix

MediumVioletRed #C71585 Shades Mix

MidnightBlue #191970 Shades Mix

MintCream #F5FFFA Shades Mix

MistyRose #FFE4E1 Shades Mix

Moccasin #FFE4B5 Shades Mix

NavajoWhite #FFDEAD Shades Mix

Navy #000080 Shades Mix

OldLace #FDF5E6 Shades Mix

Olive #808000 Shades Mix

OliveDrab #6B8E23 Shades Mix

225

Page 226: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Orange #FFA500 Shades Mix

OrangeRed #FF4500 Shades Mix

Orchid #DA70D6 Shades Mix

PaleGoldenRod #EEE8AA Shades Mix

PaleGreen #98FB98 Shades Mix

PaleTurquoise #AFEEEE Shades Mix

PaleVioletRed #DB7093 Shades Mix

PapayaWhip #FFEFD5 Shades Mix

PeachPuff #FFDAB9 Shades Mix

Peru #CD853F Shades Mix

Pink #FFC0CB Shades Mix

Plum #DDA0DD Shades Mix

PowderBlue #B0E0E6 Shades Mix

Purple #800080 Shades Mix

Red #FF0000 Shades Mix

RosyBrown #BC8F8F Shades Mix

RoyalBlue #4169E1 Shades Mix

SaddleBrown #8B4513 Shades Mix

Salmon #FA8072 Shades Mix

226

Page 227: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

SandyBrown #F4A460 Shades Mix

SeaGreen #2E8B57 Shades Mix

SeaShell #FFF5EE Shades Mix

Sienna #A0522D Shades Mix

Silver #C0C0C0 Shades Mix

SkyBlue #87CEEB Shades Mix

SlateBlue #6A5ACD Shades Mix

SlateGray #708090 Shades Mix

Snow #FFFAFA Shades Mix

SpringGreen #00FF7F Shades Mix

SteelBlue #4682B4 Shades Mix

Tan #D2B48C Shades Mix

Teal #008080 Shades Mix

Thistle #D8BFD8 Shades Mix

Tomato #FF6347 Shades Mix

Turquoise #40E0D0 Shades Mix

Violet #EE82EE Shades Mix

Wheat #F5DEB3 Shades Mix

White #FFFFFF Shades Mix

227

Page 229: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Selected color: 

#E60000

#FF0000

#FF1919

#FF3333

#FF4D4D

#FF6666

#FF8080

#FF9999

#FFB2B2

#FFCCCC

#FFE6E6

#FFFFFF

HTML Color Mixer Mix two colors and see the result.

Select colors:Top color: 

  #FF0000

  #F2000D

  #E6001A

  #D90026

  #CC0033

  #BF0040

  #B2004C

  #A60059

  #990066

#FF0000

#0000FF

229

#FF0000

#FF0000

Page 230: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

  #8C0073

  #800080

  #73008C

  #660099

  #5900A6

  #4D00B2

  #4000BF

HTML ASCII Reference

The ASCII character-set is used to send information between computers on the Internet.

The ASCII Character Set

ASCII stands for the "American Standard Code for Information Interchange".  It was designed in the early 60's, as a standard character-set for computers and hardware devices like teleprinters and tapedrives.

ASCII is a 7-bit character set containing 128 characters.

It contains the numbers from 0-9, the uppercase and lowercase English letters from A to Z, and some special characters.

The character-sets used in modern computers, HTML, and Internet are all based on ASCII.

230

#0000FF

Page 231: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

The following table lists the 128 ASCII characters and their equivalent HTML entity codes.

ASCII Printable CharactersASCII Character HTML Entity Code Description

&#32; space

! &#33; exclamation mark

" &#34; quotation mark

# &#35; number sign

$ &#36; dollar sign

% &#37; percent sign

& &#38; ampersand

' &#39; apostrophe

( &#40; left parenthesis

) &#41; right parenthesis

* &#42; asterisk

+ &#43; plus sign

, &#44; comma

- &#45; hyphen

. &#46; period

/ &#47; slash

231

Page 232: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

0 &#48; digit 0

1 &#49; digit 1

2 &#50; digit 2

3 &#51; digit 3

4 &#52; digit 4

5 &#53; digit 5

6 &#54; digit 6

7 &#55; digit 7

8 &#56; digit 8

9 &#57; digit 9

: &#58; colon

; &#59; semicolon

< &#60; less-than

= &#61; equals-to

> &#62; greater-than

? &#63; question mark

@ &#64; at sign

A &#65; uppercase A

B &#66; uppercase B

232

Page 233: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

C &#67; uppercase C

D &#68; uppercase D

E &#69; uppercase E

F &#70; uppercase F

G &#71; uppercase G

H &#72; uppercase H

I &#73; uppercase I

J &#74; uppercase J

K &#75; uppercase K

L &#76; uppercase L

M &#77; uppercase M

N &#78; uppercase N

O &#79; uppercase O

P &#80; uppercase P

Q &#81; uppercase Q

R &#82; uppercase R

S &#83; uppercase S

T &#84; uppercase T

U &#85; uppercase U

233

Page 234: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

V &#86; uppercase V

W &#87; uppercase W

X &#88; uppercase X

Y &#89; uppercase Y

Z &#90; uppercase Z

[ &#91; left square bracket

\ &#92; backslash

] &#93; right square bracket

^ &#94; caret

_ &#95; underscore

` &#96; grave accent

a &#97; lowercase a

b &#98; lowercase b

c &#99; lowercase c

d &#100; lowercase d

e &#101; lowercase e

f &#102; lowercase f

g &#103; lowercase g

h &#104; lowercase h

234

Page 235: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

i &#105; lowercase i

j &#106; lowercase j

k &#107; lowercase k

l &#108; lowercase l

m &#109; lowercase m

n &#110; lowercase n

o &#111; lowercase o

p &#112; lowercase p

q &#113; lowercase q

r &#114; lowercase r

s &#115; lowercase s

t &#116; lowercase t

u &#117; lowercase u

v &#118; lowercase v

w &#119; lowercase w

x &#120; lowercase x

y &#121; lowercase y

z &#122; lowercase z

{ &#123; left curly brace

235

Page 236: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

| &#124; vertical bar

} &#125; right curly brace

~ &#126; Tilde

ASCII Device Control Characters

The ASCII device control characters were originally designed to control hardware devices.

Control characters have nothing to do inside an HTML document.

ASCII Character HTML Entity Code Description

NUL &#00; null character

SOH &#01; start of header

STX &#02; start of text

ETX &#03; end of text

EOT &#04; end of transmission

ENQ &#05; Enquiry

ACK &#06; Acknowledge

BEL &#07; bell (ring)

BS &#08; Backspace

HT &#09; horizontal tab

LF &#10; line feed

236

Page 237: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

VT &#11; vertical tab

FF &#12; form feed

CR &#13; carriage return

SO &#14; shift out

SI &#15; shift in

DLE &#16; data link escape

DC1 &#17; device control 1

DC2 &#18; device control 2

DC3 &#19; device control 3

DC4 &#20; device control 4

NAK &#21; negative acknowledge

SYN &#22; Synchronize

ETB &#23; end transmission block

CAN &#24; Cancel

EM &#25; end of medium

SUB &#26; Substitute

ESC &#27; Escape

FS &#28; file separator

237

Page 238: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

GS &#29; group separator

RS &#30; record separator

US &#31; unit separator

DEL &#127; delete (rubout)

HTML ISO-8859-1 Reference

Modern browsers supports several character-sets:

ASCII character set Standard ISO character sets Mathematical symbols, Greek letters, and other symbols

ISO-8859-1

ISO-8859-1 is the default character set in most browsers.

The first 128 characters of ISO-8859-1 is the original ASCII character-set (the numbers from 0-9, the uppercase and lowercase English alphabet, and some special characters).

The higher part of ISO-8859-1 (codes from 160-255) contains the characters used in Western European countries and some commonly used special characters.

Entities are used to implement reserved characters or to express characters that cannot easily be entered with the keyboard.

Reserved Characters in HTML

Some characters are reserved in HTML and XHTML. For example, you cannot use the greater than or less than signs within your text because the browser could mistake them for markup.

HTML and XHTML processors must support the five special characters listed in the table below:

238

Page 239: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Character Entity Number Entity Name Description

" &#34; &quot; quotation mark

' &#39; &apos; apostrophe

& &#38; &amp; Ampersand

< &#60; &lt; less-than

> &#62; &gt; greater-than

Note: Entity names are case sensitive!

ISO 8859-1 SymbolsCharacter Entity Number Entity Name Description

&#160; &nbsp; non-breaking space

¡ &#161; &iexcl; inverted exclamation mark

¢ &#162; &cent; Cent

£ &#163; &pound; Pound

¤ &#164; &curren; Currency

¥ &#165; &yen; Yen

¦ &#166; &brvbar; broken vertical bar

§ &#167; &sect; Section

¨ &#168; &uml; spacing diaeresis

© &#169; &copy; Copyright

ª &#170; &ordf; feminine ordinal indicator

« &#171; &laquo; angle quotation mark (left)

¬ &#172; &not; Negation

&#173; &shy; soft hyphen

® &#174; &reg; registered trademark

¯ &#175; &macr; spacing macron

239

Page 240: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

° &#176; &deg; Degree

± &#177; &plusmn; plus-or-minus

² &#178; &sup2; superscript 2

³ &#179; &sup3; superscript 3

´ &#180; &acute; spacing acute

µ &#181; &micro; Micro

¶ &#182; &para; Paragraph

· &#183; &middot; middle dot

¸ &#184; &cedil; spacing cedilla

¹ &#185; &sup1; superscript 1

º &#186; &ordm; masculine ordinal indicator

» &#187; &raquo; angle quotation mark (right)

¼ &#188; &frac14; fraction ¼

½ &#189; &frac12; fraction ½

¾ &#190; &frac34; fraction ¾

¿ &#191; &iquest; inverted question mark

× &#215; &times; Multiplication

÷ &#247; &divide; Division

ISO 8859-1 CharactersCharacter Entity Number Entity Name Description

À &#192; &Agrave; capital a, grave accent

Á &#193; &Aacute; capital a, acute accent

 &#194; &Acirc; capital a, circumflex accent

à &#195; &Atilde; capital a, tilde

Ä &#196; &Auml; capital a, umlaut mark

Å &#197; &Aring; capital a, ring

Æ &#198; &AElig; capital ae

240

Page 241: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Ç &#199; &Ccedil; capital c, cedilla

È &#200; &Egrave; capital e, grave accent

É &#201; &Eacute; capital e, acute accent

Ê &#202; &Ecirc; capital e, circumflex accent

Ë &#203; &Euml; capital e, umlaut mark

Ì &#204; &Igrave; capital i, grave accent

Í &#205; &Iacute; capital i, acute accent

Î &#206; &Icirc; capital i, circumflex accent

Ï &#207; &Iuml; capital i, umlaut mark

Ð &#208; &ETH; capital eth, Icelandic

Ñ &#209; &Ntilde; capital n, tilde

Ò &#210; &Ograve; capital o, grave accent

Ó &#211; &Oacute; capital o, acute accent

Ô &#212; &Ocirc; capital o, circumflex accent

Õ &#213; &Otilde; capital o, tilde

Ö &#214; &Ouml; capital o, umlaut mark

Ø &#216; &Oslash; capital o, slash

Ù &#217; &Ugrave; capital u, grave accent

Ú &#218; &Uacute; capital u, acute accent

Û &#219; &Ucirc; capital u, circumflex accent

Ü &#220; &Uuml; capital u, umlaut mark

Ý &#221; &Yacute; capital y, acute accent

Þ &#222; &THORN; capital THORN, Icelandic

ß &#223; &szlig; small sharp s, German

à &#224; &agrave; small a, grave accent

á &#225; &aacute; small a, acute accent

â &#226; &acirc; small a, circumflex accent

241

Page 242: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

ã &#227; &atilde; small a, tilde

ä &#228; &auml; small a, umlaut mark

å &#229; &aring; small a, ring

æ &#230; &aelig; small ae

ç &#231; &ccedil; small c, cedilla

è &#232; &egrave; small e, grave accent

é &#233; &eacute; small e, acute accent

ê &#234; &ecirc; small e, circumflex accent

ë &#235; &euml; small e, umlaut mark

ì &#236; &igrave; small i, grave accent

í &#237; &iacute; small i, acute accent

î &#238; &icirc; small i, circumflex accent

ï &#239; &iuml; small i, umlaut mark

ð &#240; &eth; small eth, Icelandic

ñ &#241; &ntilde; small n, tilde

ò &#242; &ograve; small o, grave accent

ó &#243; &oacute; small o, acute accent

ô &#244; &ocirc; small o, circumflex accent

õ &#245; &otilde; small o, tilde

ö &#246; &ouml; small o, umlaut mark

ø &#248; &oslash; small o, slash

ù &#249; &ugrave; small u, grave accent

ú &#250; &uacute; small u, acute accent

û &#251; &ucirc; small u, circumflex accent

ü &#252; &uuml; small u, umlaut mark

ý &#253; &yacute; small y, acute accent

þ &#254; &thorn; small thorn, Icelandic

242

Page 243: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

ÿ &#255; &yuml; small y, umlaut mark

HTML Symbol Entities Reference

HTML Symbol Entities

This entity reference includes mathematical symbols, Greek characters, various arrows, technical symbols and shapes.

Note: Entity names are case sensitive.

Math Symbols Supported by HTMLCharacter Entity Number Entity Name Description

∀ &#8704; &forall; for all

∂ &#8706; &part; part

∃ &#8707; &exist; exists

243

Page 244: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

∅ &#8709; &empty; empty

∇ &#8711; &nabla; nabla

∈ &#8712; &isin; isin

∉ &#8713; &notin; notin

∋ &#8715; &ni; ni

∏ &#8719; &prod; prod

∑ &#8721; &sum; sum

− &#8722; &minus; minus

∗ &#8727; &lowast; lowast

√ &#8730; &radic; square root

∝ &#8733; &prop; proportional to

∞ &#8734; &infin; infinity

∠ &#8736; &ang; angle

∧ &#8743; &and; and

∨ &#8744; &or; or

∩ &#8745; &cap; cap

∪ &#8746; &cup; cup

∫ &#8747; &int; integral

∴ &#8756; &there4; therefore

244

Page 245: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

∼ &#8764; &sim; similar to

≅ &#8773; &cong; congruent to

≈ &#8776; &asymp; almost equal

≠ &#8800; &ne; not equal

≡ &#8801; &equiv; equivalent

≤ &#8804; &le; less or equal

≥ &#8805; &ge; greater or equal

⊂ &#8834; &sub; subset of

⊃ &#8835; &sup; superset of

⊄ &#8836; &nsub; not subset of

⊆ &#8838; &sube; subset or equal

⊇ &#8839; &supe; superset or equal

⊕ &#8853; &oplus; circled plus

⊗ &#8855; &otimes; circled times

⊥ &#8869; &perp; perpendicular

⋅ &#8901; &sdot; dot operator

Greek Letters Supported by HTMLCharacter Entity Number Entity Name Description

Α &#913; &Alpha; Alpha

245

Page 246: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Β &#914; &Beta; Beta

Γ &#915; &Gamma; Gamma

Δ &#916; &Delta; Delta

Ε &#917; &Epsilon; Epsilon

Ζ &#918; &Zeta; Zeta

Η &#919; &Eta; Eta

Θ &#920; &Theta; Theta

Ι &#921; &Iota; Iota

Κ &#922; &Kappa; Kappa

Λ &#923; &Lambda; Lambda

Μ &#924; &Mu; Mu

Ν &#925; &Nu; Nu

Ξ &#926; &Xi; Xi

Ο &#927; &Omicron; Omicron

Π &#928; &Pi; Pi

Ρ &#929; &Rho; Rho

undefined Sigmaf

Σ &#931; &Sigma; Sigma

Τ &#932; &Tau; Tau

246

Page 247: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Υ &#933; &Upsilon; Upsilon

Φ &#934; &Phi; Phi

Χ &#935; &Chi; Chi

Ψ &#936; &Psi; Psi

Ω &#937; &Omega; Omega

α &#945; &alpha; alpha

β &#946; &beta; beta

γ &#947; &gamma; gamma

δ &#948; &delta; delta

ε &#949; &epsilon; epsilon

ζ &#950; &zeta; zeta

η &#951; &eta; eta

θ &#952; &theta; theta

ι &#953; &iota; iota

κ &#954; &kappa; kappa

λ &#955; &lambda; lambda

μ &#956; &mu; mu

ν &#957; &nu; nu

ξ &#958; &xi; xi

247

Page 248: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

ο &#959; &omicron; omicron

π &#960; &pi; pi

ρ &#961; &rho; rho

ς &#962; &sigmaf; sigmaf

σ &#963; &sigma; sigma

τ &#964; &tau; tau

υ &#965; &upsilon; upsilon

φ &#966; &phi; phi

χ &#967; &chi; chi

ψ &#968; &psi; psi

ω &#969; &omega; omega

ϑ &#977; &thetasym; theta symbol

ϒ &#978; &upsih; upsilon symbol

ϖ &#982; &piv; pi symbol

Other Entities Supported by HTMLCharacter Entity Number Entity Name Description

Π&#338; &OElig; capital ligature OE

œ &#339; &oelig; small ligature oe

Š &#352; &Scaron; capital S with caron

248

Page 249: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

š &#353; &scaron; small S with caron

Ÿ &#376; &Yuml; capital Y with diaeres

ƒ &#402; &fnof; f with hook

ˆ &#710; &circ; modifier letter circumflex accent

˜ &#732; &tilde; small tilde

  &#8194; &ensp; en space

  &#8195; &emsp; em space

  &#8201; &thinsp; thin space

&#8204; &zwnj; zero width non-joiner

&#8205; &zwj; zero width joiner

&#8206; &lrm; left-to-right mark

&#8207; &rlm; right-to-left mark

– &#8211; &ndash; en dash

— &#8212; &mdash; em dash

‘ &#8216; &lsquo; left single quotation mark

’ &#8217; &rsquo; right single quotation mark

‚ &#8218; &sbquo; single low-9 quotation mark

“ &#8220; &ldquo; left double quotation mark

” &#8221; &rdquo; right double quotation mark

249

Page 250: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

„ &#8222; &bdquo; double low-9 quotation mark

† &#8224; &dagger; dagger

‡ &#8225; &Dagger; double dagger

• &#8226; &bull; bullet

… &#8230; &hellip; horizontal ellipsis

‰ &#8240; &permil; per mille

′ &#8242; &prime; minutes

″ &#8243; &Prime; seconds

‹ &#8249; &lsaquo; single left angle quotation

› &#8250; &rsaquo; single right angle quotation

‾ &#8254; &oline; overline

€ &#8364; &euro; euro

™ &#8482; or &#153; &trade; trademark

← &#8592; &larr; left arrow

↑ &#8593; &uarr; up arrow

→ &#8594; &rarr; right arrow

↓ &#8595; &darr; down arrow

↔ &#8596; &harr; left right arrow

↵ &#8629; &crarr; carriage return arrow

250

Page 251: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

⌈ &#8968; &lceil; left ceiling

⌉ &#8969; &rceil; right ceiling

⌊ &#8970; &lfloor; left floor

⌋ &#8971; &rfloor; right floor

◊ &#9674; &loz; lozenge

♠ &#9824; &spades; spade

♣ &#9827; &clubs; club

♥ &#9829; &hearts; heart

♦ &#9830; &diams; diamond

251

Page 252: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTML URL Encoding Reference

URL encoding converts characters into a format that can be transmitted over the Internet.

URL - Uniform Resource Locator

Web browsers request pages from web servers by using a URL.

The URL is the address of a web page, like: http://www.w3schools.com.

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 a valid ASCII format.

URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits.

URLs cannot contain spaces. URL encoding normally replaces a space with a + sign.

252

Page 253: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Try It Yourself

If you click the "Submit" button below, the browser will URL encode the input before it is sent to the server. A page at the server will display the received input.

 

Try some other input and click Submit again.

URL Encoding Functions

In JavaScript, PHP, and ASP there are functions that can be used to URL encode a string.

In JavaScript you can use the encodeURI() function. PHP has the rawurlencode() function and ASP has the Server.URLEncode() function.

Click the "URL Encode" button to see how the JavaScript function encodes the text.

 

Note: The JavaScript function encodes space as %20.

URL Encoding ReferenceASCII Character URL-encoding

space %20

! %21

" %22

# %23

$ %24

% %25

253

Hello Günter Submit

Hello Günter

Page 254: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

& %26

' %27

( %28

) %29

* %2A

+ %2B

, %2C

- %2D

. %2E

/ %2F

0 %30

1 %31

2 %32

3 %33

4 %34

5 %35

6 %36

7 %37

8 %38

254

Page 255: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

9 %39

: %3A

; %3B

< %3C

= %3D

> %3E

? %3F

@ %40

A %41

B %42

C %43

D %44

E %45

F %46

G %47

H %48

I %49

J %4A

K %4B

255

Page 256: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

L %4C

M %4D

N %4E

O %4F

P %50

Q %51

R %52

S %53

T %54

U %55

V %56

W %57

X %58

Y %59

Z %5A

[ %5B

\ %5C

] %5D

^ %5E

256

Page 257: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

_ %5F

` %60

a %61

b %62

c %63

d %64

e %65

f %66

g %67

h %68

i %69

j %6A

k %6B

l %6C

m %6D

n %6E

o %6F

p %70

q %71

257

Page 258: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

r %72

s %73

t %74

u %75

v %76

w %77

x %78

y %79

z %7A

{ %7B

| %7C

} %7D

~ %7E

%7F

` %80

� %81

‚ %82

ƒ %83

„ %84

258

Page 259: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

… %85

† %86

‡ %87

ˆ %88

‰ %89

Š %8A

‹ %8B

Π%8C

� %8D

Ž %8E

� %8F

� %90

‘ %91

’ %92

“ %93

” %94

• %95

– %96

— %97

259

Page 260: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

˜ %98

™ %99

š %9A

› %9B

œ %9C

� %9D

ž %9E

Ÿ %9F

%A0

¡ %A1

¢ %A2

£ %A3

¤ %A4

¥ %A5

¦ %A6

§ %A7

¨ %A8

© %A9

ª %AA

260

Page 261: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

« %AB

¬ %AC

%AD

® %AE

¯ %AF

° %B0

± %B1

² %B2

³ %B3

´ %B4

µ %B5

¶ %B6

· %B7

¸ %B8

¹ %B9

º %BA

» %BB

¼ %BC

½ %BD

261

Page 262: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

¾ %BE

¿ %BF

À %C0

Á %C1

 %C2

à %C3

Ä %C4

Å %C5

Æ %C6

Ç %C7

È %C8

É %C9

Ê %CA

Ë %CB

Ì %CC

Í %CD

Î %CE

Ï %CF

Ð %D0

262

Page 263: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Ñ %D1

Ò %D2

Ó %D3

Ô %D4

Õ %D5

Ö %D6

× %D7

Ø %D8

Ù %D9

Ú %DA

Û %DB

Ü %DC

Ý %DD

Þ %DE

ß %DF

à %E0

á %E1

â %E2

ã %E3

263

Page 264: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

ä %E4

å %E5

æ %E6

ç %E7

è %E8

é %E9

ê %EA

ë %EB

ì %EC

í %ED

î %EE

ï %EF

ð %F0

ñ %F1

ò %F2

ó %F3

ô %F4

õ %F5

ö %F6

264

Page 265: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

÷ %F7

ø %F8

ù %F9

ú %FA

û %FB

ü %FC

ý %FD

þ %FE

ÿ %FF

URL Encoding Reference

The ASCII device control characters %00-%1f were originally designed to control hardware devices. Control characters have nothing to do inside a URL.

ASCII Character Description URL-encoding

NUL null character %00

SOH start of header %01

STX start of text %02

ETX end of text %03

EOT end of transmission %04

ENQ enquiry %05

265

Page 266: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

ACK acknowledge %06

BEL bell (ring) %07

BS backspace %08

HT horizontal tab %09

LF line feed %0A

VT vertical tab %0B

FF form feed %0C

CR carriage return %0D

SO shift out %0E

SI shift in %0F

DLE data link escape %10

DC1 device control 1 %11

DC2 device control 2 %12

DC3 device control 3 %13

DC4 device control 4 %14

NAK negative acknowledge %15

SYN synchronize %16

ETB end transmission block %17

266

Page 267: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

CAN cancel %18

EM end of medium %19

SUB substitute %1A

ESC escape %1B

FS file separator %1C

GS group separator %1D

RS record separator %1E

US unit separator %1F

HTML Language Code Reference

ISO Language Codes

The HTML lang attribute can be used to declare the language of a Web page or a portion of a Web page. This is meant to assist search engines and browsers.

According to the W3C recommendation you should declare the primary language for each Web page with the lang attribute inside the <html> tag, like this:

<html lang="en">...</html>

In XHTML, the language is declared inside the <html> tag as follows:

267

Page 268: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">...</html>

ISO 639-1 Language Codes

ISO 639-1 defines abbreviations for languages. In HTML and XHTML they can be used in the lang and xml:lang attributes.

Language ISO Code

Abkhazian ab

Afar aa

Afrikaans af

Albanian sq

Amharic am

Arabic ar

Aragonese an

Armenian hy

Assamese as

Aymara ay

Azerbaijani az

Bashkir ba

Basque eu

268

Page 269: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Bengali (Bangla) bn

Bhutani dz

Bihari bh

Bislama bi

Breton br

Bulgarian bg

Burmese my

Byelorussian (Belarusian) be

Cambodian km

Catalan ca

Cherokee

Chewa

Chinese (Simplified) zh

Chinese (Traditional) zh

Corsican co

Croatian hr

Czech cs

Danish da

Divehi

269

Page 270: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Dutch nl

Edo

English en

Esperanto eo

Estonian et

Faeroese fo

Farsi fa

Fiji fj

Finnish fi

Flemish

French fr

Frisian fy

Fulfulde

Galician gl

Gaelic (Scottish) gd

Gaelic (Manx) gv

Georgian ka

German de

Greek el

270

Page 271: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Greenlandic kl

Guarani gn

Gujarati gu

Haitian Creole ht

Hausa ha

Hawaiian

Hebrew he, iw

Hindi hi

Hungarian hu

Ibibio

Icelandic is

Ido io

Igbo

Indonesian id, in

Interlingua ia

Interlingue ie

Inuktitut iu

Inupiak ik

Irish ga

271

Page 272: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Italian it

Japanese ja

Javanese jv

Kannada kn

Kanuri

Kashmiri ks

Kazakh kk

Kinyarwanda (Ruanda) rw

Kirghiz ky

Kirundi (Rundi) rn

Konkani

Korean ko

Kurdish ku

Laothian lo

Latin la

Latvian (Lettish) lv

Limburgish ( Limburger) li

Lingala ln

Lithuanian lt

272

Page 273: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Macedonian mk

Malagasy mg

Malay ms

Malayalam ml

Maltese mt

Maori mi

Marathi mr

Moldavian mo

Mongolian mn

Nauru na

Nepali ne

Norwegian no

Occitan oc

Oriya or

Oromo (Afaan Oromo) om

Papiamentu

Pashto (Pushto) ps

Polish pl

Portuguese pt

273

Page 274: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Punjabi pa

Quechua qu

Rhaeto-Romance rm

Romanian ro

Russian ru

Sami (Lappish)

Samoan sm

Sangro sg

Sanskrit sa

Serbian sr

Serbo-Croatian sh

Sesotho st

Setswana tn

Shona sn

Sichuan Yi ii

Sindhi sd

Sinhalese si

Siswati ss

Slovak sk

274

Page 275: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Slovenian sl

Somali so

Spanish es

Sundanese su

Swahili (Kiswahili) sw

Swedish sv

Syriac

Tagalog tl

Tajik tg

Tamazight

Tamil ta

Tatar tt

Telugu te

Thai th

Tibetan bo

Tigrinya ti

Tonga to

Tsonga ts

Turkish tr

275

Page 276: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Turkmen tk

Twi tw

Uighur ug

Ukrainian uk

Urdu ur

Uzbek uz

Venda

Vietnamese vi

Volapük vo

Wallon wa

Welsh cy

Wolof wo

Xhosa xh

Yi

Yiddish yi, ji

Yoruba yo

Zulu zu

276

Page 277: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

HTTP Status Messages

When a browser requests a service from a web server, an error might occur.

This is a list of HTTP status messages that might be returned:

1xx: InformationMessage: Description:

100 Continue The server has received the request headers, and the client should proceed to send the request body

101 Switching Protocols The requester has asked the server to switch protocols

277

Page 278: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

103 Checkpoint Used in the resumable requests proposal to resume aborted PUT or POST requests

2xx: SuccessfulMessage: Description:

200 OK The request is OK (this is the standard response for successful HTTP requests)

201 Created The request has been fulfilled, and a new resource is created

202 Accepted The request has been accepted for processing, but the processing has not been completed

203 Non-Authoritative Information The request has been successfully processed, but is returning information that may be from another source

204 No Content The request has been successfully processed, but is not returning any content

205 Reset Content The request has been successfully processed, but is not returning any content, and requires that the requester reset the document view

206 Partial Content The server is delivering only part of the resource due to a range header sent by the client

3xx: RedirectionMessage: Description:

300 Multiple Choices A link list. The user can select a link and go to that location. Maximum five addresses

301 Moved Permanently The requested page has moved to a new URL

278

Page 279: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

302 Found The requested page has moved temporarily to a new URL

303 See Other The requested page can be found under a different URL

304 Not Modified Indicates the requested page has not been modified since last requested

306 Switch Proxy No longer used

307 Temporary Redirect The requested page has moved temporarily to a new URL

308 Resume Incomplete Used in the resumable requests proposal to resume aborted PUT or POST requests

4xx: Client ErrorMessage: Description:

400 Bad Request The request cannot be fulfilled due to bad syntax

401 Unauthorized The request was a legal request, but the server is refusing to respond to it. For use when authentication is possible but has failed or not yet been provided

402 Payment Required Reserved for future use

403 Forbidden The request was a legal request, but the server is refusing to respond to it

404 Not Found The requested page could not be found but may be available again in the future

405 Method Not Allowed A request was made of a page using a request method not supported by that page

406 Not Acceptable The server can only generate a response that is not accepted by the client

279

Page 280: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

407 Proxy Authentication Required The client must first authenticate itself with the proxy

408 Request Timeout The server timed out waiting for the request

409 Conflict The request could not be completed because of a conflict in the request

410 Gone The requested page is no longer available

411 Length Required The "Content-Length" is not defined. The server will not accept the request without it

412 Precondition Failed The precondition given in the request evaluated to false by the server

413 Request Entity Too Large The server will not accept the request, because the request entity is too large

414 Request-URI Too Long The server will not accept the request, because the URL is too long. Occurs when you convert a POST request to a GET request with a long query information

415 Unsupported Media Type The server will not accept the request, because the media type is not supported

416 Requested Range Not Satisfiable The client has asked for a portion of the file, but the server cannot supply that portion

417 Expectation Failed The server cannot meet the requirements of the Expect request-header field

5xx: Server ErrorMessage: Description:

500 Internal Server Error A generic error message, given when no more specific message is suitable

501 Not Implemented The server either does not recognize the request method, or it lacks the ability to fulfill the request

280

Page 281: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

502 Bad Gateway The server was acting as a gateway or proxy and received an invalid response from the upstream server

503 Service Unavailable The server is currently unavailable (overloaded or down)

504 Gateway Timeout The server was acting as a gateway or proxy and did not receive a timely response from the upstream server

505 HTTP Version Not Supported The server does not support the HTTP protocol version used in the request

511 Network Authentication Required The client needs to authenticate to gain network access

HTTP Methods: GET vs. POST

The two most used HTTP methods are: GET and POST.

What is HTTP?

The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers.

HTTP works as a request-response protocol between a client and server.

A web browser may be the client, and an application on a computer that hosts a web site may be the server.

Example: A client (browser) submits an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content.

Two HTTP Request Methods: GET and POST

Two commonly used methods for a request-response between a client and server are: GET and POST.

281

Page 282: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

GET - Requests data from a specified resource POST - Submits data to be processed to a specified resource

The GET Method

Note that query strings (name/value pairs) is sent in the URL of a GET request:

/test/demo_form.asp?name1=value1&name2=value2

Some other notes on GET requests:

GET requests can be cached GET requests remain in the browser history GET requests can be bookmarked GET requests should never be used when dealing with sensitive data GET requests have length restrictions GET requests should be used only to retrieve data

The POST Method

Note that query strings (name/value pairs) is sent in the HTTP message body of a POST request:

POST /test/demo_form.asp HTTP/1.1Host: w3schools.comname1=value1&name2=value2

Some other notes on POST requests:

POST requests are never cached POST requests do not remain in the browser history POST requests cannot be bookmarked POST requests have no restrictions on data length

Compare GET vs. POST

The following table compares the two HTTP methods: GET and POST.

GET POST

BACK button/Reload Harmless Data will be re-submitted (the browser should alert the user that the data are about to be re-

282

Page 283: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

submitted)

Bookmarked Can be bookmarked Cannot be bookmarked

Cached Can be cached Not cached

Encoding type application/x-www-form-urlencoded application/x-www-form-urlencoded or multipart/form-data. Use multipart encoding for binary data

History Parameters remain in browser history Parameters are not saved in browser history

Restrictions on data length Yes, when sending data, the GET method adds the data to the URL; and the length of a URL is limited (maximum URL length is 2048 characters)

No restrictions

Restrictions on data type Only ASCII characters allowed No restrictions. Binary data is also allowed

Security GET is less secure compared to POST because data sent is part of the URL

Never use GET when sending passwords or other sensitive information!

POST is a little safer than GET because the parameters are not stored in browser history or in web server logs

Visibility Data is visible to everyone in the URL Data is not displayed in the URL

Other HTTP Request Methods

The following table lists some other HTTP request methods:

Method Description

HEAD Same as GET but returns only HTTP headers and no document body

PUT Uploads a representation of the specified URI

DELETE Deletes the specified resource

OPTIONS Returns the HTTP methods that the server supports

CONNECT Converts the request connection to a transparent TCP/IP tunnel

283

Page 284: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Keyboard Shortcuts

Save time by using keyboard shortcuts.

Keyboard Shortcuts For Windows and Mac

Keyboard shortcuts are often used in modern operating systems and computer software programs.

Using keyboard shortcuts could save you a lot of time.

Basic Shortcuts

Description Windows Mac OS

284

Page 285: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Edit menu Alt + E Ctrl + F2 + F

File menu Alt + F Ctrl + F2 + E

View menu Alt + V Ctrl + F2 + V

Select all text Ctrl + A Cmd + A

Copy text Ctrl + C Cmd + C

Find text Ctrl + F Cmd + F

Find and replace text Ctrl + H Cmd + F

New Document Ctrl + N Cmd + N

Open a file Ctrl + O Cmd + O

Print options Ctrl + P Cmd + P

Save file Ctrl + S Cmd + S

Paste text Ctrl + V Cmd + V

Cut text Ctrl + X Cmd + X

Redo text Ctrl + Y Shift + Cmd + Z

Undo text Ctrl + Z Cmd + Z

285

Page 286: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Text Editing

Description Windows Mac OS

Cursor Movement

Go to the right or to the beginning of next line break Right Arrow Right Arrow

Go to the left or to the end of previous line break Left Arrow Left Arrow

Go up one row Up Arrow Up Arrow

Go down one row Down Arrow Down Arrow

Go to the beginning of the current line Home Cmd + Left Arrow

Go to the end of the current line End Cmd + Right Arrow

Go to the beginning of the document Ctrl + Home Cmd + Up Arrow

Go to the end of the document Ctrl + End Cmd + Down Arrow

Move up one frame Page Up Fn + Up Arrow

Move down one frame Page Down Fn + Down

286

Page 287: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Arrow

Go to beginning of previous word Ctrl + Left Arrow Option + Left Arrow

Go to beginning of next word Ctrl + Right Arrow Option + Right Arrow

Go to beginning of line break Ctrl + Up Arrow Cmd + Left Arrow

Go to end of line break Ctrl + Down Arrow Cmd + Right Arrow

Text Selection

Select characters to the left Shift + Left Arrow Shift + Left Arrow

Select characters to the right Shift + Right Arrow Shift + Right Arrow

Select lines upwards Shift + Up Arrow Shift + Up Arrow

Select lines downwards Shift + Down Arrow Shift + Down Arrow

Select words to the left Shift + Ctrl + Left Shift + Opt + Left

Select words to the right Shift + Ctrl + Right Shift + Opt + Right

Select paragraphs to the left Shift + Ctrl + Up Shift + Opt + Up

Select paragraphs to the right Shift + Ctrl + Down Shift + Opt + Down

Select text between the cursor and the beginning of the current line

Shift + Home Cmd + Shift + Left

287

Page 288: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Arrow

Select text between the cursor and the end of the current line

Shift + End Cmd + Shift + Right Arrow

Select text between the cursor and the beginning of the document

Shift + Ctrl + Home Cmd + Shift + Up Arrow or Cmd + Shift + Fn + Left Arrow

Select text between the cursor and the end of the document Shift + Ctrl + End Cmd + Shift + Down Arrow or Cmd + Shift + Fn + Right Arrow

Select one frame at a time of text above the cursor Shift + Page Up Shift + Fn + Up Arrow

Select one frame at a time of text below the cursor Shift + Page Down Shift + Fn + Down Arrow

Select all text Ctrl + A Cmd + A

Find text Ctrl + F Cmd + F

Text Formatting

Make selected text bold Ctrl + B Cmd + B

Make selected text italic Ctrl + I Cmd + I

Underline selected text Ctrl + U Cmd + U

Make selected text superscript Ctrl + Shift + = Cmd + Shift + =

Make selected text subscript Ctrl + = Cmd + =

288

Page 289: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Text Editing

Delete characters to the left Backspace Backspace

Delete characters to the right Delete Fn + Backspace

Delete words to the right Ctrl + Del Cmd + Backspace

Delete words to the left Ctrl + Backspace Cmd + Fn + Backspace

Indent Tab Tab

Outdent Shift + Tab Shift + Tab

Copy text Ctrl + C Cmd + C

Find and replace text Ctrl + H Cmd + F

Paste text Ctrl + V Cmd + V

Cut text Ctrl + X Cmd + X

Redo text Ctrl + Y Shift + Cmd + Z

Undo text Ctrl + Z Cmd + Z

Web Browsers

Description Windows Mac OS

289

Page 290: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Navigation

Scroll down a frame Space or Page Down Space or Fn + Down Arrow

Scroll up a frame Shift + Space or Page Up Shift + Space or Fn + Up Arrow

Go to bottom of the page End Cmd + Down Arrow

Go to top of the page Home Cmd + Up Arrow

Go back Alt + Left Arrow or Backspace

Cmd + Left Arrow

Go forward Alt + Right Arrow or Shift + Backspace

Cmd + Right Arrow

Refresh a webpage F5 Cmd + R

Refresh a webpage (no cache) Ctrl + F5 Cmd + Shift + R

Stop Esc Esc

Toggle full-screen F11 Cmd + Shift + F

Zoom in Ctrl + + Cmd + +

Zoom out Ctrl + - Cmd + -

Zoom 100% (default) Ctrl + 0 Cmd + 0

Open homepage Alt + Home Option + Home or Option + Fn + Left

290

Page 291: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

Arrow

Find text Ctrl + F Cmd + F

Tab / Window Management

Open a new tab Ctrl + T Cmd + T

Close current tab Ctrl + W Cmd + W

Close all tabs Ctrl + Shift + W Cmd + Q

Close all tabs except the current tab Ctrl + Alt + F4 Cmd + Opt + W

Go to next tab Ctrl + Tab Control + Tab or Cmd + Shift + Right Arrow

Go to previous tab Ctrl + Shift + Tab Shift + Control + Tab or Cmd + Shift + Left Arrow

Go to a specific tab number Ctrl + 1-8 Cmd + 1-8

Go to the last tab Ctrl + 9 Cmd + 9

Reopen the last closed tab Ctrl + Shift + T Cmd + Shift + T

Open a new window Ctrl + N Cmd + N

Close current window Alt + F4 Cmd + W

Go to next window Alt + Tab Cmd + Tab

Go to previous window Alt + Shift + Tab Cmd + Shift

291

Page 292: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

+ Tab

Reopen the last closed window Ctrl + Shift + N

Open links in a new tab in the background Ctrl + Click Cmd + Click

Open links in a new tab in the foreground Ctrl + Shift + Click Cmd + Shift + Click

Print current webpage Ctrl + P Cmd + P

Save current webpage Ctrl + S Cmd + S

Address Bar

Cycle between toolbar, search bar, and page elements Tab Tab

Go to browser's address bar Ctrl + L or Alt + D Cmd + L

Focus and select the browser's search bar Ctrl + E Cmd + E / Cmd + K

Open the address bar location in a new tab Alt + Enter Opt + Enter

Display a list of previously typed addresses F4

Add "www." to the beginning and ".com" to the end of the text typed in the address bar (e.g., type "w3schools" and press Ctrl + Enter to open "www.w3schools.com")

Ctrl + Enter Cmd + Enter or Control + Enter

Bookmarks

Open the bookmarks menu Ctrl + B Cmd + B

Add bookmark for current page Ctrl + D Cmd + Opt + B or Cmd + Shift + B

Open browsing history Ctrl + H Cmd + Shift

292

Page 293: Htmlnotes 150323102005-conversion-gate01

Notes By Niraj Bharambe

+ H or Cmd + Y

Open download history Ctrl + J Cmd + J or Cmd + Shift + J

Screenshots

Description Windows Mac OS

Save screenshot of the whole screen as file Cmd + Shift + 3

Copy screenshot of the whole screen to the clipboard PrtScr (Print Screen) or Ctrl + PrtScr

Cmd + Ctrl + Shift + 3

Save screenshot of window as file Cmd + Shift + 4, then Space

Copy screenshot of window to the clipboard Alt + PrtScr Cmd + Ctrl + Shift + 4, then Space

Copy screenshot of wanted area to the clipboard Cmd + Ctrl + Shift + 4

Save screenshot of wanted area as file Cmd + Shift + 4

Note: Due to different keyboard setups, some shortcuts may not be compatible for all users.

293