HTML and Css
HTML and Css
Introduction
1. Tim Berners-Lee developed html. HTML stands for Hypertext Markup Language basis
for creating a web page. The html programs output can be seen after using browser.
2. It is object-based language, not an object oriented language (like java), neither a
procedural language (like c, FORTRAN e.t.c).
3. Html pages can be developed to be simple text or to be complex multimedia program
containing sound, moving images and java applets.
4. Html is considered to be the global publishing format for Internet. It is not a
programming language.
5. HTML standards are created by a group of interested organizations called W3C (World
Wide Web consortium).
6. In HTML use tags specifies formatting. A tag is a format name surrounded by angle
brackets. End tags that switch a format off also contain a forward slash.
7. Html documents are saved with dot htm or html extension.
8. Html documents will run on any browser.
1. Body Tag
1. It contain some attributes such as bgcolor, background etc.
2. To change the color of links or of the page background hexadecimal values are placed
in the <body> tag.
3. Background attribute will take the path of the image, which you can place as the
background image in the browser.
4. The vlink attribute sets the color of links visited recently, alink the color of a currently
active link. The six figure hexadecimal values must be enclosed in double quotes and
preceded by a hash (#).
4. Hr Tag
It places a horizontal line across the system to break the page and contains attribute
width, which draws the horizontal line with the screen size of the browser. This tag does
not require an end tag.
<Hr width=”50%” Align=”left” size=”5” NOSHADE>.
6. Font Tag
It sets font size, color and relative values for a particular text.
<Font size=”10” color=”#f1f2f3” face=”face name”>
7. Bold Tag
It is used for implement bold effect on the text.
<B>text displayed in bold </b>
8. Italic Tag
It implements italic effects on the text.
<I> text displayed in italic</I>
9. Strong Tag
This tag is used to always emphasize the text.
<Strong>emphasize text</strong>
10. Tt Tag
It is used to give typewriting effect on the text.
<Tt> typewriting effect on the text </tt>
21. Em Tag
It is used for Emphasis (new standard for italics).
<EM>Text</EM>
<Html>
<Head><title>Tags demonstration</title></head>
<Body bgcolor="blue" text="yellow">
<H6 align="center"> Header1</h1>
<H5 align="center"> Header2</h2>
<Hr size=5 width=60% align="center">
<Base font size=4>
Base font
<P> paragraph</p>
<B>bold tag</b><br>
<I>Italic Tag</I><br>
<Tt>Typing text effect</tt><br>
<Strong> strong</strong><br>
&Quot quote "<br>
Subscript <B>CO<sub>2</sub></B>  
superscript<B>a<sup>2</sup>+b<sup>2</sup></B><br>
Ampersand &<br>
Less than <<br>
Greater than ><br>
<U>Underline Tag</U><br>
<S>Strike Tag</s><br>
<Del>Strike Tag</del>
<Pre>Pre Tag</Pre>
<Samp>code sample text</samp><br>
<Var>Small fonts, fixed width</var><br>
<Address>address tag</Address>
<Em>Emphasis (for italics)</Em><br>
<A href=”c:\”> Anchor Tag</A>
</body>
</html>
Lists
It is a collection of items. Lists are of five types. They were
a. Ordered lists. b. Unordered lists.
c. Definition lists. d. Directory lists.
e. Nested list.
Ordered lists
1. In this list of items have an order that is signified by numbers.
2. Ordered lists are also called as numbered lists.
3. Ordered lists starts with <OL> tag which followed by<LI>tag and ends with </OL>.
4. Different Ordered lists types like numeral lists, alphabetic list e.t.c can be specified
with TYPE attribute.
Syntax
<OL Type=1 or I or a or A or i Start=value>
<Li>Item Name1
-----------
<Li>Item Name n
</OL>
Example
<Html>
<Head><Title>ordered lists</title></head>
<Body>
Numbered lists Output
<OL TYPE=1 START=4>
<Li>Item 1
<Li>Item 2
</OL>
Alphabetic list
<OL TYPE=a START=2>
<Li>Item 1
<Li>Item 2
</OL>
Unordered lists
1. It is used to present a list of items, which are typically separated by white space and or
marked by bullets.
2. Unordered lists are also called as unnumbered lists.
3. Unordered lists starts with <UL> tag which followed by<LI>tag and ends with </UL>.
Syntax
<UL Type=Square or disk or circle>
<Li>Item Name1
<Li>Item Name2
-----------
<Li>Item Name n
</UL>
Example
<Html> Output
<Head><Title>Unordered lists</title></head>
<Body>
Unordered list
<Ul TYPE=circle>
<Li>Item 1
<Li TYPE=square>Item 2
<Li>Item 3
<Li TYPE=disk>Item n
</Ul>
</body>
</html>
Definition List
1. Definition list tag<DL> numbers or bullet is not used in front of the list item. Instead
it uses definition for the items. <DD>, <DT> are sub tags of <DL>.
2. Definition term tag <DT> is used for marking the items whose definition is provided
in the next data definition.
3. Definition description tags <DD>, definition of the terms are enclosed within these
tags. The definition may include any text or block.
Example
<Html>
<Head><Title>Definition lists</title></head>
<Body>
<Dl>
<DT> Web Technologies</DT>
<Dd> This subject is related to the technologies used in web applications</dd>
</dl>
</body>
</html>
Output
Web Technologies
This subject is related to the technologies used in web applications
Directory Lists
1. It is used to present a list of items containing up to 20 characters each.
2. It start with <DL> followed by <LI> tag ends with </DL>.
3. It may be arranged in columns, typically 24 characters wide.
4. Instead <DIR> we use <UL> because it is a deprecated tag and is not preferable to use.
Example Output
<Html>
<Head><Title>Directory lists</title></head>
<Body>Directory lists
<DIR>
<Li>Item 1
<Li>Item 2
</DIR>
</body>
</html>
Nested Lists
List with in another list is called as nested list.
Tables
1. A large data stored in a table can be easily referred because it provides an organized
and systematic display of data.
2. Spanning of cells is possible that is you can merge some sequence of rows or columns
with the help of ROWSPAN or COLSPAN attributes respectively.
<HTML>
<HEAD><TITLE>Table</TITLE><HEAD>
<BODY>
<table align="center" border="4" bgcolor="green"
bordercolor="white" >
<Caption>Student details</caption>
<THEAD>
<TR>
<Th>Name</Th>
<Th>Class</Th>
<Th>Branch</Th>
<Th>Roll no</Th>
</TR>
</thead>
<TR>
<td>a</td>
<td>1</td>
<td>cse</td>
<td>1</td>
</TR>
<TR>
<td>b</td>
<td>1</td>
<td>cse</td>
<td>2</td>
</TR>
<Tfoot>Table Foot</tfoot>
</Table>
</BODY>
</HTML>
<HTML>
<HEAD><TITLE>Table</TITLE><HEAD>
<BODY>
<table align="center" cellpadding="5" cellspacing="4" border="4" bgcolor="green"
bordercolor="white" >
<THEAD>
<TR>
<Th rowspan=2>Features</Th>
<Th colspan="2">Companies</Th>
</TR>
<TR>
<Th>Compaq</Th>
<Th>laser</Th>
</TR>
</thead>
<TR><td>price</td> <td>1</td> <td>2</td>
</TR>
</Table>
</BODY>
</HTML>
FORMS
1. Html provides several user interface elements to accept data from user using Form.
I.e. Forms are the best way of adding interactivity of element in a web page. They are
Usually used to let the user to send information back to the server but can also be used to
Simplify navigation on complex web sites.
2. Html form is used to create user interface screens. Action and method are the two
attributes of form.
4. Attributes of form
a. Name b. Action c. Method.
NAME
Any name can be given to form.
ACTION
It indicates path to the script.
I.e. when user submits the form where it should go is given in action attribute.
METHOD
1. It specifies how the data entered in the form is sent to the destination, which may be
the web server.
2. There are two methods of sending of information.
a. Post.
b. Get.
POST METHOD
1. It sends the information along with the body of the html page.
2. Data is not visible while sending.
3. Provides security.
4. Can send any number of characters can be send.
5. Special characters are also possible to send.
GET METHOD
1. It sends the data along with web page address that is appended to the URL.
2. Data is visible in site address.
3. No security, because password also sent like this.
4. Only limited number of characters.
5. Special characters are not possible to send, only for standard characters.
2. Write an html program which uses form attributes action and method to open
local drive c and add html page
<Html>
<Head><title>form get and post methods</title></head>
<body bgcolor="blue" text="yellow">
<form Name="f1" method="get" action="C:\">
<input type="submit" value=" Get method open Cdrive " >
<input name="n1" type="reset" value="reset" ></br>
</form>
2. The attribute type is used to implement text, password, checkbox, and radio and submit
button e.t.c.
FILE
A file upload element.
HIDDEN
No field is presented to the user, but the content of the field is sent with the submitted
form. This value can be used to transmit state information about client/server interaction.
IMAGE
An image field which you can click, causing the form to be immediately submitted. The
coordinates of the selected point are measured in pixel units from the upper-left corner of
the image, and are returned (along with the other contents of the form) in two name/value
pairs. The x-coordinate is submitted under the name of the field with .x appended, and the
y-coordinate is submitted under the name of the field with .y appended. Any
VALUE=attribute is ignored. The image itself is specified by the SRC= attribute, exactly
as for the Image element.
PASSWORD
The same as the TEXT attribute, except that text is not displayed as the user enters it.
RADIO
Used for attributes that accept a single value from a set of alternatives. Each radio-button
field in the group should be given the same name. Only the selected radio button in the
group generates a name/value pair in the submitted data. Radio buttons require an explicit
Value attribute.
RESET
It is a button that when pressed resets the form's fields to their specified initial values.
The label to be displayed on the button may be specified just as for the SUBMIT button.
SELECT-MULTIPLE
Specifies a multiple select list box.
SELECT-ONE
Specifies a single-select list box.
SUBMIT
It is a button, when it is pressed the form data is send to the corresponding sever of that
form.
TEXT
Used for a single-line text-entry field. Important Attributes of text are SIZE= and
MAXLENGTH=.
TEXTAREA
It is used to write the text. Used
for multiple-line text-entry fields. Use in conjunction with the
size and maxlength attributes.
LIST
It is used to have a list of item from which a user can choose. The name of the particular
select tag and the name of the chosen option are returned.
<Select name=”string”>…</select>
<Option value=”string” selected>…</option>
The select statement will have several options from which the user can choose. The
values will be displayed as the user moves through the list and the chosen one returned to
the server.
Frames
1. Normally only one HTML page can be displayed in the web browser at a time but
using the concept of frames more than one HTML page can be displayed on the browser
at a time.
2. Window is logically called as frame in HTML.
3. Collection of frame into a set is called as frameset, which provides facility to display
more than one page at a time on the browser.
I.e. frameset is collection of frames.
4. Web page that contains frame elements is called framed page.
5. Framed page begins with <FRAMESET> tag and ends with </ FRAMESET>.
6. Each individual frame is identified through <FRAME> tag.
7. Each HTML document is called a frame, and each frame is independent of the others.
FRAMESET Tag
It defines how to divide the window into frames each frameset defines a set of rows or
columns. The values of the rows/columns indicate the amount of screen area each
row/column will occupy.
<Frameset cols=” %, %” | rows=” %, %”> code</frameset>
<Frame name=”name” src=”filename” scrolling =” yes or no” frameborder =”0 or 1”>
ROWS ATTRIBUTE
It takes as its value a comma separated list of values. These values can be absolute pixel
values, percentage values between 1 and 100, or relative scaling values. The number of
rows is implicit in the number of elements in the list.
Example
1. For 3 rows, the first and the last being smaller than the center row:
<FRAMESET ROWS="20%, 60%, 20%">
2. For 3 rows, the first and the last being fixed height, with the remaining space assigned
to the middle row: <FRAMESET ROWS="100, *, 100">
COLS ATTRIBUTE
It takes as its value a comma separated list of values that is of the exact same syntax as
the list described above for the ROWS attribute.
BORDER ATTRIBUTE
It accepts a pixel value, which determines the thickness of any borders used within the
frame set.
FRAME Tag
This tag defines a single frame in a frameset. It has 6 possible attributes.
SRC ATTRIBUTE
It takes as its value the URL of the document to be displayed in this particular frame.
Frames without SRC attributes are displayed, as a blank space the size the frame would
have been.
NAME ATTRIBUTE
It is used to assign a name to a frame so it can be targeted by links in other documents
(These are usually from other frames in the same document.) The NAME attribute is
optional; by default all windows are unnamed.
Names must begin with an alphanumeric character. However, several reserved names
have been defined, which start with an underscore. These is currently:
_Blank always load this link into a new, unnamed window.
_Self always load this link over your self.
_Parent always load this link over your parent. (Becomes self if you have no parent).
_Top always load this link at the top level. (Becomes self if you are at the top).
MARGINWIDTH ATTRIBUTE
It is used when the document author wants some control of the margins for this frame. If
specified, the value for MARGINWIDTH is in pixels. Margins can not be less than one-
so that frame objects will not touch frame edges-and can not be specified so that there is
no space for the document contents. The MARGINWIDTH attribute is optional; by
default, all frames default to letting the browser decide on an appropriate margin width.
MARGINHEIGHT ATTRIBUTE
It is just like MARGINWIDTH above, except it controls the upper and lower margins
instead of the left and right margins.
SCROLLING ATTRIBUTE
It is used to describe if the frame should have a scrollbar or not. Yes results in scrollbars
always being visible on that frame. No results in scrollbars never being visible. Auto
instructs the browser to decide whether scrollbars are needed, and place them where
necessary. The SCROLLING attribute is optional; the default value is auto.
NORESIZE ATTRIBUTE
It has no value. It is a flag that indicates that the frame is not resizable by the user. Users
typically resize frames by dragging a frame edge to a new position. Note that if any frame
adjacent to an edge is not resizable, that entire edge will be restricted from moving. This
will affect the resizability of other frames. The NORESIZE attribute is optional; by
default all frames are resizable.
Disadvantages of Frames
1. The web developer must keep track of more HTML documents
2. It is difficult to print the entire page
1. Write a program to divide a web page into two equal half’s and divide the second half
into two equal half using frames.
Open.html frame1.html
<Html> <font size="5">
<frameset rows="50%,50%"> <center>Frame1<center>
<frame src="frame1.html" noresize="noresize">
<frameset cols="50%,50%">
<frame src="fc1.html">
<frame src="fc2.html">
</frameset>
</frameset>
</html>
fc1.html fc2.html
<font size="5"> <font size="5">
<Center>Frame column1<center> <center>Frame column2<center>
Output
Selector
It is used to create a link between the rule and the HTML tag. The declaration has two
parts: a property and a value. Declarations must be separated using colons and terminated
using semicolons. Selector {property: value; property: value.}
<html><title>CSS Example</title>
<head>
<Style type="style sheet language">
h1 { color: blue ; }
</style>
</head>
Type Attribute
Style sheet language can be used specified to the browser that More than one language
is used by the style tag using type attribute of the HTML <style> tag.
Example specifies that the type is text/css; that is, text and cascading style sheet.
<Style type="text/css">
The Inline Type and the <style> Attribute
Inline style sheets are also embedded within an HTML document, but are assigned as an
attribute of the <style> tag in the body of the document and are useful for overriding an
already existing style for a particular element in a linked style sheet. On the negative side,
they have to be redefined for any element that requires that style, element by element. For
example, if the h1 element has been defined to be blue and you want to temporarily
change it to red, you can define the style as an attribute of the style tag for that element:
A class can be used on any of the HTML elements in the body of the document as long as
that element understands the style you have applied to it. To apply the class, you use the
class attribute. The class attribute is assigned the name of the class; for example, for the
<p> tag, you would stipulate <p class=name> where name is the name of the class.
Property Means
Bottom, right The placement of the bottom, right edges of an element
Position How to position the element on the page
Top, left The placement of the top, left edges of an element
Width, height The size in width and height of an element's content.
Visibility Whether an element can be seen
Z-index The third dimension in a stack of objects
Absolute Positioning
It places an element in a specific location on the page and can be used to achieve full
animation; for instance, moving an image across a page. It is used to specify the absolute
coordinates (x, y) of the element in terms of the browser window itself. The top and left
properties are used to determine the coordinates. If not specified, the browser will assume
the top left corner of the browser window, where x is 0 and y is 0. The top left corner of
the window is position 0,0 and the bottom right corner depends on the resolution of the
screen. If the screen resolution is set to 800 pixels in width and 600 pixels in height, the
bottom right corner is positioned at coordinates 800, 600.
<html> OUTPUT: -
<head> <title>layers</title></head>
<style type="text/css">
#first{
background-color: red;border-style: solid; font-weight:bold;top: 20;
position: absolute; left: 20; height: 100; width: 100;
}
#second{
background-color: blue; border-style: solid; font-weight:bold;
top: 30 ; position: absolute; left: 60; height: 100; width: 100;
}
#third{
background-color: orange;border-style: solid;font-weight:bold;
top: 40 ; position: absolute; left: 100;height: 100; width: 100;
}
</style>
<body>
<p id="first"> First position </p>
<p id="second">Second position </p>
<p id="third"> Third position </p>
</body>
</html>
Relative Positioning
It places the element in a position relative to the element where it is defined in the
document. In the following example the. ParaStyle class is positioned relative to where it
should be placed within its container, a div block.
The z-index and Three Dimensions
The last type of position sets the precedence of a stack of overlapping elements. The
absolute position properties include three coordinates: x, y, and z, where x is the left side
of an object, y is the right side, and z is the value of the stacking position. If you have
three containers layered on top of each other, the z position of the bottom layer is 0; the
next layer, 1; and the top layer in the stack is layer 2. JavaScript will allow us to move
these objects around, rearranging the stacking order dynamically, by manipulating the z-
position.
1. Write a program for demonstrating CSS internal style sheets and external style sheets.
Open.html
<Html>
<Head>
<Title>Style sheets</title>
<Link rel="stylesheet" type="text/css" href="csslink.html">
</head>
<style type="text/css">
Body {background-image: url("a.JPG")}
Body {background-color: blue}
</style>
<Body >
<a href="C:\" class="xlink" >cross link</a><br>
<a href="" class="hlink">help hair</a>
<p>HTML</p>
</body>
</html>