New Web1 PDF
New Web1 PDF
1 HTML
1. What is HTML? Explain its Advantages and Disadvantages.
Markup languages are designed for the processing, definition and presentation of
text. The language specifies code for formatting, both the layout and style, within a
text file. The code used to specify the formatting are called tags. HTML is an example
of a widely known and used markup language.
HTML: HTML stands for Hyper-Text Markup Language. It allows us to create web pages.
It does not include any control structure and can produce only static content. A HTML
page consists of various tags that make a web page. The features, advantages and
disadvantages of HTML page are listed below.
Features of HTML:
It is a formatting language for text and images.
It allows us to read the content nonlinearly by using hyperlinks to a file.
HTML is an application of SGML.
HTML uses markup tags to describe web pages
It is not case sensitive i.e. code can be written in small case or uppercase letters.
All the HTML documents have “.html” or “.htm” extension.
HTML documents can be edited using editors such as notepad or front page.
HTML5 was first published in 2008. But it was recommended by W3C in 2014. It
has been standardized and new elements were added and some of the old
elements were deprecated.
New in HTML5:
The DOCTYPE declaration for HTML5 is very simple:
<!DOCTYPE html>
The character encoding (charset) declaration is also very simple:
<meta charset="UTF-8">
HTML5 Example:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
Content of the document......
</body>
</html>
New HTML5 Elements: The most interesting new HTML5 elements are:
New semantic elements like <header>, <footer>, <article>, and <section>.
New attributes of form elements like number, date, time, calendar, and
range.
New graphic elements: <svg> and <canvas>.
New multimedia elements: <audio> and <video>.
Removed Elements in HTML5: The HTML4 elements like big, center, dir, frame,
frameset, font and few more have been removed in HTML5
3. What are the main steps involved in creating a webpage and how does it get
executed? (Or) Explain the procedure to create HTML document.
1. Creating a webpage: To create a web page, we can use simple text editors or GUI
editors like FrontPage or even MS-Word.
If we are using an editor like note pad, we need to write the code using HTML
tags as per the requirement.
If we are using FrontPage, we can place the required elements using drag and
drop methods or using menu options.
2. Saving the file and previewing (executing) in a Browser: When saving a HTML file,
we need to give the file extension as “.htm” or “.html”. To preview a HTML file, we
need to open a browser like Internet Explorer or Netscape navigator and type in
the file name in its location window and press enter key.
3. Publishing the webpage: Publishing becomes very easy using tools like Front Page.
This involves uploading the webpage to a hosting server and be able to access it
through www.
WWW stands for World Wide Web. It is an Internet service developed to incorporate
footnotes, figures and cross-references into online hypertext documents. Hypertext
documents are those in which a user can jump to another location in the same
document or any other document by clicking on some highlighted text. WWW was
created in 1989 at Geneva, Switzerland.
Web page is page of any website that can be accessed through WWW.
HTML Tags: HTML uses markup tags to describe web pages. HTML markup tags are
usually called HTML tags. The properties of tags are listed below.
Element
A HTML document is basically separated in two parts: the head (HTML head tag) and
the body (HTML body tag). We also add a Document type declaration on top of it to get
the basic document structure and HTML version. The structure of a HTML document is
shown below.
The !DOCTYPE declaration: Every well written HTML document begins with a basic
declaration that defines what type of document it is. This declaration is made using
the !DOCTYPE tag and is to be written at the beginning of the document. It tells the
processing agent and HTML version. Sample is shown below.
<!DOCTYPE HTML>
<HTML> tag: The html tag acts as a container for the whole document. Every
character in the document should be in between the html start and end tags. The
html tag can also be used to define the language of the contained document
through the "lang" attribute. The content of the html tag is divided in two parts
using the head (HTML head tag) and the body (HTML body tag).
<HEAD> tag: This section is the document's head. All the information contained in
the document's head is loaded first, before any other thing in the document, as it's
defined before the body segment. It includes tags like title, script, style, meta and
so on.
<BODY> tag: This is the document's body: The body is the container for the visual
part of a document. All the things written here will be shown when the document
is rendered. Most of the tags in HTML can be inserted in the body section (inside
the HTML body tag) and will take care of the visual aspects of the document.
Example:
<HTML>
<HEAD>
<TITLE> My first Page </TITLE>
B- Com III – Web Programming
6 Apoorva Publishers
</HEAD>
<BODY>
<H1> Hello HTML <H1>
</BODY>
</HTML>
8. What are Attributes? What are the Common or Standard Attributes of HTML tags?
Attributes: Attributes provide additional information about an element (tag). All the
tags can have attributes. And these attributes are always specified in the start tag. The
following are the characteristics of attributes.
Attributes have default values
Attributes come in name/value pairs like: attribute-name="value"
There are some valueless attributes like ‘checked’ in <input> tag.
Some of the attributes are required in some of the tags. For example, ‘src’
attribute of <IMG> tag is mandatory.
Attribute names and attribute values are case-insensitive.
Below is a list of some attributes that are standard (also known as global
attributes) for most HTML elements (i.e. except for- base, head, html, meta,
param, script, style, and title elements)
Example: The following <IMG> tag uses ‘src', 'width' and ‘height’ attributes.
<img src="img_girl.jpg" width="500" height="600">
9. What are Text (Character) formatting tags in HTML? (Or) What are Physical Tags in
HTML?
Formatting tags: Formatting tags are used to apply formatting to the text. They render
the text in different formats according to the tag used. The common formatting tags
are listed below. The listed tags are known as physical tags. Physical tags define how
the text should be displayed in the browser. They control the Physical characteristics of
the text.
Tag Description
Example:
<!DOCTYPE html>
<html> Output:
<body>
<B>Hello </B> <BR>
<I> Hello </I> <BR>
<U> Hello </U> <BR>
H<sub>2</sub>O <BR>
x<sup>2</sup>y <BR>
<del>Hello</strike></del>
<BR>
<em>Hello</em> <BR>
<mark>Hello</mark> <BR>
</body>
</html>
Tag Description
<article> Defines an article in a document
<aside> Defines content aside from the page content
<details> Defines additional details that the user can view or
hide
<dialog> Defines a dialog box or window
<figcaption> Defines a caption for a <figure> element
<figure> Defines self-contained content
Paragraph Formatting Text: The following tags are used to format a paragraph. When
used, they create new paragraphs by introducing new line to the text written in them.
Tag Description
<div> It defines a division in the document
<p > It defines a paragraph
<pre> Preformatted text, it writes text exactly as it is,
including spaces.
<br> forces the browser to start a new line
<blockquote> Blockquote produces text that is indented in from both
the left and right margins.
<address> This tag is used to enclose information such as
"address, signature and authorship"
<h1>, <h2>,..<h6> Generates headings in different sizes
Example: Output:
<html> New Section
<body>
<div> New Section </div>
<p> I am a paragraph </p> I am a paragraph
<pre>too many spaces</pre>
<blockquote> Note this too many spaces
point</blockquote> Note this point
<address> Ravi, 7/G, Brindavan Ravi, 7/G, Brindavan Colony
Colony </address>
<br> Text in the Next Line
Logical Tags: Logical tag tells how the text is being used. They indicate the 'type' of
content they enclose. They do not determine the display of the text and the browser is
free to determine its display style. There are tags for emphasizing important sections of
text, for definitions and citations, computer output and other data.
Tag Description
<strong> Defines strong text
<em> Defines emphasized text
<ins> Defines inserted text
<del> Defines deleted text
<code> Defines computer code text
<kbd> Defines keyboard text
<samp> Defines sample computer code
<var> Defines a variable
<abbr> Defines an abbreviation
<bdo> Defines the text direction
<address> Defines an address element. This tag is used to enclose
information such as "address, signature and authorship"
<blockquote> Defines a long quotation. Blockquote produces text that is
indented from both the left and right margins.
<q> Defines a short quotation
<cite> Defines a citation
<dfn> Defines a definition term
<mark> Intended to be highlighted
Example: Following lines of code uses some of the above tags. Output is shown.
Heading Tags: Headings are most common type of inclusion in any writing. It can be
used to divide the page into sections. In HTML there are six types of heading tags. <H1>
to <H6>. When we use headings, they automatically appear in new lines. The following
program uses different heading tags.
<html> Output:
<body>
<h1>Hello </h1>
<h2>Hello </h2>
<h3>Hello </h3>
<h4>Hello </h4>
<h5>Hello </h5>
<h6>Hello </h6>
</body>
The comment tag is an empty tag in which the comment is placed. The beginning of the
tag is "<!--" and the end of the tag is "-->". Any tags placed within the comment are
ignored by the browsers.
Syntax:
<!-- text -->
Example:
<BODY>
<!-- My First Greetings -->
<H1> Hello </H1>
</BODY>
— em dash —
– en dash –
¼ fraction-1/4 ¼
½ fraction-1/2 ½
¾ fraction-3/4 ¾
... horizontal-ellipsis …
® registered-trademark ®
§ section §
™ trademark &trade
Example:
<!DOCTYPE html>
<html>
<body>
Background Music: Background sound can be added using the tags <bgsound>.
The two main attributes it takes are ‘src’ and ‘loop’. The loop attributes determines
the number of times the audio file is played.
Example: <BGSOUND SRC="MySong.wav" LOOP=INFINITE >
18. Write short notes on <IMG> (Image) tag. (Or) How to add images to HTML pages?
<IMG> Tag: We use the Image tag to place images in web pages. The Image tag has no
closing tag. But, it has one required attribute (src), along with few other attributes.
Src: identifies the URL of the image and must be enclosed in quotes. This is a
required attribute.
Srcset: Specifies the URL of the image to use in different situations
Alt: provides alternative text in case the image doesn't load. The alt text also
appears if the user moves the mouse cursor over the image for a few seconds.
Width, height: They specify the width and height of the image. If we only specify
one of these, the image will maintain it's aspect ratio, so we generally need to
indicate one or the other. The number specified can represent the size in pixels or
a percentage of the original width and/or height.
Usemap: Specifies an image as client side image map.
Ismap: Specifies an image as a server-side image-map
Sizes: Specifies image sizes for different page layouts
Longdesc: Specifies a URL to a detailed description of an image
To make the image 200 x 100 pixels in size, we use the following code.
<img src="www.smartclass.co/images/logo.jpg" alt="My Logo"
width="200" height="100">
19. How do you place objects or multimedia content in HTML pages? (Or) How do you play
Audio and Video files in HTML? (OR)
To embed multimedia content or to include objects such as images, audio, videos, Java
applets, ActiveX, PDF, and Flash, we use <object> and <embed> tags.
a) Object Tag: The object tag tells browser to include a multimedia application (java
applets, PDF, Falsh). The browser retrieves the file specified in the DATA attribute.
Example: <object data=“abc.swf” height=“200” width=“200”>
</object>
b) Embed tag: The embed-tag is similar to the object tag in that it allows us to include
multimedia in an HTML document.
Example: <embed src=“pokiri.mid” height=“200” width=“200”>
c) Audio tag: The <audio> tag defines sound, such as music or other audio streams.
Currently, there are 3 supported file formats for the <audio> element: MP3, WAV,
and OGG:
Example: <audio controls>
<source src="shapeofu.mp3" type="audio/mpeg">
</audio>
d) Video tag: The <video> tag specifies video, such as a movie clip or other video
streams.
Example: <video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
</video>
e) Source tag: Defines multiple media resources for media elements (<video> and <audio>)
20. What is Image Mapping? (Or) Write short notes on <MAP> and <AREA >tags.
Image mapping allows us to create clickable regions on a single image. These clickable
regions act like hyperlinks which on clicking open other documents or take us to other
locations. These are also known as hotspots. For this, we use <AREA> and <MAP> tags.
To create hotspots i.e. image mapping we follow the three steps listed below:
1. Create an image and set value (name of a map) to the attribute ‘usemap’.
2. Create the map identified by the name used in ‘usemap’. This includes <area>
tags to create clickable regions.
3. Create the clickable regions (rect or circle or polygon) by specifying
coordinates.
<AREA> tag: The <AREA> tag is used to divide a page in to some parts by means of
various shapes. This tag will take three attributes. The COORDS attribute gives the
value of the coordinates. The SHAPE attribute specifies the Shape of the area. Within
the area we can specify the HREF attribute. The total code under the <AREA> tag
should be enclosed within the <MAP> tag.
Example: The following program creates three hotspots (clickable regions) on the
image “planets.gif” using <IMG>, <MAP> and <AREA> tags.
<html>
<body>
<p>Click on the sun or on one of the planets </p>
<img src="planets.gif" width="145" height="126"
alt="Planets" usemap="#planetmap" />
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun"
href="sun.html" />
<area shape="circle" coords="90,58,3" alt="Mercury"
href="mercury.html" />
<area shape="circle" coords="124,58,8" alt="Venus"
href="venus.html" />
</map>
</body>
</html>
Output:
HTML allows mainly three types of lists. They can be used for giving numbers and
bullets to the lists. We can also nest the lists. The three types are:
1. Ordered List (OL)
2. Unordered List (UL)
3. Description List (DL)
1. Ordered List: This gives numbering to the list items. The numbering could be
Arabic numerals or roman numeral or alphabets depending on the value of the
‘type’ attribute of ordered list. The tag used is ‘<OL>’. We can also indicate start
value using 'start' attribute. The number order can be made to be in descending
order using reversed attribute. The different values of ‘type’ can be:
Type Description
1 The default. Uses Arabic numerals.
I Uses uppercase Roman numerals.
i Uses lowercase Roman numerals.
A Uses uppercase letters.
a Uses lowercase letters.
<html>
<body> Output:
<h1>Select a Fruit </h1>
<OL>
<LI> APPLE </LI>
<LI> MANGO </LI>
<LI> BANANA </LI>
</OL>
</body>
</html>
If we change the ‘type’ value to ‘I’ i.e. to get roman numerals, it is going to be like
this.
B- Com III - Web Programming
Apoorva Publishers 17
2. Unordered List: This gives bullets to the list items. The bullets by default are of
type circle. The tag used is ‘<UL>’. We don’t have 'type' attribute for this tag in
HTML5.
3. Description List: A kind of listing in which the terms using <DT> and its description
using <DD> can be taken. The following list demonstrates the description list. The
tag used for definition list is ‘<DL>’.
<!DOCTYPE html> Output:
<html>
<body>
<h1> ONLINE TUTORIAL</H1>
<DL>
<DT> HTML </DT>
<DD> Hyper Text Markup
Language </DD>
<DT> WWW</DT>
<DD> World Wide Web</DD>
<DT> CGI </DT>
<DD> Common Gateway
Interface</DD>
</DL>
</body>
</html>
22. Write about <TABLE> tag. (Or) How do you create tables in HTML?
<TR>: This tag is used to define a Table Row. Each table row is delimited by the <TR>
and </TR> tags. Table rows are nested within the table element described above.
<TD>: This tag is used to define Table Data i.e. value in each cell. Each cell (or table
data) is delimited by the <TD> and </TD> tags. The cells are nested within the table row
element.
<TH>: This tag produces a row, which is normally used has header row. Each table
header is delimited by the <TH> and </TH> tags. Most browsers display the content of
a table header cell in boldface.
Example:
<html>
<html>
<body>
<h1> Marks Memo </H1>
<table>
<tr>
<th> Name </th> <th> Rno </th>
<th> Marks </th>
</tr>
<tr>
<td> Ravi </td> <td> 33 </td> Output:
<td> 500 </td>
</tr>
Marks Memo
<tr> Name Rno Marks
<td> Kiran </td> <td> 44 </td>
<td> 600 </td>
</tr> Ravi 33 500
<tr>
<td> Raju </td> <td> 55 </td>
<td> 700 </td> Kiran 44 600
</tr>
</table>
</body> Raju 55 700
</html>
23. Write about Column spanning and Row spanning in tables with an example. (Or) Explain
Spanning columns and Rows in a table with the help of an example.
Spanning Column: The following code displays a table that has a cell
which spans in two columns. For this, we used colspan=2 for the cell of the
first row.
Output:
<table>
<tr> <td colspan=2> APOORVA APOORVA
</td> </tr>
<tr> <td> Degree College </td>
<td> MBA College </td> </tr> Degree College MBA College
</table>
Spanning Row: The following code displays a table that has a cell, which
spans in two rows. For this, we used rowspan=2 for the first cell of first row.
<table> Output:
<tr> <td rowspan=2> APOORVA Degree College
</td> <td> Degree College
</td></tr> APOORVA
<tr> <td> MBA College </td> MBA College
</tr>
</table>
24. How do you create links in HTML? (Or) Write about <A HREF> tag.
A link or hyperlink is some highlighted text which on clicking takes to other page, or
other website or another location in the same page. Hyperlinks facilitate non-linear
reading. HTML allows us to create hyperlinks using anchor tag. Anchor tag has one
mandatory attribute ‘href’ which specifies the target page or location. The text that
acts like hyperlink should be delimited by <a> and </a>. An anchor can point to any
resource on the Web: an HTML page, an image, a sound file, a movie, etc.
Examples:
B- Com III – Web Programming
20 Apoorva Publishers
The following link which on clicking takes to a website
<a href="www.winningbrains.com”> See More </a>
The following link which on clicking takes to another page in the same website
<a href="../index2.html”> Learn More </a>
The following link which on clicking takes to another location in the same page. For
this, we need to assign a name to the target location.
<a href="#advantages"> See advantages </a>
………
<a name=”advantages”> … </a> …
The following link which on clicking opens an image
<a href=”logo.gif”> See The Logo </a>
The following link which on clicking opens the page in a new window.
<a href="../index2.html” target=”_blank”> Do More </a>
The commonly used attributes of the anchor tag are shown below.
Example: The following link which on clicking opens the page in a new window. This
uses ‘target’ attribute.
26. Write short notes on ‘target’ attribute of anchor tag. (Or) Explain how to open
documents trough hyperlinks in different ways (targets)
A link or hyperlink is some highlighted text which on clicking takes to other page, or
other website or another location in the same page. It uses an attribute called ‘target’,
which specifies where to open the linked document.
TARGET controls where the new document will be displayed when the user follows a
link. Most of the time, clicking on a link simply loads a new document in the same
window where the link is. However, with TARGET, we can have the new document
open in a new window, or in another frame or in the same or parent window.
Example: The following link, which on clicking opens the page in a new window. This
uses ‘target’ attribute.
<a href="../index2.html” target=”_blank”> Learn It </a>
27. How do you make an image as a hyperlink? (Or) How to create Graphical
Hyperlinks in HTML? Give an example.
Not only text can be made as a hyperlink, but also images can be made as hyperlinks.
Thus, when clicking on the given image, it opens the linked document or takes to a
book-marked location. This is something like creating graphical hyperlink.
This can be achieved with the same anchor tag <a>. Between the pair of an anchor
tag, we use <img> tag to make an image as hyperlink. This technique can be used to
display thumb nails which on clicking open the enlarged images or to represent
companies/sites by some images or by their logos, which is much effective than
displaying text.
Example:
28. What are Form Elements (Components)? Explain. (Or) Explain <FORM> tag in detail.
Forms: Forms are the most popular way to make web pages interactive. Like forms on
paper, a form on a web page allows the user to enter requested information and
submit it for processing.
<FORM> tag: The <form> tag is used to create an HTML form for user input. A form can
contain input elements like text fields, checkboxes, radio-buttons, submit buttons and
more. A form can also contain select menus, textarea, and label elements. Forms are
used to pass data to a server.
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
<FORM> tag Attributes: The commonly used <form> tag attributes are listed below.
<FORM>
name: <INPUT TYPE=TEXT NAME=pname> <BR> name:
password: <INPUT TYPE=PASSWORD
NAME=email> <BR> password:
<INPUT TYPE=SUBMIT>
</FORM> Submit Query
<INPUT> tag: The <input> tag is used to select user information. An input field can vary
in many ways, depending on the type attribute. An input field can be a text field, a
checkbox, a password field, a radio button, a button, and more.
This tag takes two main attributes: TYPE and NAME. TYPE indicates what kind of
element should appear on the form. NAME assigns a name to go with the input field.
The ‘type’ attribute can take any of the following values.
Text: Provides a single line text box.
Textarea: Provides a multiline text box.
Password: Same as the TEXT type, but characters are displayed as asterisks.
Button: Creates a button with which a user can initiate some action.
Submit: Creates a button labeled "submit". This on clicking sends information from
form-elements to a server.
Reset: Creates a button labeled "reset" in the form. Using this, a user can clear the
values of the form elements.
Checkbox: Produces an on-screen check box for users to make multiple choices
Radio: Creates a radio button for a range of selections from which the user may
select only one.
File: This displays a text box along with a “browse” that allows us to select files
from local computer. The selected file appears in the text box.
HTML5 has several new values for input's type attribute which include: color,
image, date, email, month, number, range, search, tel, time, url and week.
<FORM>
name: <INPUT TYPE=TEXT NAME=pname> <BR> name:
password: <INPUT TYPE=PASSWORD
NAME=email> <BR> password:
<INPUT TYPE=SUBMIT>
</FORM> Submit Query
<LEGEND> is used with <FIELDSET> to give a title to each set of fields. This is very useful
to show the separation of groups with a border and title and it is more visually
appealing.
The <fieldset> tag is used to logically group together elements in a form.
The <fieldset> tag draws a box around the related form elements.
The <legend> tag defines a caption for the fieldset element.
Example: Output:
<FIELDSET>
<LEGEND> Personal Details
</LEGEND>
<BR>
name: <INPUT NAME="pname">
<BR>
email: <INPUT NAME="email">
</FIELDSET>
32. Write short notes on <FRAME> tag. (Or) Explain Frames in HTML? (Or) What is a
Frameset? Explain how to create Horizontal and Vertical Frames.
Frames are achieved by creating a frameset page, and defining each frame from within
that page. This frameset page doesn't actually contain any content - just a reference to
each frame. The HTML <frame> tag is used to specify each frame within the frameset.
All frame tags are nested with a frameset tag.
So, in other words, if we want to create a web page with 2 frames, we would need to
create 3 files - 2 files for two frames, and 1 file to specify how they fit together.
The frameset Tag Attributes: In the frameset tag, we specify either cols or rows,
depending on whether we want frames to be displayed vertically or horizontally. The
common attributes in <frameset> tag are:
Attribute Description
rows Specifies the number of rows and their height in pixels, percentages,
or relative lengths. Default is 100%
cols Specifies the number of columns and their width in either pixels,
percentages, or relative lengths. Default is 100%
The frame Tag Attributes: For each frame we want to display, we specify a frame tag.
We nest these within the frameset tag. The common attributes in <frame> tag are:
Attribute Description
name Assigns a name to a frame. This is useful for loading contents
into one frame from another.
src Location of the frame contents (for example, the HTML page to
be loaded into the frame).
noresize Specifies whether the frame is resizable or not (i.e. whether the
user can resize the frame or not).
scrolling Whether the frame should be scrollable or not (i.e. should
scrollbars appear). Possible values are : yes, no, auto
frameborder Whether the frame should have a border or not. Possible values
are : 0 or 1
marginwidth Specifies the margin, in pixels, between the frame's contents
and it's left and right margins.
marginheight Specifies the margin, in pixels, between the frame's contents
and it's top and bottom margins.
<html> Output:
<frameset cols="25%,50%,25%">
<frame src='a1.html'>
<frame src='a2.html'>
<frame src='a3.html'>
</frameset>
</html>
<html>
<frameset
rows="50%,30%,20%">
<frame src='a1.html'>
<frame src='a2.html'>
<frame src='a3.html'>
</frameset>
</html>
A nested frame is a frame within another frame. Here, we need to use one frameset in
another frameset. The second frameset comprising two or more other frames takes the
position of second frame in the outer frameset.
Example: Following program uses nested frames. The outer frameset uses horizontal
farming and the inner frameset uses vertical framing. Here, ‘a1.html’, ‘a2.html’ and
‘a3.html’ have to be created first.
Inline or “floating” frame is the one, which appear on a page like an ordinary element
such as tables or images. Using an inline frame, we can display a html page within
some other html page. The tag used for inline frames is <iframe>. The attributes of this
tag are listed below.
src: This allows us to specify the URL of the document in the frame.
width: This allows us to specify the frame’s length, in pixels.
height: This allows us to specify the frame’s height, in pixels.
Name: This is to set the name of the frame
Srcdoc: Specifies the address of the document to embed in the <iframe>
Example: The following program uses an inline frame to display a previously created
html file “a1.html”.
Output:
<html>
<body bgcolor=green>
<center>
<h1> INLINE FRAMES </H1>
<iframe src='a1.html' >
</iframe>
</center>
</body>
</html>
<HR> tag: The <hr> tag tag defines a thematic break in an HTML page (e.g.
a shift of topic).. The hr element can be used to separate content in an
HTML page. It is an empty i.e. has no closing.
Example:
<p>HTML is a formatting language.....</p>
<hr>
<p>CSS defines how to display HTML elements.....</p>
HTML5 offers new semantic elements that define the different parts of a
web page. We can also call them HTML Layout Elements.
Example: The following program shows how to use these semantic layout
elements.
<!DOCTYPE html>
<head>
<title>My Title</title>
</head>
<body>
<header>
<nav>..navigation menu links
here…</nav>
</header>
<article>
<section>…</section>
<section>…</section>
<section>…</section>
</article>
<aside>…</aside>
<footer>…</footer>
</body>
</html>
HTML Layout - Using Tables: The simplest and most popular way of creating
layouts is using HTML <table> tag. These tables are arranged in columns and
rows, so you can utilize these rows and columns in whatever way you like. But
layouts using tables is not recommended.
Example: The following HTML layout example is achieved using a table with 3
rows and 2 columns but the header and footer column spans both columns
using the colspan attribute.
<!DOCTYPE html>
<html>
<body>
<table width = "100%" border = "0">
<tr>
<td colspan = "2" bgcolor= "cyan">
<h1>Main title</h1>
</td>
</tr>
<tr>
<td bgcolor = "green" width = "50">
<b>Main Menu</b><br />
HTML<br />
PHP<br />
PERL...
</td>
<td width="100" height="200">
Welcome to Apoorva group of Colleges
</td>
</tr>
<tr>
<td colspan=2 bgcolor="cyan">
<center>
Apoorva Degree College
</center>
</td>
</tr>
</table>
</body>
</html>
39. How to create Layouts using Layout tag? (or) Write short notes on Layout tag.
<LAYER> tag: The HTML <layer> tag (not valid in HTML5) is used to position and
animate (through scripting) elements in a page. A layer can be thought of as a separate
document that resides on top of the main one, all existing within one window. This tag
has support in Netscape browsers. The common attributes supported by this tag are:
left/ top: The LEFT and TOP parameters specify the horizontal and
vertical positions of the top-left corner of the layer.
bgcolor Specifies the background color of the layer.
width/ height The width and height parameter determine the width and
height of the layer at which the layer's contents wrap.
visibility The VISIBILITY parameter determines whether the layer is
DHTML: DHTML stands for dynamic HTML. DHTML is not a programming or markup
language like HTML. It is a term that is used to describe the creation of dynamic and
interactive pages. One of the advantages of DHTML for web design and clients is that it
can combine the use of HTML, JavaScript/VBScript, XML and CSS (Cascading Style
Sheets).
HTML is capable of producing only static pages i.e. the information that it shows in a
page cannot be user-specific and it cannot facilitate user interaction. But, dynamic
content can very well facilitate user interaction or the pages can be made user-specific
and time-specific or it allows the users to set their own settings to view pages.
For example, a page may recognize the user and greet him with his name or it may ask
the user to fill in information and perform validity or calculations on it.
To design a web site with dynamic content, we need a set of technologies like HTML,
CSS, JavaScript/VBScript, XML etc. This technological integration is nothing but DHTML.
Advantages:
DHTML is more efficient for content management purposes.
A rich set of graphical capabilities can be implemented
Allows for event driven programming
DHTML results in faster and fresher content, which is more visually appealing.
Both content and layouts can be quickly manipulated
DHTML content loads very fast
Support for XML
Supports DOM (Document Object Model)
Disadvantages:
Costly Editing tools: Although DHTML provides great functionality but the DHTML
editors available are expensive. Dreamweaver is an example of HTML editor.
Long and Complex coding: DHTML coding is long and complex.
HTML DHTML
HTML stands for HyperText Markup DHTML stands for Dynamic HTML
Langauge
It is an application of SGML. It is a technological integration of HTML,
VBScript, JavaScript, CSS and etc.
It is a sequential formatting language DHTML is not a language. It includes
programming through scripts and uses
DOM (Document Object Model)
This can produce only static content This can produce dynamic content
HMTL forms basis for DHTML DHTML uses HTML and depends on that.
Browse dependent Browser and Script dependent
No event handling, No validations, styles It supports event handling, validations
and styles
CSS: CSS stands for Cascading Style Sheets. Cascading Style Sheet (CSS) is a style sheet
language used to describe the presentation semantics (the look and formatting) of a
document written in a markup language. The common application of CSS is to style web
pages written in HTML and XHTML, but the language can also be applied to any kind of
XML document.
Syntax: CSS has a simple syntax and uses a number of English keywords to specify the
names of various style properties. A style sheet consists of a list of rules. Each rule
consists of one or more selectors and a declaration block. A declaration-block consists
of a list of declarations in braces. Each declaration itself consists of a property, a colon
(:), a value, then a semi-colon (;). The syntax is shown below.
The selector is normally a HTML element or our own class or id we want to style.
Each declaration consists of a property and a value.
B- Com III – Web Programming
36 Apoorva Publishers
The property is the style attribute we want to change. Each property has a value.
Types of properties supported by CSS: The main capabilities of CSS are its support for
the following.
Font properties such as type, size and emphasis
Color of text, backgrounds, and other elements
Text attributes such as spacing between words, letters, and lines of text
Alignment of text, images, tables and other elements
Margin, border, padding, and positioning of elements
Advantages:
CSS can be made dynamic by using them in Scripts. With a simple change of one
line, a different style sheet can be used for the same page
It facilitates Separation of content from presentation (styles)
Site-wide consistency, the global style sheet can be used to affect and style
elements site-wide.
Bandwidth, a style sheet is stored in the browser cache. Therefore, it can be used
on multiple pages without being reloaded, reducing data transfer over a network.
Disadvantages:
Poor layout controls
There are control limitations to place elements vertically
We cannot use mathematical expressions in the place of values
Lack of column declaration i.e. multiple columns are complex to implement.
Pseudo-class (like :hover, :first-line) dynamic behavior not controllable
Example: The following program uses two HTML element selectors h1 and h2 to apply
styles on them.
<HEAD>
<TITLE>CSS Example</TITLE>
<STYLE TYPE="text/css">
H1 { font-size: x-large; color: red }
H2 { font-size: large; color: blue }
</STYLE>
</HEAD>
<body>
<h1> Hello </h1>
<h2> Apoorva </h2>
</body>
Style Sheet: A style sheet is used to describe the presentation semantics (the look and
formatting) of a document written in a markup language. The common application of
CSS is to style web pages written in HTML and XHTML, but the style sheets can also be
applied to any kind of XML document.
Types Style Sheets: CSS allows three types of style sheets, which are discussed below.
1. Inline styles: These are written inside the HTML document, style information on a
single element, specified using the "style" attribute
2. Embedded style: These are written as blocks of CSS information inside the HTML
using <style> tag.
3. External style sheets: These are separate “.CSS” files referenced from the
document.
4. Imported Style Sheets: These are used to import “.css” files from other servers.
Inline styles: These are written inside the HTML document, style information on a
single element, specified using the "style" attribute
The keyword style is followed by a quoted list of style properties and associated values,
connected with colons (:) and separated by semicolons (;). For instance, to set the font
family and font size for the text contained within a paragraph, the following inline style
sheet is coded inside the opening <p> tag.
Embedded Style Sheets: These are written as blocks of CSS information inside the
HTML using <style> tag. When a large number of style settings are used on a Web page,
we can use style settings together in one place as an embedded style sheet. An
embedded style sheet normally is coded inside the <head> section of the document
surrounded by a <style> tag. It applies styles across the entire Web page through
simple selectors, group selectors, contextual selectors, ID selectors, class selectors,
and sub-class selector whose general formats are shown below.
<head>
<style type="text/css">
tag {property:value; ...} /* Simple selector */
tag, tag,... {property:value; ...} /* Group selectors */
tag sub-tag ... {property:value; ...} /* Contextual selector */
#id {property:value; ...} /* Id selector */
.class {property:value; ...} /* Class selector */
tag.class {property:value; ...} /* sub-class Selector */
</style>
</head>
Example: The following program uses two one simple selector ‘h1’ and a class selector
“mystyle” to apply styling. Here, we have embedded the style definitions in the HTML
program using <style> tag.
<HEAD>
<TITLE>CSS Example</TITLE>
<STYLE TYPE="text/css">
h1 { font-size: x-large; color: red }
mystyle { font-size: large; color: blue }
</STYLE>
</HEAD>
<body>
<h1> Hello </h1>
<h2 class="mystyle"> Apoorva </h2>
</body>
For example, below is a set of style specifications contained within a text document
named “mysheet.css”
Any HTML page can apply these style settings by linking to this mysheet.css document
with a <link> tag coded in the <head> section of the page. With this, the page can have
all the styles defined in that linked file.
<head>
<link href="mysheet.css" type="text/css" rel="stylesheet">
</head>
<body>
<h1> Hello </h1>
<p> Welcome to Apoorva </p>
<h2 class="mystyle"> Thankyou </h2>
<body>
A style sheet may be imported with the @import statement. This statement may be
used in a CSS file or inside the STYLE element. This can be used to import .css files from
other directories or other servers. The following example shows importing .css files
from other server and other directory.
<style type="text/css">
tag {property:value; ...} /* Simple selector */
tag, tag,... {property:value; ...} /* Group selectors */
tag sub-tag ... {property:value; ...} /* Contextual selector */
#id {property:value; ...} /* Id selector */
.class {property:value; ...} /* Class selector */
tag.class {property:value; ...} /* sub-class Selector */
tag:pseudo-class {property:value; ...} /* pseudo-class Selector */
</style>
Simple Selectors: Here, we associate styles with an existing HTML tag. In this, the
tag name is followed by a set of properties and values enclosed within braces { }. For
instance, to set the font family and size for all paragraphs (the tag <p>) in a document,
the following simple selector entry is written. And, wherever a <p> tag is encountered
in the Web document, the browser applies these styles to its content.
<style type="text/css">
p {font-family:arial; font-size:9pt}
</style>
<p> Welcome to Apoorva </p>
Group Selectors: In a similar manner, identical styles can be applied to multiple tags
by listing the tag names separated by commas. In the following example, all <h1>,
<h2>, and <h3> tags appearing on the page will have the same styling.
<style type="text/css">
h1, h2, h3 {font-family:arial; color:blue}
</style>
<h1> Welcome to Apoorva </h1>
<h2> Welcome to Apoorva </h2>
<h3> Welcome to Apoorva </h3>
Contextual Selectors: A contextual selector gives the combination of tags and sub-
tags (or nested tags) separated by spaces. For example, the contextual selector in the
example below is P EM. This rule says that emphasized text within a paragraph should
have a yellow background; <em> in other tags or <p> tag alone or <em> tag alone
would not affect the text in those tags.
<style type="text/css">
P EM { background: yellow }
</style>
<p> <em> Welcome </em> </p> <!-- displayed with yellow background -->
<style type="text/css">
#MyPar {font-family:arial; font-weight:bold}
</style>
<p id="MyPar"> Welcome to Apoorva </p>
Class Selectors: A general style that can be applied to any tag is known as a style
class and is defined by assigning a class name, preceded by a period (.), to its style
properties. In the following example, a class named “.mystyle” is created. This can be
used in any tag as the value of “class” attribute with in that.
<style type="text/css">
.mystyle{font-family:arial; font-size:10pt; color:blue}
</style>
<p class="mystyle"> Welcome to Apoorva </p>
<h1 class="mystyle"> Know More </h1>
Sub-Class Selectors: A simple selector can have different classes, thus allowing the
same element to have different styles. For example, we may wish to display <h1> in a
different color depending on the class value it uses in the corresponding tag.
<style type="text/css">
H1.style1 { color: red }
H1.style2 { color: blue }
</style>
<h1 class="style1"> Know More </h1>
<h1 class="style2"> Grow More </h1>
A general style that can be applied to any tag is known as a style class and is
defined by assigning a class name, preceded by a period (.), to its style properties.
Style classes are also known as class selectors.
One element (tag) can have only one class attribute, but the same class can be
used in many different tags.
Style classes can be defined in embedded styles and external styles.
In the following example, a class named “.mystyle” is created. This can be used in
any tag as the value of “class” attribute with in that.
<head>
<style type="text/css">
.mystyle{font-family:arial; font-size:10pt; color:blue}
</style>
</head>
<body>
<p class="mystyle"> Welcome to Apoorva </p>
<h1 class="mystyle"> Know More </h1>
</body>
float Declares whether a box should float left, right, none div { float:left; }
to the left or right of other content or div { float:right; }
not
visibility Declares the visibility of an element Visible, hidden, div { visibility:visible; }
collapse div { visibility:hidden; }
caption-side Declares where the table top, bottom, left, caption { caption-side:top; }
caption is displayed in right caption { caption-side:right; }
relation to the table.
empty-cells Declares the way empty show, hide table { empty-cells:show; }
cells are displayed (if table { empty-cells:hide; }
border-collapse is
separate).
table-layout Declares the type of table auto, fixed table { table-layout:auto; }
layout table { table-layout:fixed; }
59. How to position the following elements using style sheet? Write a
program to position three images as shown in the figure below.
To position the images as shown in the above program, we use the CSS style property
‘position’ with ‘absolute’ as its value. When we use this option, the exact positioning
can be set using the properties left and top. The following program positions the three
images as required.
<html>
<body>
<img src="face.gif" width=100 height=100
style="position:absolute; left=0; top:0">
<img src="face.gif" width=100 height=100
style="position:absolute; left=100; top:100">
<img src="face.gif" width=100 height=100
style="position:absolute; left=200; top:200">
</body>
The CSS Box Model: All HTML elements can be considered as boxes. In CSS, the
term "box model" is used when talking about design and layout. The CSS box
model is essentially a box that wraps around every HTML element. It consists
of: margins, borders, padding, and the actual content. The image below
illustrates the box model:
The box model allows us to add a border around elements, and to define space
between elements.
Example
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: lightgrey;
width: 300px;
border: 25px solid green;
padding: 25px;