HTML Basics for Web Development
HTML Basics for Web Development
UNIT-1
HTML Introduction:
HTML stands for Hyper Text Markup Language. It is the standard language
used to create and structure content on the web.
HTML is a markup language, not a programming language, meaning it
annotates text to define how it is structured and displayed by web
browsers.
It forms the building blocks of all websites and is complemented by CSS for
style and JavaScript for interactivity.
Here are 4 common reasons to learn HTML:
1. Build Websites: HTML is the basic building block for creating any website.
Learning HTML can help you pursue a career in web development.
2. Customize Content: Allows you to edit or tweak web pages, emails, or
templates to fit your needs.
3. Understand how the web works: Helps you grasp how the internet works
and how web pages are structured.
[Link] Easily: HTML is beginner-friendly, making it a great first step into the
world of coding and technology
HTML tags:
HTML tags are the fundamental building blocks of web development,
providing the structure and organization necessary for creating web pages.
They include tags for headings, paragraphs, links, images, and more.
Commonly used tags like <html>, <head>, and <body> are essential for
creating a well-structured web document.
These tags provide the framework for building user-friendly and accessible
web pages.
Document structure tag
The <html> tag is essential, encapsulating the entire HTML document and
serving as the root element for content organization.
Structure
Tag Syntax Description
<html>
The root of the HTML document
<html> Statements...
specifies it as HTML.
</html>
0
Web Programming BCA – V Sem Sri Srinivasa Degree College
Structure
Tag Syntax Description
<head>
Contains head elements such as title,
<head> Statements...
style, and meta tags in the HTML file.
</head>
<title>
<title> Statements... Defines the title of an HTML document.
</title>
HTML elements:
An HTML element is defined by a start tag, some content, and an end tag:
Syntax:<tagname> Content goes here... </tagname>
The HTML element is everything from the start tag to the end tag:
Note: Some HTML elements have no content (like the <br> element). These
elements are called empty elements. Empty elements do not have an end tag!
1
Web Programming BCA – V Sem Sri Srinivasa Degree College
Ex:<html>
<body>
</body>
</html>
Output:
HTML attributes:
All HTML elements can have attributes
Attributes provide additional information about elements
Attributes are always specified in the start tag
2
Web Programming BCA – V Sem Sri Srinivasa Degree College
3
Web Programming BCA – V Sem Sri Srinivasa Degree College
From 1990 to 1995, HTML underwent changes and extensions, initially at CERN
and then at the IETF. The World Wide Web Consortium (W3C) became the new
home for HTML development.
Here you will see the evolution of HTML over the past couple of decades. The
major upgrade was done in HTML5 in 2012.
Year Progress
199 Tim Berners-Lee created HyperText Markup Language but it was not
1 officially released.
4
Web Programming BCA – V Sem Sri Srinivasa Degree College
199 Tim Berners-Lee created the first version of HTML that was published and
3 available to the public.
199 HTML 2.0 was released with a few additional features along with the
5 existing features.
199 There was an attempt to extend HTML with HTML 3.0, but it was
7 replaced by the more practical HTML 3.2.
199 The W3C (World Wide Web Consortium) decided to shift focus to an
8 XML-based HTML equivalent called XHTML.
199 HTML 4.01, which became an official standard in December 1999, was
9 the most widely used version in the early 2000s.
200
XHTML 1.0, completed in 2000, was a combination of HTML4 in XML.
0
5
Web Programming BCA – V Sem Sri Srinivasa Degree College
201 HTML5 can be seen as an extended version of HTML 4.01, which was
2 officially published in 2012.
It didn’t support audio and video It supports audio and video controls
without the use of flash player with the use of <audio> and <video>
support. tags.
Not possible to draw shapes like HTML5 allows to draw shapes like
circle, rectangle, triangle etc. circle, rectangle, triangle etc.
6
Web Programming BCA – V Sem Sri Srinivasa Degree College
HTML HTML5
Elements like nav, header were not New element for web structure like
present. nav, header, footer etc.
Attributes like charset, async and Attributes of charset, async and ping
ping are absent in HTML. are a part of HTML 5.
Features of HTML:
It allows the creation of hyperlinks with the <a> tag, connecting different
web pages.
Uses tags to mark elements and content, such as headings (<h1> to <h6>).
It supports embedding images (<img>), videos (<video>), and audio
(<audio>) for multimedia content.
It provides form elements like <form>, <input>, and <button> for user
input and data submission.
Semantic tags like <article>, <section>, and <nav> for better document
structure and accessibility.
7
Web Programming BCA – V Sem Sri Srinivasa Degree College
Features of HTML5:
Introduced new semantic elements like <header>, <footer>, <section>,
and <article> for improved structure.
Enhances multimedia capabilities with native support for audio and video
elements.
Provides the localStorage API, allowing web applications to store data
locally on the user’s device.
Enables websites to access a user’s geographical location.
Uses SQL database to store data offline.
8
Web Programming BCA – V Sem Sri Srinivasa Degree College
UNIT-2
CODING STANDARDS AND BLOCK ELEMENTS
9
Web Programming BCA – V Sem Sri Srinivasa Degree College
<body>
<p>Welcome to DataFlair.
</body>
4. Use Lowercase Attribute Names in HTML
Like elements, there is no clear distinction provided by HTML in using upper or
lower case names for attributes. However, it is good practice to use lowercase
letters for attribute names. Correct-
<a href="[Link] to DataFlair</a>
Incorrect-
<a HREF="[Link] to DataFlair</a>
Incorrect-
<table class= bordered>
Does not work-
<table class= table striped>
This does not work because of the spaces.
6. Specification of alt, width and height attributes of the image in HTML
It is an excellent practice to always specify the ‘alt’ attribute since it is the
alternative text that appears if the browser is unable to display the image.
Similarly, the height and width attributes reserve the space for an image
before loading and thus prevent flickering. Correct-
<img src="[Link]" alt="Tree" height="500px" width="500px">
Incorrect-
<img src="[Link]">
7. Spaces between equal signs in HTML
Though it is allowed to use spaces within equal signs, it is highly recommended
not to do so since it disrupts the readability of the code. Correct-
<a href="[Link] to DataFlair</a>
Incorrect-
<a href = "[Link] to DataFlair</a>
8. HTML Long Code Lines
It is advisable not to use too long lines of code and break them instead. This
prevents unnecessary scrolling from left to right.
10
Web Programming BCA – V Sem Sri Srinivasa Degree College
<html lang="en-US">
<head>
<title>Title</title>
</head>
<body>
<h1>Hi</h1>
<p>Welcome</p>
</body>
</html>
12. HTML Meta Data
The <meta> tag contains additional information related to the document such
as page description, keywords, author, character set, etc. The web browsers
use the metadata to display content, and keywords are used by search engines
and other web-services.
Character Set-
<meta charset="UTF-8">
It is a good practice to define the meta charset at the earliest in an HTML
document.
2. HTML Comments:
HTML comments are not displayed in the browser, but they can help
document your HTML source code.
11
Web Programming BCA – V Sem Sri Srinivasa Degree College
With comments you can place notifications and reminders in your HTML
code
Comments can be used to hide content.
This can be helpful if you hide content temporarily
You can also hide more than one line. Everything between the <!-- and the --
> will be hidden from the display.
Comments can be used to hide parts in the middle of the HTML code.
HTML Comment Tag
You can add comments to your HTML source by using the following syntax:
Ex:1: <html>
<body>
<p>This is a paragraph.</p>
<!-- <p>This is another paragraph </p> -->
<p>This is a paragraph too.</p>
</body>
</html>
Ex2:<html>
<body>
<p>This <!-- great text --> is a paragraph.</p>
</body>
</html>
12
Web Programming BCA – V Sem Sri Srinivasa Degree College
As a general rule, elements whose content model allows any flow content
should have either at least one descendant text node that is not inter-element
whitespace, or at least one descendant element node that is embedded
content. For the purposes of this requirement, del elements and their
descendants must not be counted as contributing to the ancestors of the del
element.
SECTIONING CONTENT
Sectioning content is content that defines the scope of headings and footers.
article, aside, nav ,section
Each sectioning content element potentially has a heading and an outline. See
the section on headings and sections for further details. There are also certain
elements that are sectioning roots. These are distinct from sectioning content,
but they can also have an outline.
HEADING CONTENT
Heading content defines the header of a section (whether explicitly marked up
using sectioning content elements, or implied by the heading content itself).
h1,h2,h3,h4, h5,[Link].
PHRASING CONTENT
Phrasing content is the text of the document, as well as elements that mark up
that text at the intra-paragraph level. Runs of phrasing content form
paragraphs.
As a general rule, elements whose content model allows any phrasing content
should have either at least one descendant text node that is not inter-element
whitespace, or at least one descendant element node that is embedded
content. For the purposes of this requirement, nodes that are descendants of
del elements must not be counted as contributing to the ancestors of the del
element.
Most elements that are categorized as phrasing content can only contain
elements that are themselves categorized as phrasing content, not any flow
content. Text, in the context of content models, means text nodes. Text is
sometimes used as a content model on its own, but is also phrasing content,
13
Web Programming BCA – V Sem Sri Srinivasa Degree College
and can be inter-element whitespace (if the text nodes are empty or contain
just space characters).
EMBEDDED CONTENT
Embedded content is content that imports another resource into the
document, or content from another vocabulary that is inserted into the
document.
audio, video, math, img etc
Elements that are from namespaces other than the HTML namespace and that
convey content but not metadata, are embedded content for the purposes of
the content models defined in this specification. (For example, MathML, or
SVG.)
Some embedded content elements can have fallback content: content that is
to be used when the external resource cannot be used (e.g. because it is of an
unsupported format). The element definitions state what the fallback is, if any.
INTERACTIVE CONTENT
Interactive content is content that is specifically intended for user interaction.
a,details,frame,input,select etc
Certain elements in HTML have an activation behavior, which means that the
user can activate them. This triggers a sequence of events dependent on the
activation mechanism,
4. Block elements:
Every HTML element has a default display value, depending on what type of
element it [Link] two most common display values are block and inline.
A block-level element always starts on a new line, and the browsers
automatically add some space (a margin) before and after the element.
A block-level element always takes up the full width available (stretches out to
the left and right as far as it can).
Two commonly used block elements are: <p> and <div>.
14
Web Programming BCA – V Sem Sri Srinivasa Degree College
Ex: <html>
<body>
<p style="border: 1px solid black">Hello World</p>
<div style="border: 1px solid black">Hello World</div>
<p>The P and the DIV elements are both block elements, and they will always
start
on a new line and take up the full width available (stretches out to the left and
right as far as it can).</p>
</body>
</html>
Output:
Hello World
Hello World
The P and the DIV elements are both block elements, and they will always start
on a new line and take up the full width available (stretches out to the left and
right as far as it can).
Some of the the block-level elements in HTML:
<address>,<article>,<aside>,<blockquote>,<canvas>,<div> ,<dt>,<fieldset>
<figcaption>,<figure>,<footer>,<form>,<h1><h6>,<header>,<hr>,<li>,<main>,
<nav>,<noscript>,<ol>,<p>.
15
Web Programming BCA – V Sem Sri Srinivasa Degree College
</body>
</html>
Output:
The blockquote element
Here is a quote from WWF's website:
For 50 years, WWF has been protecting the future of nature. The world's
leading conservation organization, WWF works in 100 countries and is
supported by 1.2 million members in the United States and close to 5 million
globally.
Attribute Description
accesskey Specifies a shortcut key to
activate/focus an element
class Specifies one or more classnames for
an element (refers to a class in a style
sheet)
contenteditable Specifies whether the content of an
element is editable or not
dir Specifies the text direction for the
content in an element
enterkeyhint Specifies the text of the enter-key on a
virtual keybord
hidden Specifies that an element is not yet, or
is no longer, relevant
id Specifies a unique id for an element
16
Web Programming BCA – V Sem Sri Srinivasa Degree College
Collapsing white spaces decreases the transmission time between the server
and the client because collapsing features remove unnecessary bytes that are
occupied by the white spaces.
By mistake, if you leave extra white space, the browser will ignore it and
display the UI perfectly.
Example 1: The following example shows the basic example for collapsing
white space. The h1 tag contains a lot of space between the short form and the
full form. If you run this code in the browser you will see the following output.
All the white space in between the two has been converted into a single white
space.
Ex: <html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Welcome to GFG. GeeksforGeeks.</h1>
</body>
</html>
7. Pre element:
The <pre> tag defines preformatted text. Text in a <pre> element is displayed
in a fixed-width font, and the text preserves both spaces and line breaks. The
text will be displayed exactly as written in the HTML source code. The <pre>
tag also supports the Global Attributes in HTML. The <pre> tag also supports
the Event Attributes in HTML.
Ex: <html>
<body>
<h1>The pre element</h1>
<pre>
Text in a pre element
is displayed in a fixed-width
font, and it preserves
both spaces and
line breaks
</pre></body></html>
Output:
The pre element
Text in a pre element
is displayed in a fixed-width
17
Web Programming BCA – V Sem Sri Srinivasa Degree College
displayed in a similar way as other basic tags like <b>, <i>, <pre>, and <tt>.
Here we will take you through all the important phrase tags; so let's start
seeing them one by one. Following is the list of phrase tags.
Emphasized text:
Content that is enclosed within the <em>...</em> element is displayed as
emphasized text. The <em> element typically renders text in italics, indicating
emphasis.
Ex:
<html>
<body>
<p>The following word uses a <em>emphasized</em> typeface.</p> </body>
</html>
Marked text:
Anything that is enclosed within the <mark>...</mark> element is displayed as
marked with yellow ink.
<html>
<body>
<p>The following word has been <mark>marked</mark> with yellow.</p>
18
Web Programming BCA – V Sem Sri Srinivasa Degree College
</body>
</html>
Strong text:
Content that is enclosed within the <strong>...</strong> element is displayed
as important text. The <strong> element displays text in a bold font, indicating
strong importance.
<html>
<body>
<p>The following word uses a <strong>strong</strong> typeface. </p>
</body>
</html>
Abbrevation text:
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.
Ex: <html>
<body>
<p>My best friend's name is <abbr title="Abhishek">Abhy</abbr>.
</p> </body> </html>
Output:
My best friend's name is Abhy.
Directed Text:
19
Web Programming BCA – V Sem Sri Srinivasa Degree College
The <q>...</q> element is used when you want to add a double quote within a
sentence. By using <q>...</q>, you ensure that the enclosed text is presented
as a direct quotation, enhancing readability and maintaining proper
punctuation in your HTML document.
Ex: <html>
<body>
<p>Amit is in Spain, <q>I think I am wrong</q>.
</p>
</body>
</html>
Output:
Amit is in Spain, “I think I am wrong”.
Text Citations
If you are quoting a text, you can indicate the source by placing it between an
opening <cite>tag and closing </cite> [Link] you would expect in a print
publication, the content of the <cite> element is rendered in italicized text by
default.
Ex:
<html>
<body>
<p>This HTML tutorial is derived from <cite>W3 Standard for HTML</cite>.
</p>
</body>
</html>
Address Text
The <address>...</address> element is used to contain any address.
<html> <body>
<address>388A, Road No 22, Jubilee Hills - Hyderabad</address> </body>
</html>
20
Web Programming BCA – V Sem Sri Srinivasa Degree College
Bootstrap Studio is a visual editor, and as such HTML can't be edited directly.
The application generates HTML code from the components that you add to
your page and the options that you choose for them.
You can do nearly everything from the visual tools which Bootstrap Studio
gives you, but for the rare cases where you need HTML editing, you can
achieve it with the Custom Code component
Syntax
<q cite="URL">
Attribute Values
It contains a single value URL which is used to specify the URL of the quotation.
The possible value of the URL is:
Absolute URL: It is used to point out other websites (like cite
=”[Link]
Relative URL: It is used to point out the page within the website. (like
cite=”[Link]”).
21
Web Programming BCA – V Sem Sri Srinivasa Degree College
22
Web Programming BCA – V Sem Sri Srinivasa Degree College
Output:
The code Element
Programming code example:
x = 5; y = 6; z = x + y;
23
Web Programming BCA – V Sem Sri Srinivasa Degree College
Example:
Code
<p>This is the first line.<br>This is the second line.</p>
This will result in two separate lines in the browser.
Note: The <br> tag is an empty tag (it has no end tag), meaning it should be
used as <br> or <br/>.
Example:
24
Web Programming BCA – V Sem Sri Srinivasa Degree College
Code
<p>This is a very long word: antidisestablishmentarianism<wbr>ism</p>
If the text "antidisestablishmentarianism" is too long for the available space,
the browser may choose to break it at the <wbr> tag.
Note: The <wbr> tag is also an empty tag (it has no end tag).
<html>
<body>
<h1>GeeksforGeeks</h1>
<h2><wbr> Tag</h2>
<!-- It is mostly used when the used word is too long and
there are chances that the browser may break lines at
the wrong place -->
<p>GFGstandsforGeeksforGeeksanditis<wbr>acomputerscienceportalforgeeks.
</p>
</body>
</html>
This tag describes how the text is being used not necessarily, how it is
formatted. Some of the logical character tags are:
Citation tag: This tag is used to make the text in italic face. It is represented
as <cite> . It is a container tag.
<cite>...............</cite>---Italic
Delete tag: This tag is used to display the text with a line through it> It is
represented as <del>. It is a container tag.
<del>...............</del>.---------strike
Insert tag: This tag is used to display the text with underline. It is
represented as <ins>. It is a container tag.
25
Web Programming BCA – V Sem Sri Srinivasa Degree College
<ins>...........</ins>------------underlined
Emphasize tag: This tag is used to display the in italic face. It is represented
as <em>. It is a container tag.
<em>.........</em>------------Italic
Strong tag: This tag is used to make the text in strong face. It s represented
as <strong> . It is a container tag.
<strong>............</strong>------Bold.
Physical character tags:
This tag controls how the characters are formatted. some of the physical
character tags are:
Bold tag: This tag is used to make the text in Bold face. It is represented as
<b>. It is a container tag.
Bold tag--<b>--------------</b>.
Italic tag: This tag is used to make the text in Italic face. It is represented as
<i>. It is a container tag.
Italic tag--<i>---------------</i>
Underline tag: This tag is used to set underline to the text. It is represented
as <u>. it is a container tag.
Underline tag<u>-------------</u>
Subscript tag: This tag is used to set the text as subscript.(base/suffix).It is
represented as <sub>. It is a container tag.
Subscript tag-<sub>----------</sub>
Superscript tag: this tag is used to set the text as superscript.(power/prefix).
It is represented as <sup>. It is a container tag.
Superscript tag-<sup>----------</sup>
Big tag: This tag is used to make the text in bold face. It is represented as
<big>. It is a container tag.
Big tag<big>...............</big>
26
Web Programming BCA – V Sem Sri Srinivasa Degree College
Strike tag: This tag is used to display the text with a line through it. It is
represented as <s>. it is a container tag.
Strike tag-><s>.................</s>
27
Web Programming BCA – V Sem Sri Srinivasa Degree College
Generic container:
It doesn't have a specific meaning like other semantic HTML elements (e.g.,
<p> for paragraphs).
Used for styling:
It's commonly used to apply styles (like color, font, etc.) to specific parts of text
or elements.
Used for JavaScript manipulation:
28
Web Programming BCA – V Sem Sri Srinivasa Degree College
UNIT-3
CASCADING STYLE SHEETS
CSS overview:
CSS stands for Cascading Style Sheets, used to describe the presentation and
design of a web [Link] CSS, you can control the color of the text, the style
of fonts, the spacing between paragraphs, how columns are sized and laid out,
what background images or colors are used. CSS can control the layout of
multiple web pages all at once.
CSS Properties
A CSS property styles an aspect of an HTML element. Here are a few
examples:
property-name : property-value
If you specify more than one CSS property, the each name - value pair is
separated by a semicolon, like this:
property1 : property-value1;
property2 : property-value2;
The last property declaration does not have to end with a semicolon, but it
makes it easier to add more CSS properties without forgetting to put in that
extra semicolon.
There are many CSS properties you can specify for different HTML elements.
These CSS properties are covered in their own texts.
CSS Rules
A CSS rule is a grouping of one or more CSS properties which are to be
applied to one or more target HTML elements.
29
Web Programming BCA – V Sem Sri Srinivasa Degree College
A CSS rule consists of a CSS selector and a set of CSS properties. The CSS
selector determines what HTML elements to target with the CSS rule. The CSS
properties specifies what to style of the targeted HTML elements
CSS Benefits:
CSS Saves Time: You can write CSS once and then reuse same sheet in
multiple HTML pages.
Pages Load Faster: If you are using CSS, you do not need to write HTML tag
or attributes every time. Just write one CSS rule of a tag and apply it to all the
occurrences of that tag.
Easy Maintenance: To make a global change, simply change the style, and all
elements in all the web pages will be updated automatically.
Superior Styles to HTML: CSS has a much wider array of attributes than
HTML, so you can get a far better look to your HTML page.
Multiple Device Compatibility: For the same HTML document, different
versions of a website can be presented for different screen widths
Global Web Standards: Now most of the HTML attributes are being
deprecated and
30
Web Programming BCA – V Sem Sri Srinivasa Degree College
Styles can be defined in external files called “Linking style sheets”. Which can
be used in any document by including the style sheet through a “URL”.
2. CSS Selectors:
CSS selectors are patterns used to select and style HTML elements. They allow
developers to target specific elements or groups of elements based on various
criteria, such as element type, class, ID, attributes, and hierarchy within the
document structure.
Categories of Selector
Selectors can be divided into different categories based on their specificity and
how they target elements within the HTML document. Here are the main
categories:
Simple Selector
Select elements based on name, id, and class.
Element Selector
Selects elements based on their tag name (e.g., p, div, h1). Example
<html>
<head>
<!-- Element Selector-->
31
Web Programming BCA – V Sem Sri Srinivasa Degree College
<style>
div {
text-align: center;
color: red;
}
</style>
</head>
<body>
<div>Welcome to Geekster</div>
</body>
</html>
Universal Selector
Selects all elements on the page using the asterisk `*`.
<html>
<head>
<!-- Universal Selector-->
<style>
*{
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
<p>Welcome to Geekster</p>
</body>
</html>
CSS Id Selector
Selects a single element with a specific ID. 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.
#my-id {
text-align: center;
color: red;
}
<html>
<head>
<style>
32
Web Programming BCA – V Sem Sri Srinivasa Degree College
#my-id{
text-align: center;
color: red;
}
</style>
</head>
<body>
<p id="my-id">Welcome to Geekster</p>
</body>
</html>
h1, div, p {
33
Web Programming BCA – V Sem Sri Srinivasa Degree College
text-align: center;
color: red;
}
Attribute Selector
Selecting Elements with a Specific Attribute:
Combinator Selectors
Descendant Selector (Whitespace): Selects an element that is a descendant
of another element.
34
Web Programming BCA – V Sem Sri Srinivasa Degree College
Logical Combinators
:is() or :matches() function: Allows grouping of multiple selectors.
:not() function: Selects elements that do not match a specified selector.
Note: Div tag has both opening(<div>) and closing (</div>) tags and it is
mandatory to close the tag.
Example: In this example we uses <div> tags styled with CSS to create colored,
block-level containers. Each div displays text “div tag” with white text on a
green background, differentiated by margins and font size.
<!DOCTYPE html>
<html>
<head>
<title>Div tag</title>
<style>
div {
color: white;
margin: 2px;
font-size: 25px;
}
.div1 {
35
Web Programming BCA – V Sem Sri Srinivasa Degree College
</body>
</html>
36
Web Programming BCA – V Sem Sri Srinivasa Degree College
<div> <span>
The <div> tag is a block level element. The <span> tag is an inline element.
It is best to attach it to a section of a It is best to attach a CSS to a small
web page. section of a
line in a web page.
Ex:
37
Web Programming BCA – V Sem Sri Srinivasa Degree College
<html>
<title>[Link]</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="[Link]
<body>
<div>
<h2>Without a Container</h2>
<p>The w3-container class is one of the most important [Link] classes.</p>
<p>It provides correct margins, padding, alignments, and more, to most HTML
elements.</p>
</div>
<div class="w3-container">
<h2>With a Container</h2>
<p>The w3-container class is one of the most important [Link] classes.</p>
<p>It provides correct margins, padding, alignments, and more, to most HTML
elements.</p>
</div>
</body>
</html>
38
Web Programming BCA – V Sem Sri Srinivasa Degree College
</body>
</html>
5. CSS Properties:
CSS means “cascading style sheet”. Generally HTML is used for designing the
WebPages. But it is a poor page formatting. We use CSS it is used to improve
the page formatting.
In CSS there are number of properties and values which are used to format the
webpage. Those are:
Properties related to font.
Properties related to text.
Properties related to colors.
Properties related to boxes/borders.
The properties which are used for the fonts are given below:
Font-family: This property is used to change the different types of fonts , to
the text. The general form is:
39
Web Programming BCA – V Sem Sri Srinivasa Degree College
Font-weight : This property is used to set font weight to the text. The general
form is:
The properties which are used for the Text are given below.
Text-decoration: This property is used to decorate the text. The general form
is:
Ex: text-align:right
Text-transform: This property is used to transform the text in to lower and
upper cases. The general form is:
The properties which are used for the COLORS are given below
Color: This property is used to set colors to the text. The general form is:
40
Web Programming BCA – V Sem Sri Srinivasa Degree College
Syntax: background-image:url
Ex: background-image: [Link]
PROPERTIES RELATED TO BOXES/BORDERS:
The properties which are used for the boxes/borders are given below.
Border-style: This property is used to set the border style to the text: The
general form is:
41
Web Programming BCA – V Sem Sri Srinivasa Degree College
42
Web Programming BCA – V Sem Sri Srinivasa Degree College
<body>
<h1> Embedded Stylesheet</h1>
<h2>second style sheet</h2>
<p> CSS types in DHTML</p>
<h1>web technologies</h1>
<p> Degree College </p>
<h2>Create smart people</h2>
</body>
</html>
Syntax:
<link rel=“stylesheet” href=“url”>
The above syntax is placed in HEAD section only.
Ex: Save as [Link]
ul ul{color:red;background-color:pink}
em{border-style:dotted;border-color:blue}
li em{color:green; background-color:#ffaa77}
h1{text-align:center;text-transform:uppercase}
Save as [Link]:
<html>
<head>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<h1>
shopping list for <em>Monday</em>
</h1>
<ul>
<li>Milk</li>
<li>Bread
<ul>
<li>White Bread</li>
<li>Wheat Bread</li>
</ul>
43
Web Programming BCA – V Sem Sri Srinivasa Degree College
</li>
<li>Rice</li>
<li>Potatoes with <em>Mushrooms</em></li>
</ul>
</body>
</html>
7. CSS Colors:
Colors are specified using predefined color names, or RGB, HEX, HSL, values.
HSL(Hue-Saturation-Lightness):
Hue Hue is represented as an angle of the color circle (i.e. the rainbow
represented in a circle). This angle is so typically measured in degrees that the
unit is implicit in CSS; syntactically, only a <number> is given. By definition
red=0=360, and the other colors are spread around the circle, so green=120,
blue=240, etc. As an angle, it implicitly wraps around such that -120=240 and
480=120.
Saturation Saturation is represented as percentages. 100% is full saturation,
and 0% is a shade of gray.
Lightness Lightness is represented as percentages. 0% lightness is black,
100% lightness is white, and 50% lightness is “normal”.
44
Web Programming BCA – V Sem Sri Srinivasa Degree College
45
Web Programming BCA – V Sem Sri Srinivasa Degree College
46
Web Programming BCA – V Sem Sri Srinivasa Degree College
9. CSS Margins:
Margins are used to create space around elements, outside of any defined
borders. The CSS margin properties are used to create space around elements,
outside of any defined [Link] CSS, you have full control over the
margins. There are properties for setting the margin for each side of an
element (top, right, bottom, and left).
All CSS Margin Properties Property Description
margin A shorthand property for setting all the
margin properties in one declaration
margin-bottom Sets the bottom margin of an element
margin-left Sets the left margin of an element
margin-right Sets the right margin of an element
margin-top Sets the top margin of an element
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
Ex: <html>
<head>
<style>
h1{
border: 1px solid black;
margin: 25px 50px 75px 100px;
47
Web Programming BCA – V Sem Sri Srinivasa Degree College
background-color: lightblue;
}
</style>
</head>
<body>
<h2>The margin shorthand property - 4 values</h2>
<h1>This div element has a top margin of 25px, a right margin of 50px, a
bottom
margin of 75px, and a left margin of 100px.</h1>
</body>
</html>
The auto Value:
You can set the margin property to auto to horizontally center the element
within its container.
The element will then take up the specified width, and the remaining space will
be split equally between the left and right margins.
Ex: <html>
<head>
<style>
h3{
width: 300px; margin: auto;border: 1px solid red;
}
</style></head><body>
<h2>Use of margin: auto</h2>
<p>You can set the margin property to auto to horizontally center the element
within its container. The element will then take up the specified width, and the
remaining space will be split equally between the left and right margins:</p>
<h3>
This div will be horizontally centered because it has margin: auto;
</h3></body></html>
10.. CSS Padding:
The CSS padding properties are used to generate space around an element's
content, inside of any defined borders. With CSS, you have full control over the
padding. There are properties for setting the padding for each side of an
element (top, right, bottom, and left).
Properties:
CSS has properties for specifying the padding for each side of an element:
padding-top
padding-right
padding-bottom
48
Web Programming BCA – V Sem Sri Srinivasa Degree College
padding-left
Ex: <html>
<head>
<style>
h1 {border: 1px solid black; padding: 25px 50px 75px 100px; background-color:
lightblue; }
</style></head><body>
<h2>The padding shorthand property - 4 values</h2>
<h1>This div element has a top padding of 25px, a right padding of 50px, a
bottom
padding of 75px, and a left padding of 100px.</h1>
</body></html>
Padding and Element Width:
The CSS width property specifies the width of the element's content area. The
content area is the portion inside the padding, border, and margin of an
element (the box model).So, if an element has a specified width, the padding
added to that element will be added to the total width of the element. This is
often an undesirable result.
Ex: <html>
<head>
<style>
.ex1 {width: 300px; background-color: yellow;}
.ex2 {width: 300px; padding: 25px; background-color: lightblue;}
</style></head>
<body>
<h2>Padding and element width</h2>
<h1 class="ex1">This div is 300px wide.</h1>
<h2 class="ex2">The width of this div is 350px, even though it is defined as
300px in the
CSS.</h2
</body></html>
11. CSS TEXT:
CSS has a lot of properties for formatting text.
49
Web Programming BCA – V Sem Sri Srinivasa Degree College
Text Color:
The color property is used to set the color of the text. The color is specified by:
a color name - like "red"
a HEX value - like "#ff0000"
an RGB value - like "rgb(255,0,0)"
Text Alignment:
The text-align property is used to set the horizontal alignment of a text.A text
can be left or right aligned, centered, or justified.
Text Decoration:
The properties of text decoration are:
text-decoration-line: The text-decoration-line property is used to add a
decoration line to [Link] values are: overline,line-through,underline and
overline underline.
text-decoration-color: The text-decoration-color property is used to set the
color of the decoration line.
text-decoration-style: The text-decoration-style property is used to set the
style of the decoration line.
text-decoration-thickness: The text-decoration-thickness property is used to
set the thickness of the decoration line.
Text Transformation:
The text-transform property is used to specify uppercase and lowercase letters
in a [Link] can be used to turn everything into uppercase or lowercase letters,
or capitalize the first letter of each word:
Ex: <html>
<head>
<style>
p { color: blue}
h1 {color: green;text-align: center;text-transform: uppercase}
h2{text-align: right; text-decoration-line:overline;text-decoration-color: red}
</style></head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<p>This is an ordinary paragraph..</p>
</body></html>
Text Shadow:
The text-shadow property adds shadow to text and add a color to the shadow..
Ex: In its simplest use, you only specify the horizontal shadow (2px) and the
vertical shadow (2px):
50
Web Programming BCA – V Sem Sri Srinivasa Degree College
Ex: <html><head>
<style>
h1 { text-shadow: 2px 2px red;}
</style></head><body>
<h1>Text-shadow effect!</h1></body>
</HTML>
12.. CSS FONTS:
Choosing the right font has a huge impact on how the readers experience a
website.
The right font can create a strong identity for your brand.
Using a font that is easy to read is important. The font adds value to your
text. It is also important to choose the correct color and text size for the font.
font-family Property:
In CSS, we use the font-family property to specify the font of a text.
Font Style Property:
The font-style property is mostly used to specify italic text.
This property has three values:
normal - The text is shown normally
italic - The text is shown in italics
oblique - The text is "leaning" (oblique is very similar to italic, but less
supported)
Relative size:
Sets the size relative to surrounding elements
51
Web Programming BCA – V Sem Sri Srinivasa Degree College
Ex:
<html>
<head>
<style>
.p1 { font-family:Times New Roman; font-style: normal; font-size: 40px}
.p2 {font-family:Arial; font-style: italic; font-size: 40px}
.p3 {font-family:Lucida Console; font-style: oblique; font-size: 40px}
</style></head>
<body>
<h1>CSS font-family</h1>
<p class="p1">This is a paragraph, shown in the Times New Roman font.</p>
<p class="p2">This is a paragraph, shown in the Arial font.</p>
<p class="p3">This is a paragraph, shown in the Lucida Console font.</p>
</body></html>
13. CSS Line-height property:
The line-height property specifies the height of a line.
Note: Negative values are not allowed.
CSS Syntax
line-height: normal|number|length|initial|inherit;
Ex: <html>
<head>
<style>
div.a {
line-height: 10px;
}
div.b {
line-height: 30px;
}
div.c {
line-height: 0.5cm;
}
div.d {
line-height: 1cm;
}
</style>
</head>
<body>
<h1>The line-height Property</h1>
52
Web Programming BCA – V Sem Sri Srinivasa Degree College
<h2>line-height: 10px:</h2>
<div class="a">This is a paragraph with a specified line-height.<br>
The line height is here set to 10 pixels.</div>
<h2>line-height: 30px:</h2>
<div class="b">This is a paragraph with a specified line-height.<br>
The line height is here set to 30 pixels.</div>
<h2>line-height: 0.5cm:</h2>
<div class="c">This is a paragraph with a specified line-height.<br>
The line height is here set to 0.5 centimeter.</div>
<h2>line-height: 1cm:</h2>
<div class="d">This is a paragraph with a specified line-height.<br>
The line height is here set to 1 centimeter.</div>
</body>
</html>
14. CSS Box Model
In CSS, the term "box model" is used when talking about design and [Link]
CSS box model is essentially a box that wraps around every HTML element. It
consists of: content, padding, borders and margins. The image below illustrates
the box model:
Explanation of the different parts:
Content - The content of the box, where text and images appear
Padding - Clears an area around the content. The padding is transparent
Border - A border that goes around the padding and content
Margin - Clears an area outside the border. The margin is transparent
The box model allows us to add a border around elements, and to define space
between elements.
EX: <html>
<head>
<style>
div {
background-color: lightgrey;
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
</style>
</head>
<body>
53
Web Programming BCA – V Sem Sri Srinivasa Degree College
54
Web Programming BCA – V Sem Sri Srinivasa Degree College
The picture above is 350px wide. The total width of this element is also 350px.
The total height of this element is 80px.
55
Web Programming BCA – V Sem Sri Srinivasa Degree College
UNIT-4
1. CSS LISTS:
"list-style-position: inside;" means that the bullet points will be inside the list
item. As it is part of the list item, it will be part of the text and push the text at
the start:
Coffee - A brewed drink prepared from roasted coffee beans...
Tea
Coca-cola
56
Web Programming BCA – V Sem Sri Srinivasa Degree College
<html>
<head><style>
ul.a { list-style-type: circle; background: #aa4422;
padding: 20px;}
ul.b { list-style-type: square; background: #3399ff;
padding: 20px;}
ol.c { list-style-type: upper-roman;background: #eedd44;
padding: 20px;}
57
Web Programming BCA – V Sem Sri Srinivasa Degree College
2. CSS COMBINATORS:
A combinator is something that explains the relationship between the
selectors.A CSS selector can contain more than one simple selector. Between
the simple selectors, we can include a combinator.
There are four different combinators in CSS:
descendant selector (space)
child selector (>)
adjacent sibling selector (+)
general sibling selector (~)
Descendant Selector:
The descendant selector matches all elements that are descendants of a
specified [Link] following example selects all <p> elements inside <div>
elements:
EX:<html>
<head>
<style>
div p {background-color: yellow}
</style>
</head>
<body>
<h2>Descendant Selector</h2>
<p>The descendant selector matches all elements that are descendants of a
specified
element.</p>
<div>
<p>Paragraph 1 in the div.</p>
<p>Paragraph 2 in the div.</p>
<section><p>Paragraph 3 in the div.</p></section>
</div>
58
Web Programming BCA – V Sem Sri Srinivasa Degree College
59
Web Programming BCA – V Sem Sri Srinivasa Degree College
figcaption {
background-color: black;
color: white;
font-style: italic;
padding: 2px;
text-align: center;
}
</style>
</head>
<body>
<h1>The figure and figcaption elements + CSS</h1>
<figure>
<img src="pic_trulli.jpg" alt="Trulli" style="width:100%">
<figcaption>Fig.1 - Trulli, Puglia, Italy</figcaption>
</figure></body></html>
Output:
60
Web Programming BCA – V Sem Sri Srinivasa Degree College
nav
header
footer
1. <section>:
Represents a thematic grouping of content, often with a heading.
Can be used for chapters in a book, sections on a webpage (introduction,
content, contact), etc.
It's a generic sectioning element, meaning it should be used when no more
specific element is available.
2. <article>:
Represents a self-contained composition, like a blog post, newspaper article,
or a comment.
Can be syndicated or shared independently.
Can contain multiple <section> elements within it.
3. <aside>:
Represents content tangentially related to the main content.
Examples include pull quotes, author bios, background information, related
links, or supplementary content.
Often displayed as a sidebar.
4. <nav>:
61
Web Programming BCA – V Sem Sri Srinivasa Degree College
Let’s instead consider a page with several articles inside , for example a posts
page in a Blog. Each article could have it’s own header and footer. The header
could contain the title and author of the article, the footer could contain links
related to the article, contact info for the author, or something else. In this
case, the header would be the header of the parent article element rather than
the header of the whole page.
Ex: <html> <head> <title>Example Web Page</title> </head> <body> <header>
<h1>My Website Title</h1> <nav> <ul> <li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li>
</ul> </nav> </header>
<main> <!-- Main content of the page --> <section id="home"> <h2>Welcome!
</h2> <p>This is the main content area.</p> </section> </main> <footer>
<p>© 2025 My Website. All rights reserved.</p>
5. CSS Tables :
The look of an HTML table can be greatly improved with CSS.
62
Web Programming BCA – V Sem Sri Srinivasa Degree College
Table is a collection of rows and columns. Using tables we can present the data
in row wise and column wise. Using tables to provide information in an
organised way.
The following tags are used to create tables in an HTML document.
Table tag
Table row tag
Table data tag
Table heading tag
In CSS use different properties to create tables. Some of them are, table
borders,height and width, Table alignment, padding and colors.
Table Borders:
To specify table borders in CSS, use the border property.
The example below specifies a solid border for <table>, <th>, and <td>
elements:
Table Width and Height:
The width and height of a table are defined by the width and height properties.
CSS Table Alignment:
Horizontal Alignment:
The text-align property sets the horizontal alignment (like left, right, or center)
of the content in <th> or <td>.By default, the content of <th> elements are
center-aligned and the content of <td> elements are left-aligned. To center-
align the content of <td> elements as well, use text-align: center:
Vertical Alignment
The vertical-align property sets the vertical alignment (like top, bottom, or
middle) of the content in <th> or <td>.
By default, the vertical alignment of the content in a table is middle (for both
<th> and <td> elements).
Table Padding:
To control the space between the border and the content in a table, use the
padding property on <td> and <th> elements:
Table Color:
The example below specifies the background color and text color of <th>
elements:
Ex:
<html><head>
<style>
table,th,td {border: 1px solid;width: 50%;height: 50px;text-align: center;
vertical-align: bottom; padding: 15px;background-color: #04AA6D;
63
Web Programming BCA – V Sem Sri Srinivasa Degree College
color: pink}
</style></head>
<body><h2>Add a border ,height and width,alignment, padding and color to a
table:</h2>
<table> <tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
</body></html>
Value Description
64
Web Programming BCA – V Sem Sri Srinivasa Degree College
<tr>
65
Web Programming BCA – V Sem Sri Srinivasa Degree College
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>
<h2>table-layout: fixed; width: 180px:</h2>
<table class="b">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
66
Web Programming BCA – V Sem Sri Srinivasa Degree College
<td>Italy</td>
</tr>
</table>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>
<h2>table-layout: fixed; width: 100%:</h2>
<table class="d">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
67
Web Programming BCA – V Sem Sri Srinivasa Degree College
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>
</body>
</html>
LINKS AND IMAGES
1. Implement a link with the a element:
In addition, links can be styled differently depending on what state they are in.
The four links states are:
a:link - a normal, unvisited link
a:visited - a link the user has visited
a:hover - a link when the user mouses over it
a:active - a link the moment it is clicked
Ex: <html>
<head>
<style>
/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
/* mouse over link */
a:hover {
color: hotpink;
}
/* selected link */
a:active {
68
Web Programming BCA – V Sem Sri Srinivasa Degree College
color: blue;
}
</style>
</head>
<body>
<h2>Styling a link depending on state</h2>
<p><b><a href="[Link]" target="_blank">This is a link</a></b></p>
<p><b>Note:</b> a:hover MUST come after a:link and a:visited in the CSS
definition in order to be effective.</p>
<p><b>Note:</b> a:active MUST come after a:hover in the CSS definition in
order to be effective.</p>
</body>
</html>
Output:
Styling a link depending on state
This is a link
Note: a:hover MUST come after a:link and a:visited in the CSS definition in
order to be effective.
Note: a:active MUST come after a:hover in the CSS definition in order to be
effective.
Ex: <html>
<head>
<title>HTML a href Attribute</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
69
Web Programming BCA – V Sem Sri Srinivasa Degree College
Approach
Use the Anchor Tag <a>: In HTML, use the <a> tag to create links within the
same page.
Assign Unique IDs: Assign unique IDs to different sections of the webpage
using the id attribute.
Set the href Attribute: Set the href attribute of the anchor tag to “#section1”
(replace “section1” with the desired ID) to link to a specific section.
Avoid Using Class Names in href: Class names are not unique identifiers and
should not be used in the href attribute for internal linking.
Example:
<html>
70
Web Programming BCA – V Sem Sri Srinivasa Degree College
<head>
<title>Anchor Link Example</title>
</head>
<body>
<!-- Link to jump to the section -->
<a href="#section2">Go to Section 2</a>
<p>Scroll down to see the section...</p>
<!-- Some space to make scrolling necessary -->
<div style="height: 1000px;"></div>
<!-- Target section with an id -->
<h2 id="section2">Section 2</h2>
<p>This is the content of Section 2.</p>
</body></html>
4. Understand the concepts behind GIF, JPEG and PNG bitmap image formats:
1. GIF (Graphics Interchange Format)
Key Features:
Supports animation: GIF is the only one among these formats that natively
supports simple animations.
Lossless compression: Maintains image quality without loss during
compression.
Supports transparency: But only binary transparency (fully transparent or
fully opaque — no partial transparency).
Color limitation: Limited to 256 colors, which makes it less suitable for
detailed photos but okay for simple graphics, logos, or icons.
71
Web Programming BCA – V Sem Sri Srinivasa Degree College
background-image: url("[Link]");
Use when:
You’re displaying photographs or detailed images.
File size is a concern and some quality loss is acceptable.
Transparency or animation is not required.
3. PNG (Portable Network Graphics)
Key Features:
Lossless compression: High-quality images without data loss.
Supports full transparency: Including alpha transparency (partial opacity).
Supports millions of colors.
Does not support animation (though APNG is an extension that does).
When to use in CSS:
background-image: url("[Link]");
Use when:
You need transparent or semi-transparent images (e.g., overlays, logos).
You want high-quality graphics with no color loss.
File size is less of a concern than visual quality.
72
Web Programming BCA – V Sem Sri Srinivasa Degree College
📌 Notes:
Ensure the .bmp file is correctly referenced and accessible from the server.
Consider converting .bmp to more web-friendly formats like .jpg, .png,
or .webp to improve performance and compatibility.
73
Web Programming BCA – V Sem Sri Srinivasa Degree College
74
Web Programming BCA – V Sem Sri Srinivasa Degree College
UNIT-5
Image manipulations, Audio and Video
1. position an image:
To change the position of an image in CSS, properties like object position and
float are used to control the placement of an image within its container.
1. Using object-position Property
The object-position property in CSS is used to set the position of an image
within its container when using the object-fit property. It allows you to adjust
how the image is displayed inside the box by specifying the alignment in terms
of x and y coordinates.
Syntax
object-position: <x-position> <y-position>;
Property Values
x-position: The horizontal alignment (distance from the left of the content
box).
y-position: The vertical alignment (distance from the top of the content box).
Ex:<h4>object-position Property</h4>
<img
src="[Link]
[Link]"
style="width: 500px; height: 200px;
object-fit: none; object-position: center top;
border: 2px solid black;" />
<img
src="[Link]
[Link]"
style="width: 500px; height: 200px;
object-fit: none; object-position: 50px 30px;
border: 2px solid black;" />
[Link] float Property
The float property in CSS is used to position an image to the left or right of its
container. It allows text and other content to wrap around the image, creating
a flowing layout.
Note: Elements are floated only horizontally i.e. left or right
Syntax
float: none | left | right | inherit | initial;
EX:<h4>Float Property</h4>
<div style="height: 400px; width: 800px; border: 2px solid green;">
75
Web Programming BCA – V Sem Sri Srinivasa Degree College
<img
src=[Link]
.png
Syntax:
<!-- For ICO format (traditional) -->
<link rel="icon" href="/[Link]" type="image/x-icon" />
<!-- For PNG format -->
<link rel="icon" href="/[Link]" type="image/png" />
<!-- For SVG (modern browsers) -->
<link rel="icon" href="/[Link]" type="image/svg+xml" />
✅ Example:
<html> <head> <title>My Website</title> <link rel="icon"
href="images/[Link]" type="image/x-icon"> <link rel="shortcut icon"
href="images/[Link]" type="image/x-icon"> </head> <body> <!-- Your
website content --> </body> </html>
[Link]:
An <iframe> (short for inline frame) is an HTML element used to embed
another HTML page within the current page. It's often used for embedding
videos, maps, or other web content like forms or external websites.
Syntax:
76
Web Programming BCA – V Sem Sri Srinivasa Degree College
Ex: <html>
<body>
<h1>The iframe element + CSS</h1>
<p>An iframe with default borders:</p>
<iframe src="/[Link]" width="100%" height="300">
</iframe>
<p>An iframe with a thin black border:</p>
<iframe src="/[Link]" width="100%" height="300" style="border:1px solid
black;">
</iframe>
<p>An iframe with no borders:</p>
<iframe src="/[Link]" width="100%" height="300" style="border:none;">
</iframe>
</body>
</html>
Output:
he iframe element + CSS
An iframe with default borders:
An iframe with a thin black border:
77
Web Programming BCA – V Sem Sri Srinivasa Degree College
An image sprite in CSS is a technique where multiple images are combined into
a single image file, and then parts of that image are displayed using CSS
background-position. This reduces the number of HTTP requests, improving
performance.
Ex:<html>
<head>
<style>
#home {
width: 46px;
height: 44px;
background: url(img_navsprites.gif) 0 0;
}
#next {
width: 43px;
height: 44px;
background: url(img_navsprites.gif) -91px 0;
}
</style>
</head>
<body>
<img id="home" src="img_trans.gif" width="1" height="1">
<img id="next" src="img_trans.gif" width="1" height="1">
</body>
</html>
Example explained:
<img id="home" src="img_trans.gif"> - Only defines a small transparent
image because the src attribute cannot be empty. The displayed image will be
the background image we specify in CSS
width: 46px; height: 44px; - Defines the portion of the image we want to use
background: url(img_navsprites.gif) 0 0; - Defines the background image and
its position (left 0px, top 0px)
78
Web Programming BCA – V Sem Sri Srinivasa Degree College
Ex: <html>
<body>
<audio controls>
<source src="[Link]" type="audio/ogg">
Ex:<html>
<body>
<audio controls autoplay muted>
<source src="[Link]" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
79
Web Programming BCA – V Sem Sri Srinivasa Degree College
1. Uncompressed Format
2. Lossy Compressed format
3. Lossless Compressed Format
3. Lossless compression: This method reduces file size without any loss in
quality. But is not as good as lossy compression as the size of file compressed
to lossy compression is 2 and 3 times more.
80
Web Programming BCA – V Sem Sri Srinivasa Degree College
FLAC - It stands for Free Lossless Audio Codec. It can compress a source file
by up to 50% without losing data. It is most popular in its category and is open-
source.
ALAC - It stands for Apple Lossless Audio Codec. It was launched in 2004 and
became free after 2011. It was developed by Apple.
7. web fonts:
Web fonts allow Web designers to use fonts that are not installed on the
user's computer.
When you have found/bought the font you wish to use, just include the font
file on your web server, and it will be automatically downloaded to the user
when needed.
Different Font Formats
TrueType Fonts (TTF)
WOFF is a font format for use in web pages. It was developed in 2009, and is
now a W3C Recommendation. WOFF is essentially OpenType or TrueType with
compression and additional metadata. The goal is to support font distribution
from a server to a client over a network with bandwidth constraints.
SVG fonts allow SVG to be used as glyphs when displaying text. The SVG 1.1
specification define a font module that allows the creation of fonts within an
SVG document. You can also apply CSS to SVG documents, and the @font-face
rule can be applied to text in SVG documents.
Embedded OpenType Fonts (EOT)
81
Web Programming BCA – V Sem Sri Srinivasa Degree College
EOT fonts are a compact form of OpenType fonts designed by Microsoft for use
as embedded fonts on web pages
NOTE: Your "own" fonts are defined within the CSS @font-face rule.
<html>
<head>
<style>
@font-face {
font-family: myFirstFont;
src: url(sansation_light.woff);
}
*{
font-family: myFirstFont;
}
</style>
</head>
<body>
<h1>The @font-face Rule</h1>
<div>
With CSS, websites can use fonts other than the pre-selected "web-safe" fonts.
</div>
</body>
</html>
Output:
The @font-face Rule
With CSS, websites can use fonts other than the pre-selected "web-safe" fonts.
82
Web Programming BCA – V Sem Sri Srinivasa Degree College
Ex:<html>
<body>
<video width="320" height="240" autoplay>
<source src="movie.mp4" type="video/mp4">
<source src="[Link]" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
Add muted after autoplay to let your video start playing automatically (but
muted):
Ex: <html>
<body>
<video width="320" height="240" autoplay muted>
<source src="movie.mp4" type="video/mp4">
<source src="[Link]" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
83
Web Programming BCA – V Sem Sri Srinivasa Degree College
CSS gradients let you display smooth transitions between two or more
specified colors.
CSS defines three types of gradients:
Linear Gradients (goes down/up/left/right/diagonally)
Radial Gradients (defined by their center)
Conic Gradients (rotated around a center point)
84
Web Programming BCA – V Sem Sri Srinivasa Degree College
#grad1 {
height: 150px;
width: 200px;
background-color: red; /* For browsers that do not support gradients */
background-image: radial-gradient(red 5%, yellow 15%, green 60%);
}
</style>
</head>
<body>
<h1>Radial Gradient - Differently Spaced Color Stops</h1>
<div id="grad1"></div>
</body>
</html>
CSS Conic Gradients
A conic gradient is a gradient with color transitions rotated around a center
point.
To create a conic gradient you must define at least two colors.
Syntax
background-image: conic-gradient([from angle] [at position,] color [degree],
color [degree], ...);
Ex:<html>
<head>
<style>
#grad1 {
height: 200px;
width: 200px;
background-color: red; /* For browsers that do not support gradients */
background-image: conic-gradient(red, yellow, green);
}
</style>
</head>
<body>
<h1>Conic Gradient - Three Colors</h1>
<div id="grad1"></div>
</body>
</html>
JAVA SCRIPT
1. Introduction:
85
Web Programming BCA – V Sem Sri Srinivasa Degree College
2. JAVACSRIPT VARIABLES:
86
Web Programming BCA – V Sem Sri Srinivasa Degree College
87
Web Programming BCA – V Sem Sri Srinivasa Degree College
You can declare many variables in one statement. Start the statement with var
and separate the variables by comma:
Ex 3:
<html>
<body>
<h1>JavaScript Variables</h1>
<p>You can declare many variables in one statement.</p>
<script language="javascript">
var person = "John Doe", carName = "Volvo", price = 200;
[Link](person+"<br>" +carName+"<br>"+price);
</script>
</body>
</html>
Output:
JavaScript Variables
You can declare many variables in one statement.
John Doe Volvo 200
3. JavaScript identifiers:
JavaScript identifiers are names used to identify variables, functions, and
objects. They must follow specific rules:
Start: Identifiers must begin with a letter (a-z, A-Z), an underscore (\_), or a
dollar sign ($).
Subsequent characters: They can be followed by letters, digits (0-9),
underscores, or dollar signs.
Case-sensitive: JavaScript is case-sensitive, so myVar and myvar are different
identifiers.
Reserved words: Identifiers cannot be reserved keywords like var, let, const,
function, if, else, etc.
Unicode: Identifiers can contain Unicode characters, allowing for names from
various languages and mathematical symbols, but it is common to use only
ASCII characters for portability.
No spaces: Identifiers cannot contain spaces.
Cannot start with a digit: Identifiers cannot begin with a digit to avoid
confusion with numbers.
These rules ensure that JavaScript can distinguish between identifiers and
other elements of the code. Identifiers are fundamental for creating
meaningful and organized JavaScript programs.
All JavaScript identifiers are case sensitive.
The variables lastName and lastname, are two different variables:
Ex:<html>
88
Web Programming BCA – V Sem Sri Srinivasa Degree College
<body>
<h2>JavaScript is Case Sensitive</h2>
<p>Try to change lastName to lastname.</p>
<p id="demo"></p>
<script>
let lastname, lastName;
lastName = "Doe";
lastname = "Peterson";
[Link]("demo").innerHTML = lastName;
</script>
</body>
</html>
Output:
JavaScript is Case Sensitive
Try to change lastName to lastname.
Doe
4. JavaScript Assignments:
Assignment operators assign values to JavaScript variables.
Operator Example Same As
= x=y x=y
+= x += y x=x+y
-= x -= y x=x-y
*= x *= y x=x*y
/= x /= y x=x/y
%= x %= y x=x%y
**= x **= y x = x ** y
Bitwise Assignment Operators
Operator Example Same As
&= x &= y x=x&y
^= x ^= y x=x^y
|= x |= y x=x|y
Logical Assignment Operators
Operator Example Same As
&&= x &&= y x = x && (x = y)
||= x ||= y x = x || (x = y)
??= x ??= y x = x ?? (x = y)
Ex:
<html>
<body>
89
Web Programming BCA – V Sem Sri Srinivasa Degree College
<h1>JavaScript Assignments</h1>
<h2>Simple Assignment</h2>
<h3>The = Operator</h3>
<p id="demo"></p>
<script>
let x = 10;
[Link]("demo").innerHTML = "Value of x is: " + x;
</script>
</body>
</html>
Output:
JavaScript Assignments
Simple Assignment
The = Operator
Value of x is: 10
90
Web Programming BCA – V Sem Sri Srinivasa Degree College
<button onclick="[Link]('demo').innerHTML=Date()">The
time is?</button>
<p id="demo"></p>
</body>
</html>
6. JavaScript functions:
A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is defined with the function keyword, followed by a
name, followed by parentheses ().
Function names can contain letters, digits, underscores, and dollar signs
(same rules as variables).
The parentheses may include parameter names separated by commas:
(parameter1, parameter2, ...)
The code to be executed, by the function, is placed inside curly brackets: {}
Syntax:function name(parameter1, parameter2, parameter3) { // code to be
executed }
Function parameters are listed inside the parentheses () in the function
definition.
Function arguments are the values received by the function when it is
invoked.
Inside the function, the arguments (the parameters) behave as local
variables.
Function Invocation
The code inside the function will execute when "something" invokes (calls) the
function:
When an event occurs (when a user clicks a button)
When it is invoked (called) from JavaScript code
Automatically (self invoked)
Function Return
When JavaScript reaches a return statement, the function will stop
executing.
If the function was invoked from a statement, JavaScript will "return" to
execute the code after the invoking statement.
Functions often compute a return value. The return value is "returned" back
to the "caller":
Ex:<html>
<body>
91
Web Programming BCA – V Sem Sri Srinivasa Degree College
<h1>JavaScript Functions</h1>
<p>Call a function which performs a calculation and returns the result:</p>
<p id="demo"></p>
<script>
let x = myFunction(4, 3);
[Link]("demo").innerHTML = x;
function myFunction(a, b) {
return a * b;
}
</script>
</body>
</html>
Output:
JavaScript Functions
Call a function which performs a calculation and returns the result:
12
Functions advantages
With functions you can reuse code
You can write code that can be used many times.
You can use the same code with different arguments, to produce different
results.
7. JavaScript DOM:
When a web page is loaded, the browser creates a Document Object Model
of the page.
With the HTML DOM, JavaScript can access and change all the elements of an
HTML document.
The HTML DOM model is constructed as a tree of Objects:
92
Web Programming BCA – V Sem Sri Srinivasa Degree College
With the object model, JavaScript gets all the power it needs to create dynamic
HTML:
JavaScript can change all the HTML elements in the page
JavaScript can change all the HTML attributes in the page
JavaScript can change all the CSS styles in the page
JavaScript can remove existing HTML elements and attributes
JavaScript can add new HTML elements and attributes
JavaScript can react to all existing HTML events in the page
JavaScript can create new HTML events in the page
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing documents:
The HTML DOM is a standard object model and programming interface for
HTML. It defines:
The HTML elements as objects
The properties of all HTML elements
The methods to access all HTML elements
The events for all HTML elements
In other words: The HTML DOM is a standard for how to get, change, add, or
delete HTML elements.
In the DOM, all HTML elements are defined as objects.
The programming interface is the properties and methods of each object.
A property is a value that you can get or set (like changing the content of an
HTML element).
A method is an action you can do (like add or deleting an HTML element).
Ex: <html>
<body>
<h2>My First Page</h2>
93
Web Programming BCA – V Sem Sri Srinivasa Degree College
<p id="demo"></p>
<script>
[Link]("demo").innerHTML = "Hello World!";
</script>
</body>
</html>
Output:
My First Page
Hello World!
In the example above, getElementById is a method, while innerHTML is a
property.
The getElementById Method
The most common way to access an HTML element is to use the id of the
element.
In the example above the getElementById method used id="demo" to find
the element.
An HTML form is used to collect user input. The user input is most often sent to
a server for processing.
The <form> Element
The HTML <form> element is used to create an HTML form for user input:
Syntax: <form> . form elements . </form>
The <form> element is a container for different types of input elements, such
as: text fields, checkboxes, radio buttons, submit buttons, etc.
All the different form elements are covered in this chapter: HTML Form
Elements.
The <input> Element
The HTML <input> element is the most used form element.
An <input> element can be displayed in many ways, depending on the type
attribute.
Here are some examples:
Type Description
<input type="text"> Displays a single-line text input
field
<input type="radio"> Displays a radio button (for
selecting one of many choices)
<input type="checkbox"> Displays a checkbox (for
94
Web Programming BCA – V Sem Sri Srinivasa Degree College
Data validation
When implementing form validation, there are a few things to consider:
1. What is defined as "valid" data? i.e. about the format, length, required
fields, and type of data.
2. What happens when invalid data is entered? i.e. whether to show an error
message inline or at the top of the form, how detailed should the error
message be, should the form be submitted anyways, should there be analytics
to track invalid format of data? And so on.
JavaScript validation in two ways:
[Link] validation using JavaScript
2.HTML5 Constraint validation API
Inline validation using JavaScript:
Ex:
html>
<body>
<h2>JavaScript Validation</h2>
<form action="/action_page.php"
method="post">
<input type="text" name="fname" required>
<input type="submit" value="Submit">
</form>
<p>If you click submit, without filling out the text field,
95
Web Programming BCA – V Sem Sri Srinivasa Degree College
In this example, we will validate using HTML5 inbuilt methods such as required
and length in conjunction with the Constraint Validation API to provide
detailed error messages.
<form>
<label for="firstname"> First Name: </label>
<input type="text" name="firstname" required id="firstname">
<button>Submit</button> </form>
const nameField = [Link]("input");
[Link]("input", () => {
[Link]("");
[Link]();
[Link]([Link]());
});
[Link]("invalid", () => {
[Link]("Please fill in your First Name.");
});
Server side validation:
Client side validation is not the only validation check you should do. You must
also validate the data received from your client on the server side code to
ensure that the data matches what you expect it to be.
Form Validation best practices:
1. Always have server side validation, since malicious actors can bypass client
side validation.
2. Provide detailed error messages in-context with the field that produced the
error.
3. Provide an example of what the data should look like in case of an error
message, such as - "Email did not match format - test@[Link]"
96
Web Programming BCA – V Sem Sri Srinivasa Degree College
4. Avoid using single error pages that involve redirection. This is bad user
experience and forces the user to go back to a previous page to fix the form
and lose context.
5. Always mark required fields.
Events are essentially the actions that occur on a web app due to user
interaction, such as clicking a button. In JavaScript, when an event occurs, the
app fires the event, which is kind of a signal that an event has occurred. The
app then automatically responds to the user in the form of output, thanks to
event handlers in JavaScript. An event handler is essentially a function with a
block of code that is executed or triggered when a specific event fires.
Sometimes, when an event occurs, it triggers multiple events. This is because
web elements in an app are often nested. This is where event propagation
comes in. Event propagation involves capturing and bubbling phases as the
event travels across the DOM hierarchy. We’ll discuss these phases later in the
article. There are common types of events:
Keyboard/touch events: Occur when a user presses or releases a key on the
keyboard or performs an action with a touch-enabled smartphone, laptop or
tablet.
JavaScript Click event: Fires when a user clicks on a button or other such web
element.
Mouse hover events: These events are fired when a user performs an action
with the mouse, such as scrolling a page or moving the cursor.
Form/submit events: Triggered when a user submits a form, modifies it, or
resets it.
Drag and drop events: Occurs when a user drags and drops an element on
the web page, such as dragging and dropping an image on a file uploader.
Event Listeners
A javascript event listener is essentially a JavaScript function that waits for a
specific event to occur and then executes a callback function to respond to
that event. Event listeners and event handlers are often considered the same
thing. However, in essence, they work together to respond to an event. As the
name suggests, the listener listens for the event, and the handler is the code
that is executed in response to that [Link] JavaScript event looping
manages asynchronous code execution.
There are two common built-in event listener methods in JavaScript:
addEventListener and removeEventListener. The addEventListener() method
97
Web Programming BCA – V Sem Sri Srinivasa Degree College
Here is an javascript code examples demonstrating the use of the event object
(Click event):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Example of using Event Object</title>
</head>
<body>
<button id="myButton">Click me!</button>
<script>
var button = [Link]("myButton");
[Link]("click", function(event) {
// Accessing event properties
[Link]("Type of Event: " + [Link]);
[Link]("Target Element: " + [Link]);
});
</script>
</body>
</html>
Basic Event Handling Examples
Based on the concepts we discussed in the previous sections, here is an
example for creating a simple button-click event:
<!DOCTYPE html>
98
Web Programming BCA – V Sem Sri Srinivasa Degree College
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Button-Click Event</title>
</head>
<body>
<button id="myButton">Click me!</button>
<script>
var button = [Link]("myButton");
// Adding an event listener
[Link]("click", function() {
alert("Button is clicked!");
});
</script>
</body>
</html>
Here is a basic example demonstrating how to handle form submissions:
<!DOCTYPE html>
<html>
<head>
<title> Handling Form Submission </title>
</head>
<body>
<form id="myForm">
<label for="username">Username:</label>
<input type="text" id="username" name="username">
<br>
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<br>
<input type="submit" value="Submit">
</form>
<script>
var form = [Link]("myForm");
// Adding an event listener for form submission
[Link]("submit", function(event) {
[Link](); // Preventing the default form submission
// Accessing form data
99
Web Programming BCA – V Sem Sri Srinivasa Degree College
100
Web Programming BCA – V Sem Sri Srinivasa Degree College
hierarchy).
mouseenter:
Similar to mouseover, but it only triggers when the pointer enters the
selected element,
not its children.
The onmouseenter event occurs when the mouse pointer enters an
element.
The onmouseenter event is often used together with the onmouseleave
event,
which occurs when the mouse pointer leaves an element.
The onmouseenter event is similar to the onmouseover event. The difference
is
that the onmouseenter event does not bubble (does not propagate up the
document
hierarchy).
mouseleave:
Similar to mouseout, but it only triggers when the pointer leaves the selected
element, not
its children.
The onmouseleave event occurs when the mouse pointer leaves an element.
The onmouseleave event is often used together with the onmouseenter
event,
which occurs when the mouse pointer enters an element.
Theonmouseleave event is similar to the onmouseout event. The difference
is that
the onmouseleave event does not bubble (does not propagate up the
document
hierarchy
How to Implement Rollover Effects
HTML Structure:
Create the HTML elements you want to apply the rollover effect to (e.g.,
images, text, divs).
Assign an ID to these elements for easier manipulation with JavaScript.
JavaScript Implementation:
Select Elements: Use [Link]() or
[Link]() to select the
HTML elements.
Event Listeners: Attach mouseover and mouseout (or mouseenter and
mouseleave) event listeners
101
Web Programming BCA – V Sem Sri Srinivasa Degree College
to the selected element. These listeners will call functions when the events
occur.
JavaScript
const element = [Link]('myElement');
[Link]('mouseover', function() {
// code to change the element's appearance when the mouse is over it
});
[Link]('mouseout', function() {
// code to revert changes when the mouse moves away
});
Event Handler Functions: Inside the event listeners, write the code to change
the
element's appearance. This might involve:
o Changing the element's style (e.g., background color, text color, size).
o Changing the src attribute of an image to swap images.
o Displaying or hiding additional content.
Ex:1<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onmouseover Event</h2>
<img onmouseover="bigImg(this)" onmouseout="normalImg(this)"
border="0" src="[Link]" alt="Smiley" width="32" height="32">
<p>The function bigImg() is triggered when the user moves the
mouse pointer over the image.</p>
<p>The function normalImg() is triggered when the mouse pointer
is moved out of the image.</p>
<script>
function bigImg(x) {
[Link] = "64px";
[Link] = "64px";
}
function normalImg(x) {
[Link] = "32px";
[Link] = "32px";
}
</script>
</body>
</html>
The onmouseover Event
102
Web Programming BCA – V Sem Sri Srinivasa Degree College
The function bigImg() is triggered when the user moves the mouse pointer
over the image.
The function normalImg() is triggered when the mouse pointer is moved out of
the image.
EX2:<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onmouseenter Event</h2>
<img onmouseenter="bigImg(this)" onmouseleave="normalImg(this)"
border="0" src="[Link]" alt="Smiley" width="32" height="32">
<p>The function bigImg() is triggered when the user moves the
mouse pointer onto the image.</p>
<p>The function normalImg() is triggered when the mouse pointer
is moved out of the image.</p>
<script>
function bigImg(x) {
[Link] = "64px";
[Link] = "64px";
}
function normalImg(x) {
[Link] = "32px";
[Link] = "32px";
}
</script>
</body></html>
HTML DOM Events
The onmouseenter Event
The function bigImg() is triggered when the user moves the mouse pointer
onto the
[Link] function normalImg() is triggered when the mouse pointer is moved
out of
the image.
103