HTML
HTML
HTML stands for Hypertext Markup Language, and it is the most widely used language to
write Web Pages.
Hypertext refers to the way in which Web pages (HTML documents) are linked
together. Thus, the link available on a webpage is called Hypertext.
As its name suggests, HTML is a Markup Language which means you use HTML to
simply "mark-up" a text document with tags that tell a Web browser how to structure
it to display.
Originally, HTML was developed with the intent of defining the structure of documents like HTML Tags
headings, paragraphs, lists, and so forth to facilitate the sharing of scientific information
As told earlier, HTML is a markup language and makes use of various tags to format the
between researchers.
content. These tags are enclosed within angle braces <Tag Name>. Except few tags, most
Now, HTML is being widely used to format web pages with the help of different tags available of the tags have their corresponding closing tags. For example, <html> has its closing
in HTML language. tag</html> and <body> tag has its closing tag </body> tag etc.
<!DOCTYPE html> <!DOCTYPE...> This tag defines the document type and HTML version.
<html>
This tag encloses the complete HTML document and mainly comprises
<head>
<html> of document header which is represented by <head>...</head> and
<title>This is document title</title> document body which is represented by <body>...</body> tags.
</head>
<body> This tag represents the document's header which can keep other HTML
<head>
tags like <title>, <link> etc.
<h1>This is a heading</h1>
<p>Document content goes here.....</p>
The <title> tag is used inside the <head> tag to mention the
</body> <title>
document title.
</html>
This tag represents the document's body which keeps other HTML tags
Either you can use Try it option available at the top right corner of the code box to check the <body>
like <h1>, <div>, <p> etc.
result of this HTML code, or let's save it in an HTML file test.htm using your favorite text
editor. Finally open it using a web browser like Internet Explorer or Google Chrome, or Firefox
etc. It must show the following output: <h1> This tag represents the heading.
16 17
HTML
2. HTML – BASIC TAGS HTML
To learn HTML, you will need to study various tags and understand how they behave, while
formatting a textual document. Learning HTML is simple as users have to learn the usage of
different tags in order to format the text or images to make a beautiful webpage. Heading Tags
World Wide Web Consortium (W3C) recommends to use lowercase tags starting from HTML Any document starts with a heading. You can use different sizes for your headings. HTML also
4. has six levels of headings, which use the elements <h1>, <h2>, <h3>, <h4>, <h5>, and
<h6>. While displaying any heading, browser adds one line before and one line after that
HTML Document Structure heading.
<!DOCTYPE html>
There are many other declaration types which can be used in HTML document depending on
what version of HTML is being used. We will see more details on this while discussing
<!DOCTYPE...> tag along with other HTML tags.
18 19
HTML HTML
The <br /> tag has a space between the characters br and the forward slash. If you omit this
space, older browsers will have trouble rendering the line break, while if you miss the forward
slash character and just use <br> it is not valid in XHTML.
Example
<!DOCTYPE html>
<html>
<head>
Paragraph Tag <title>Line Break Example</title>
The <p> tag offers a way to structure your text into different paragraphs. Each paragraph of </head>
text should go in between an opening <p> and a closing </p> tag as shown below in the <body>
example:
<p>Hello<br />
<body>
Hello
<p>Here is a first paragraph of text.</p> You delivered your assignment on time.
Thanks
<p>Here is a second paragraph of text.</p>
Mahnaz
<p>Here is a third paragraph of text.</p>
</body>
</html>
Centering Content
You can use <center> tag to put any content in the center of the page or any table cell.
This will produce the following result:
Example
Here is a first paragraph of text.
Here is a second paragraph of text. <!DOCTYPE html>
20 21
HTML HTML
</html> The <hr /> element has a space between the characters hr and the forward slash. If you
omit this space, older browsers will have trouble rendering the horizontal line, while if you
This will produce the following result: miss the forward slash character and just use <hr> it is not valid in XHTML
Any text between the opening <pre> tag and the closing </pre> tag will preserve the
Horizontal Lines formatting of the source document.
Horizontal lines are used to visually break-up sections of a document. The <hr> tag creates
a line from the current position in the document to the right margin and breaks the line Example
accordingly.
<!DOCTYPE html>
For example, you may want to give a line between two paragraphs as in the given example
<html>
below:
<head>
Example <title>Preserve Formatting Example</title>
<html> <body>
<head> <pre>
<body> }
alert (strText)
Try using the same code without keeping it inside <pre>...</pre> tags
An HTML element is defined by a starting tag. If the element contains other content, it ends
with a closing tag, where the element name is preceded by a forward slash as shown below
Nonbreaking Spaces with few tags:
Suppose you want to use the phrase "12 Angry Men." Here, you would not want a browser to
Start Tag Content End Tag
split the "12, Angry" and "Men" across two lines:
An example of this technique appears in the movie "12 Angry Men." <p> This is paragraph content. </p>
In cases, where you do not want the client browser to break text, you should use a
<h1> This is heading content. </h1>
nonbreaking space entity instead of a normal space. For example, when coding the
"12 Angry Men" in a paragraph, you should use something similar to the following code:
<div> This is division content. </div>
Example
<br />
<!DOCTYPE html>
<html>
<head>
So here <p>....</p> is an HTML element, <h1>...</h1> is another HTML element. There
<title>Nonbreaking Spaces Example</title> are some HTML elements which don't need to be closed, such as <img.../>, <hr /> and
<br /> elements. These are known as void elements.
</head>
<body> HTML documents consists of a tree of these elements and they specify how HTML documents
should be built, and what kind of content should be placed in what part of an HTML document.
<p>An example of this technique appears in the movie "12 Angry Men."</p>
</body>
HTML Tag vs. Element
</html>
An HTML element is defined by a starting tag. If the element contains other content, it ends
with a closing tag.
For example, <p> is starting tag of a paragraph and </p> is closing tag of the same
paragraph but <p>This is paragraph</p> is a paragraph element.
Example
<!DOCTYPE html>
<html>
24 25
HTML
4. HTML – ATTRIBUTES HTML
<head>
Example
<!DOCTYPE html>
<html>
<head>
<title>Align Attribute Example</title>
</head>
<body>
<p align="left">This is left aligned</p>
<p align="center">This is center aligned</p>
<p align="right">This is right aligned</p>
</body>
</html>
26 27
HTML HTML
Example
The style Attribute
<p id="html">This para explains what is HTML</p>
The style attribute allows you to specify Cascading Style Sheet (CSS) rules within the element.
<p id="css">This para explains what is Cascading Style Sheet</p>
<!DOCTYPE html>
<html>
The title Attribute
<head>
The title attribute gives a suggested title for the element. They syntax for the title attribute
is similar as explained for id attribute: <title>The style Attribute</title>
</head>
The behavior of this attribute will depend upon the element that carries it, although it is often
displayed as a tooltip when cursor comes over the element or while the element is loading. <body>
<p style="font-family:arial; color:#FF0000;">Some text...</p>
Example </body>
<!DOCTYPE html> </html>
<html>
This will produce the following result:
<head>
28 29
HTML HTML
At this point of time, we are not learning CSS, so just let's proceed without bothering much When dir attribute is used within the <html> tag, it determines how text will be presented
about CSS. Here, you need to understand what are HTML attributes and how they can be within the entire document. When used within another tag, it controls the text's direction for
used while formatting content. just the content of that tag.
<!DOCTYPE html>
<html dir="rtl"> The xml:lang Attribute
<head> The xml:lang attribute is the XHTML replacement for the lang attribute. The value of
<title>Display Directions</title> thexml:lang attribute should be an ISO-639 country code as mentioned in previous section.
</head>
<body> Generic Attributes
This is how IE 5 renders right-to-left directed text. Here's a table of some other attributes that are readily usable with many of the HTML tags.
</body>
Attribute Options Function
</html>
This will produce the following result: align right, left, center Horizontally aligns tags
30 31
HTML
5. HTML – FORMATTING HTML
Bold Text
id User Defined Names an element for use with Cascading
Anything that appears within <b>...</b> element, is displayed in bold as shown below:
Style Sheets.
class User Defined Classifies an element for use with Cascading Example
Style Sheets.
<!DOCTYPE html>
<html>
width Numeric Value Specifies the width of tables, images, or
table cells. <head>
<title>Bold Text Example</title>
height Numeric Value Specifies the height of tables, images, or </head>
table cells.
<body>
<p>The following word uses a <b>bold</b> typeface.</p>
title User Defined "Pop-up" title of the elements.
</body>
</html>
We will see related examples as we will proceed to study other HTML tags. For a complete list
This will produce the following result:
of HTML Tags and related attributes please check reference to HTML Tags List.
Italic Text
Anything that appears within <i>...</i> element is displayed in italicized as shown below:
Example
<!DOCTYPE html>
<html>
<head>
<title>Italic Text Example</title>
</head>
32 33
HTML HTML
Anything that appears within <u>...</u> element, is displayed with underline as shown
below: Monospaced Font
The content of a <tt>...</tt> element is written in monospaced font. Most of the fonts are
Example known as variable-width fonts because different letters are of different widths (for example,
the letter 'm' is wider than the letter 'i'). In a monospaced font, however, each letter has the
<!DOCTYPE html> same width.
<html>
<head> Example
<title>Underlined Text Example</title> <!DOCTYPE html>
</head> <html>
<body> <head>
<p>The following word uses a <u>underlined</u> typeface.</p> <title>Monospaced Font Example</title>
</body> </head>
</html> <body>
This will produce the following result: <p>The following word uses a <tt>monospaced</tt> typeface.</p>
</body>
The following word uses an underlined typeface.
</html>
Anything that appears within <strike>...</strike> element is displayed with strikethrough, The following word uses a monospaced typeface.
which is a thin line through the text as shown below:
<html>
Example
<head>
<title>Superscript Text Example</title> <!DOCTYPE html>
</head> <html>
<body> <head>
</body> </head>
</html> <body>
<p>I want to drink <del>cola</del> <ins>wine</ins></p>
This will produce the following result:
</body>
<!DOCTYPE html>
Example
<html>
<head> <!DOCTYPE html>
</head> <head>
</body> <body>
36 37
HTML HTML
</html>
CONTENT ARTICLES
Actual content goes here.....
The <span> element, on the other hand, can be used to group inline elements only. So, if The phrase tags have been desicolgned for specific purposes, though they are displayed in a
you have a part of a sentence or paragraph which you want to group together, you could use similar way as other basic tags like <b>, <i>, <pre>, and <tt>, you have seen in previous
the <span> element as follows chapter. This chapter will take you through all the important phrase tags, so let's start seeing
them one by one.
Example
<!DOCTYPE html>
Emphasized Text
<html> Anything that appears within <em>...</em> element is displayed as emphasized text.
<head>
Example
<title>Span Tag Example</title>
</head> <!DOCTYPE html>
<body> <html>
<p>This is the example of <span style="color:green">span tag</span> and the <span <head>
style="color:red">div tag</span> alongwith CSS</p> <title>Emphasized Text Example</title>
</body> </head>
</html> <body>
<p>The following word uses a <em>emphasized</em> typeface.</p>
This will produce the following result:
</body>
This is the example of span tag and the div tag along with CSS
</html>
These tags are commonly used with CSS to allow you to attach a style to a section of a page.
This will produce the following result:
Marked Text
Anything that appears with-in <mark>...</mark> element, is displayed as marked with
yellow ink.
Example
<!DOCTYPE html>
<html>
<head>
<title>Marked Text Example</title>
40 41
HTML HTML
The following word has been marked with yellow. This will produce the following result:
<!DOCTYPE html> At present, the major browsers do not change the appearance of the content of the
<acronym> element.
<html>
<head> Example
<title>Strong Text Example</title>
<!DOCTYPE html>
</head>
<html>
<body>
<head>
<p>The following word uses a <strong>strong</strong> typeface.</p>
<title>Acronym Example</title>
</body>
</head>
</html>
<body>
This will produce the following result: <p>This chapter covers marking up text in <acronym>XHTML</acronym>.</p>
The following word uses a strong typeface. </body>
</html>
Text Abbreviation
This will produce the following result:
You can abbreviate a text by putting it inside opening <abbr> and closing </abbr> tags. If
present, the title attribute must contain this full description and nothing else.
This chapter covers marking up text in XHTML.
Example
Text Direction
<!DOCTYPE html>
The <bdo>...</bdo> element stands for Bi-Directional Override and it is used to override
<html>
the current text direction.
<head>
42 43
HTML HTML
Special Terms <blockquote>XHTML 1.0 is the W3C's first Recommendation for XHTML, following on
The <dfn>...</dfn> element (or HTML Definition Element) allows you to specify that you from earlier work on HTML 4.01, HTML 4.0, HTML 3.2 and HTML 2.0.</blockquote>
are introducing a special term. It's usage is similar to italic words in the midst of a paragraph. </body>
Typically, you would use the <dfn> element the first time you introduce a key term. Most </html>
recent browsers render the content of a <dfn> element in an italic font.
This will produce the following result:
Example The following description of XHTML is taken from the W3C Web site:
<!DOCTYPE html>
XHTML 1.0 is the W3C's first Recommendation for XHTML, following on from earlier
<html> work on HTML 4.01, HTML 4.0, HTML 3.2 and HTML 2.0.
<head>
<title>Special Terms Example</title>
Short Quotations
</head>
The <q>...</q> element is used when you want to add a double quote within a sentence.
<body>
<p>The following word is a <dfn>special</dfn> term.</p> Example
</body>
<!DOCTYPE html>
</html>
<html>
This will produce the following result: <head>
44 45
HTML HTML
Amit is in Spain, I think I am wrong. <p>Regular text. <code>This is code.</code> Regular text.</p>
</body>
If you are quoting a text, you can indicate the source placing it between an opening <cite>tag This will produce the following result:
and closing </cite> tag
Regular text. This is code. Regular text.
As you would expect in a print publication, the content of the <cite> element is rendered in
italicized text by default.
Keyboard Text
Example When you are talking about computers, if you want to tell a reader to enter some text, you
can use the <kbd>...</kbd> element to indicate what should be typed in, as in this
<!DOCTYPE html> example.
<html>
<head> Example
<title>Citations Example</title> <!DOCTYPE html>
</head> <html>
<body> <head>
<p>This HTML tutorial is derived from <cite>W3 Standard for HTML</cite>.</p> <title>Keyboard Text Example</title>
</body> </head>
</html> <body>
This will produce the following result: <p>Regular text. <kbd>This is inside kbd element</kbd> Regular text.</p>
</body>
This HTML tutorial is derived from W3 Standard for HTML.
</html>
Any programming code to appear on a Web page should be placed Regular text. This is inside kbd element Regular text.
inside <code>...</code>tags. Usually the content of the <code> element is presented in a
monospaced font, just like the code in most programming books.
46 47
HTML HTML
Program Output
The <samp>...</samp> element indicates sample output from a program, and script etc.
Again, it is mainly used when documenting programming or coding concepts.
Example
<!DOCTYPE html>
<html>
<head>
<title>Program Output Example</title>
</head>
<body>
<p>Result produced by the program is <samp>Hello World!</samp></p>
</body>
</html>
Example
Following is an example, where we are adding HTML, Meta Tags, Metadata as important
keywords about the document.
<!DOCTYPE html>
HTML lets you specify metadata - additional important information about a document in a
variety of ways. The META elements can be used to include name/value pairs describing <html>
properties of the HTML document, such as author, expiry date, a list of keywords, document <head>
author etc.
<title>Meta Tags Example</title>
The <meta> tag is used to provide such additional information. This tag is an empty element
<meta name="keywords" content="HTML, Meta Tags, Metadata" />
and so does not have a closing tag but it carries information within its attributes.
</head>
You can include one or more meta tags in your document based on what information you
want to keep in your document but in general, meta tags do not impact physical appearance <body>
of the document so from appearance point of view, it does not matter if you include them or <p>Hello HTML5!</p>
not.
</body>
</html>
Adding Meta Tags to Your Documents
This will produce the following result:
You can add metadata to your web pages by placing <meta> tags inside the header of the
document which is represented by <head> and </head> tags. A meta tag can have
Hello HTML5!
following attributes in addition to core attributes:
Attribute Description
Document Description
Name Name for the property. Can be anything. Examples include, keywords, You can use <meta> tag to give a short description about the document. This again can be
description, author, revised, generator etc. used by various search engines while indexing your webpage for searching purpose.
Example
content Specifies the property's value.
<!DOCTYPE html>
scheme Specifies a scheme to interpret the property's value (as declared in the <html>
content attribute).
<head>
<title>Meta Tags Example</title>
http- Used for http response message headers. For example, http-equiv can be
equiv used to refresh the page or to set a cookie. Values include content-type, <meta name="keywords" content="HTML, Meta Tags, Metadata" />
expires, refresh and set-cookie. <meta name="description" content="Learning about Meta Tags." />
</head>
<body>
Specifying Keywords
<p>Hello HTML5!</p>
You can use <meta> tag to specify important keywords related to the document and later
</body>
these keywords are used by the search engines while indexing your webpage for searching
purpose. </html>
50 51
HTML HTML
You can use <meta> tag to give information about when last time the document was updated. <body>
This information can be used by various web browsers while refreshing your webpage. <p>Hello HTML5!</p>
</body>
</html>
Example
<!DOCTYPE html>
Page Redirection
<html>
You can use <meta> tag to redirect your page to any other webpage. You can also specify a
<head>
duration if you want to redirect the page after a certain number of seconds.
<title>Meta Tags Example</title>
<meta name="keywords" content="HTML, Meta Tags, Metadata" /> Example
<meta name="description" content="Learning about Meta Tags." /> Following is an example of redirecting current page to another page after 5 seconds. If you
want to redirect page immediately then do not specify content attribute.
<meta name="revised" content="Tutorialspoint, 3/7/2014" />
</head> <!DOCTYPE html>
<body> <html>
<p>Hello HTML5!</p> <head>
</body> <title>Meta Tags Example</title>
</html> <meta name="keywords" content="HTML, Meta Tags, Metadata" />
<meta name="description" content="Learning about Meta Tags." />
<html>
<head> Setting Cookies
<title>Meta Tags Example</title>
Cookies are data, stored in small text files on your computer and it is exchanged between
<meta name="keywords" content="HTML, Meta Tags, Metadata" /> web browser and web server to keep track of various information based on your web
application need.
<meta name="description" content="Learning about Meta Tags." />
<meta name="revised" content="Tutorialspoint, 3/7/2014" /> You can use <meta> tag to store cookies on client side and later this information can be used
by the Web Server to track a site visitor.
<meta http-equiv="refresh" content="5" />
52 53
HTML
Example
Following is an example of redirecting current page to another page after 5 seconds. If you
want to redirect page immediately then do not specify content attribute.
<!DOCTYPE html>
<html>
<head>
<title>Meta Tags Example</title>
<meta name="keywords" content="HTML, Meta Tags, Metadata" />
<meta name="description" content="Learning about Meta Tags." />
<meta name="revised" content="Tutorialspoint, 3/7/2014" />
54