2 Understand Various HTML Tags and Usage of Style Sheets
2 Understand Various HTML Tags and Usage of Style Sheets
UNIT -2
Understand various HTML tags and usage of style sheets
2.1 Explain the link and imaging tags <a>, <img> with attributes.
Image tags
<img> tag embeds an image in an HTML page
Ex: <img src=”photo.jpg” width:”200px” height:”200px” />
Attribute Value Description
alt Text Specifies an alternate text for an image
src URL Specifies the URL of an image
%
Height Specifies the height of an image
pixels
%
width Specifies the width of an image
pixels
2.2 Explain<object> tag with attributes
<object> tag: The HTML <object> tag is used for embedding an object
within an HTML document. Use this tag to embed multimedia (like audio,
video, Java applets, ActiveX, PDF, and Flash) in your web pages.
You can use the <param> tag to pass parameters to plugins that have
been embedded with the <object> tag.
Ex:
<object width="400" height="400" data="helloworld.swf"></objec
t>
2.2.1 Explain the tags, <form>, <input>, <button>, <label>, <select>, <options>,
<textarea>, <legend> with attributes.
<input> Defines a text input control
<form> used to pass data to a server
<textarea> Defines multiline text input control
<input>:
Defines a text input control
Syntax: <input type=”element type” name=”name of text box” value=”value”/>
Attributes
Attribute Value Description
Attributes of <input>
Type: type of element. Possible values are
1. text : textfield
2. password : password field
3. radio : radio button
4. checkbox : checkbox item
5. submit : submit button
6. reset : reset button
Ex:
To display a textbox
<input type=”Text” />
To Display a password box, HTML code is
<input type=”password”/>
Example Program
<html><body>
<form>
Username: <input type=”text” name=”uname”/> <br/>
Password:<input type=”password” name=”pwd”/><br/>
Gender: <input type=”radio” name=”gender” value=”Male”>Male
<input type=”radio” name=”gender” value=”Female”>Female<br/>
Hobbies
<Input type=”Checkbox” name=”chess” value=”chess”> <br/>
<Input type=”Checkbox” name=”Cricket” value=”Cricket”> <br/>
<input type=”submit” value=”submit form”/>
</form>
</body></html>
Form tag
Attributes
Attribute Value Description
action URL Specifies where to send the form-data when a form is
submitted
enctype application/x-www-form- Specifies how the form-data should be encoded when
urlencoded submitting it to the server (only for method="post")
multipart/form-data
text/plain
method get Specifies the HTTP method to use when sending form-data
post
name text Specifies the name of a form
target _blank Specifies where to display the response that is received
_self after submitting the form
_parent
_top
Ex:
<label>
Defines a label for an input control
Syntax: <label for=”value”>content</label>
Attribute Value Description
Specifies the id of the form element the label should
for element_id
be bound to
Ex:
<label for=”name”>Name</label>
<input type=”text” id=”name” name=”name” />
<textarea>
Defines multi-line text input control
Syntax: <textarea rows = “No.of rows” cols=”No.of cols”> </textarea>
Attributes
Attribute Value Description
cols number Specifies the visible width of a text area
rows number Specifies the visible number of lines in a text area
maxlength number Specifies the maximum number of characters allowed
in the text area
name text Specifies a name for a text area
Example
<textarea name=”Resume” rows=100 cols=30>
Web Designing
</textarea>
<button>
Defines a push button.
<html><body>
<form>
Username : <input type=”text”/> </br>
<button type=”button” onclick=”function()”>Verify</button>
</form>
</body></html>
<select>
Defines a selection list or drop down list of items
The <option> tags inside the <select> element define the available options in the drop-down
list
Attributes
Attribute Value Description
multiple multiple Specifies that multiple options can be selected at once
name name Defines a name for the drop-down list
size number Defines the number of visible options in a drop-down list
<option>
Defines an item or option in a selection list
Ex:
<option>Chrome</option>
Attributes
Attribute Value Description
selected selected Specifies that an option should be pre-selected when
the page loads
value text Specifies the value to be sent to a server
Ex:
<Select id="browsers">
<option value="Edge">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</Select>
<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select id="cars" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<input type="submit">
</form>
</body>
</html>
<fieldset>
Defines a border around elements in form
<legend>
Defines a caption for a fieldset element
Ex:
<html><body>
<form>
<fieldset>
<legend>contact details</legend>
Name: <input type=”text”/> <br/>
Email: <input type=”text”/>
</fieldset>
<form>
</body>
</html>
2.3 Explain the tags, <frame>, <frameset>, <noframe>, <iframe> with attributes.
<frameset>
This tag is used to divide the window into various frames either horizontally or vertically.
Specifies how many columns are contained in the frameset and the size of each
column. You can specify the width of each column in pixels or percentage
Ex: cols = "100, 500, 100". It creates three vertical frames with a width of 100 pixels,
1 cols 500 pixels and 100 pixels
To Specify in percentage use cols = "10%, 80%, 10%".
To specify remainder of the window use *. Ex: cols=”10%,80%,*”
2
rows Specifies how many rows are contained in the frameset and the size of each row.
You can specify the width of each row in pixels or percentage
Ex: rows = "100, 500, 100". It creates three vertical frames with a width of 100
pixels, 500 pixels and 100 pixels
To Specify in percentage use rows = "10%, 80%, 10%".
To specify remainder of the window use *. Ex: rows=”10%,80%,*”
This attribute specifies the width of the border of each frame in pixels.
3 border
For example, border = "5". A value of zero means no border.
5 framespacing This attribute specifies the amount of space between frames in a frameset.
<frame>
This tag is used to display a web page in each frame
Attribut
Description
e
This attribute is used to give the file name that should be loaded in the
src
frame.
<noframes>
This tag is used to display a message in the browser that do not support the frames
Ex: <html>
<frameset rows="50%,50%">
<frame src="frame_a.html" >
<frameset cols="25%,75%">
<frame src="frame_b.html" >
<frame src="frame_c.html" >
</frameset>
</frameset>
</html>
frame_a.html
<html>
<body>
<h1>frame A</frame>
</body>
</html>
frame_b.html
<html>
<body>
<h1>frame B</frame>
</body>
</html>
frame_c.html
<html>
<body>
<h1>frame C</frame>
</body>
</html>
Output
Iframe
The <iframe> tag is used to embed another document within the current HTML document.
Attributes
Attribute Value Description
Specifies the height of an <iframe>. Default height is
height pixels
150 pixels
name text Specifies the name of an <iframe>
Specifies the address of the document to embed in
src URL
the <iframe>
Specifies the width of an <iframe>. Default width is
width pixels
300 pixels
<html>
<body>
</body>
</html>
CSS stands for Cascading Style Sheets. It is a web language-like HTML- which
you can be used to style your web pages. You can think of CSS as the instructions
that tell a web browser how to display your web page whereas HTML is intended
to provide instructions on what to display on your web page.
It is not necessary to use CSS as you can style your web page using entirely
HTML coding but it is immensely more convenient to use CSS. This is not to
mention the fact that CSS can do a lot more with regards to what kinds of bells
and whistles you can add to dress up your pages.
How to that are linked to it using the link element in the <head>.../head> tags.
This is the most powerful form of CSS as a single .css file can control the
formatting of many web pages at once.
Anyone or all three of the above methods can be applied to the same web
page at the same time. The order of precedence when all the three styles applied
to a single web page is
Inline Styles:
This applies CSS directly to each individual HTML element on your web page using
the style attribute.
Create Inline Styles:
The syntax used to create an inline style is
<element-name style="property: value; property: value; property: value;">
Where
element-name refers to the targeted HTML element
property refers to a CSS property
value refers to an associated CSS value
Points to remember about inline CSS syntax
The property and its associated value are separated by a colon (:)
Each property/value pair ends with a semi-colon (;)
Example:
<h1 style="color:blue;text-align:center;">This is a heading</h1>
Internal Style Sheets: This applies CSS to the current page. It primarily consists of
a list of CSS rule sets placed between a set of <style>...</style> tags which
themselves are inserted in between the <head>...head> tags of your web page.
Used to apply the same styles to multiple HTML elements at once on the current
page.
: Syntax
<html>
<head>
<title></title>
<style type="text/css">
<!..
…CSS rule sets go here...
-->
</style>
</head>
<body>
...web page content...
</body>
</html>
CSS Rule Sets: Now all we have to do is define some CSS rule sets. These will
associate a list of CSS properties with certain HTML elements on our web page.
Here’s the syntax you use to create a CSS rule set:
SELECTOR {property: value; property: value; property: value;}
where
SELECTOR refers to the HTML element you want to style..
property refers to a CSS property.
value refers to an associated CSS value.
Points to remember about CSS syntax in Internal style sheets:
The list of property/value pairs are enclosed in a set of curly braces
The property and its associated value are separated by a colon ()
Each property/value pair ends with a semi-colon (G)
Example:
<html>
<head>
<title>/title>
<style type="text/css">
P {color: green; font-size: 20px;}
<style>
</head>
<body>
<p>...This is para lin green...p>
<p>...This is para 2 in green...<p>
<p>...This is para 3 in green...clp>
<p>...This is para 4 in green...p>
<body>
<html>
Note: Style is defined only once to <p> but it is applied to all paragraphs
automatically in current webpage.
.
External style sheets
Using external style sheets allows you to apply formatting to many different web
pages at once with a single .css file.
The link element can be used among other things, to specify that a
web page should use an external style sheet. The link element only requires
a start tag <link> and is inserted in between the <head>...c/head> tags of
your web.
The link element employs three important attributes: rel, type and href.
For CSS. the value of the rel attribute is always stylesheet and the value of
the type attribute is always text/css. The only part of the code you really
have to concern with is the value of the href attribute which will change
according to which .css file you're referring to.
This value can be any relative or absolute path.
Style Conflicts
When there is more than one style specified for an HTML element, Rules are applied with
following priority order.
So, an inline style has the highest priority, and will override external and internal styles and
browser defaults.
The element selector selects HTML elements based on the element name.
Example
Here, all <p> elements on the page will be center-aligned, with a red text color:
p {
text-align: center;
color: red;
}
The id selector uses the id attribute of an HTML element to select a specific element.
The id of an element is unique within a page, so the id selector is used to select one unique
element!
To select an element with a specific id, write a hash (#) character, followed by the id of the
element.
Example
The CSS rule below will be applied to the HTML element with id="para1":
#para1 {
text-align: center;
color: red;
}
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by the class name.
Example
In this example all HTML elements with class="center" will be red and center-aligned:
.center {
text-align: center;
color: red;
}
You can also specify that only specific HTML elements should be affected by a class.
Example
In this example only <p> elements with class="center" will be red and center-aligned:
p.center {
text-align: center;
color: red;
}
Color property
Colors are specified using predefined color names, or RGB, HEX, HSL, RGBA, HSLA values
Examples
background.
This poroperty is used to set background –color and background-image
CSS Syntax
background: bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-
attachment
Ex:
body {
background: lightblue url("img_tree.gif") no-repeat fixed center;
}
background-color
background-image
background-position
background-size
background-repeat
background-origin
background-clip
background-attachment
Case 3: value1 is xpos and value2 is ypos: The xpos is the horizontal
position and the ypos is the vertical. The top left corner is 0. Units can
be pixels (0px 0px) or any other CsS units. If you only specify one
value, the other value will be 50%. You can mix % and positions
Example: background-position:200 300
Example program 1:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url('c:/css.jpg')
background-repeat:no-repeat;
background-attachment:fixed;
/style>
</head>
<body>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
sp>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to seroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
</body>
</html>
Output when you scroll the image will be fixed but the text will be
scrolled.
The background-image is fixed. Try to scroll down the page.
*****
The background-image is fixed. Try to scroll down the page
The background-image is fixed. Try to scroll down the page
The background-image is fixed. Try to scroll down the page
The background-image is fixed. Try to scroll down the page
The background-image is fixed. Try to scroll down the page
The border property is a shorthand property for the following individual border properties:
border-width
border-style
border-color
Example
p {
border: 5px solid red;
}
Individual Properties
The border-width property specifies the width of the four borders in in px, pt, cm, em
p.one {
border-width: 5px;
}
The border-style property specifies what kind of border to display. Value can be dotted, dashed,
solid, double, etc.
p.one {
border-style: solid;
}
The border-color property is used to set the color of the four borders. Color can be
name, Hex, RGB, etc.
p.one {
border-color: red;
}
CSS Margins
The CSS margin properties are used to generate space around elements i.e. sets
the size of the white space outside the border. CSS have full control over the
margins and sets the margin for each side of an element (top, right, bottom, and
left). The margin property defines the space around an HTML element. It is
possible to use negative values to overlap content.
Margin-Individual Sides
CSS has properties for specifying the margin for each side of an
element:
Margin: sets 4 margins to the same size.
margin-top: sets only top margin to the specified size.
margin-right: sets only right margin to the specified size.
margin-bottom: sets only bottom margin to the specified size.
margin-left: sets only left margin to the specified size.
All the margin properties can have the following values:
auto - the browser calculates the margin
length - specifies a margin in px, pt, cm, etc.
%-specifies a margin in % of the width of the containing
element.
inherit specifies that the margin should be inherited from the
parent element.
Example: The following example sets different margins for all four
sides element:
P
{
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
Example: for first Para set all margins to 25px and second paragraph
with left 150px, top:150px, bottom 2% of width and right as 130px
with blue solid boarder of 5px.
<html>
<head>
</head>
<body>
<p style="margin: 25px; border:1px solid black;">
all four margins will be 25px
</p>
<p style="margin-top: 150px margin-left: 150px margin-bottom:2%
margin- right:130px;border:5px solid blue;">
Margins: top 150px left 150px bottom 2% right 130px
<p>
</body>
html>
Output is
All four margins wiil be 25px
CSS Padding
The CSS padding properties are used to generate space around content. The
padding clears an area around the content (inside the border) of an element.
With CSS, you have full control over the padding. There are CSS properties for
setting the padding for each side of an element (top, right, bottom, and left).
Padding Individual Sides: CSS has properties for specifying the padding for each
side of an element:
• The padding-bottom specifies the bottom padding of an element.
• The padding-top specifies the top padding of an element.
• The padding-left specifies the left padding of an element.
• The padding-right specifies the right padding of an element.
• The padding serves as shorthand for the preceding properties
All the padding properties can have the following values:
Length - specifies a padding in px, pt, cm, etc.
%- specifies a padding in % of the width of the containing element
Inherit - specifies that the padding should be inherited from the parent
element.
The following example sets different padding for all four sides of a <p> element.
Example
P{
padding-top: 50px:
padding-right: 30px
padding-bottom: 50px;
padding-left: 80px:
}
Example 2: For first Para set all paddings to 25px and second paragraph
with puddings left 150px. top:150px. bottom 2% of width and right as 130px
with blue solid boarder of 5px.
Output:
all for paddings will be 25px
Paddings top 150px left 150px bottom2% right:130px