HTML Basics for Web Design Beginners
HTML Basics for Web Design Beginners
UNIT I
Introduction to HTML:
HTML (HyperText Markup Language) is the standard language used to create web pages. It structures the
content on the page, including text, images, links, and multimedia. HTML elements are represented by tags that
are interpreted by web browsers to display the content.
An HTML document typically follows a basic structure that includes several key elements:
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Introduction</title>
</head>
<body>
<h1>Welcome to HTML</h1>
<p>This is a basic introduction to HTML.</p>
</body>
</html>
1. <!DOCTYPE html>: This declaration tells the browser that the document is written in HTML5. It is
required at the top of every HTML document.
2. <html>: The root element that wraps the entire HTML document.
3. <head>: This section contains meta-information about the document, such as the character set, title, and
viewport settings (for responsiveness).
o <meta charset="UTF-8">: Defines the character encoding, ensuring the document can handle
special characters.
o <title>: Sets the title of the web page that appears on the browser tab.
o <meta name="viewport" content="width=device-width, initial-scale=1.0">: Ensures the
page is responsive on different devices, particularly mobile devices.
4. <body>: The body of the document, where all visible content goes, such as headings, paragraphs,
images, and links.
Common HTML Tags
Headings (<h1> to <h6>): HTML provides six levels of headings, where <h1> is the highest and <h6>
is the lowest.
<h1>Main Heading</h1>
<h2>Subheading</h2>
Images (<img>): Embeds images in the page. The src attribute specifies the image source.
Lists: HTML supports both ordered (<ol>) and unordered (<ul>) lists.
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<ol>
<li>First item</li>
<li>Second item</li>
</ol>
HTML Attributes
HTML elements can have attributes that provide additional information. Attributes are placed within the
opening tag.
href (for links): Specifies the URL of the page the link goes to.
src (for images): Specifies the path to the image file.
alt (for images): Provides alternative text if the image cannot be displayed.
id and class: Used to uniquely identify elements or group them together for styling or scripting.
Example:
In this example, href specifies the URL, and target="_blank" opens the link in a new tab.
In HTML, tags are the fundamental building blocks used to define the structure and content of a web page.
HTML tags are surrounded by angle brackets, and most elements have an opening tag and a closing tag. Here's
a detailed explanation of the key concepts of HTML tags:
<p>
This is a paragraph.
Closing tag: Marks the end of an element. It is the same as the opening tag but with a forward slash /.
</p>
<p>This is a paragraph.</p>
2. Self-Closing Tags
Some HTML tags don't have content and are self-closing. In HTML5, self-closing tags don’t need a closing tag,
but in XHTML (an older standard), a forward slash is used before the closing bracket.
Headings help structure content into different levels of importance, with <h1> being the most important.
<h1>Main Heading</h1>
<h2>Subheading</h2>
<h3>Smaller Subheading</h3>
Used to create hyperlinks. The href attribute specifies the destination URL.
Displays images on a webpage. It uses attributes like src for the image source and alt for alternative text.
e. List Tags
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
A block-level container for grouping elements, often used with CSS for styling and layout.
<div>
<h2>Section Title</h2>
<p>Content goes here.</p>
</div>
4. Attributes
HTML tags can have attributes, which provide additional information about an element. Attributes are written
within the opening tag and usually come in name-value pairs like name="value".
Common Attributes:
Example:
5. Nesting Tags
Tags can be nested inside one another, but they must be properly closed. Incorrectly nesting tags can break the
structure of the page.
Correct Nesting:
<div>
<p>This is a paragraph inside a div.</p>
</div>
<div>
<p>This is incorrect nesting.</div>
</p>
6. Comments in HTML
Comments are notes within the code that are not displayed in the browser. They are useful for explaining code
or leaving reminders.
HTML5 introduced semantic tags, which give more meaning to the structure of the page.
Example:
<header>
<h1>Website Title</h1>
</header>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
</ul>
</nav>
<main>
<section>
<article>
<h2>Article Title</h2>
<p>Article content goes here.</p>
</article>
</section>
</main>
<footer>
<p>Footer content © 2024</p>
</footer>
HTML Page Structure
An HTML document is structured using a set of nested tags. Each tag is enclosed within <…> angle brackets
and acts as a container for content or other HTML tags. Let's take a look at a basic HTML document
structure:
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
<!-- content -->
</body>
<!DOCTYPE html>
The <!DOCTYPE html> declaration informs the web browser about the HTML version being used. The
latest version is HTML5. But if this changes in the future (maybe 10 years down the line), the doctype
declaration will be helpful!
HTML Root Element
<html>
The <html> tag is the root element that encapsulates all the content on the page.
</html>
Head Section
<head>
The <head> tag contains metadata and links to external resources like CSS and JavaScript files.
</head>
Title Tag
<title>Document</title>
The <title> tag sets the title of the web page, which is displayed in the browser's title bar or tab.
Body Tag
<body>
The <body> tag contains the visible content of the web page. This is where text, images, and other elements
go.
</body>
The </body> tag marks the end of the visible content of the web page.
Every HTML page should include at least these essential elements to define the basic layout. In upcoming
tutorials, we'll dive deeper into the fascinating world of HTML.
Summary:
The <!DOCTYPE html> tag specifies that the document is an HTML5 document.
The <html lang="en"> tag defines the document to be in English.
The <head> section contains metadata and the title of the webpage, which appears in the browser's
title bar.
The <body> section contains the content that will be displayed on the webpage.
The h1 and p are two types of tags. We will learn about more tags in the later section
1. Adding Comments in HTML
Comments are useful for leaving notes or explanations within your code. Comments are not displayed by the
browser and are ignored during rendering.
Syntax:
Example:
HTML provides basic text formatting tags to style and present content on a web page.
The <p> tag is used to define a block of text, making it a paragraph. Browsers automatically add space before
and after paragraphs.
Syntax:
<p>This is the first paragraph of text. It introduces the main topic of the page.</p>
In this example, the two paragraphs will appear one after the other with spacing in between them.
If you want to force a line break (without starting a new paragraph), use the <br> tag. It’s a self-closing tag,
which means it doesn’t need an end tag.
Syntax:
<br>
Example:
<p>This is the first line.<br>This is the second line, right after a line break.</p>
Here, the text after the <br> tag will appear on a new line, but it will remain part of the same paragraph.
Here's how you can combine comments, text formatting, paragraphs, and line breaks in a simple HTML
structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text and Formatting Example</title>
</head>
<body>
<p><em>Don't forget to check the other sections.</em> We have a lot more content below.</p>
</body>
</html>
Explanation:
1. Comments: Comments are added to explain various parts of the code without affecting the output.
2. Text Formatting: <strong> makes text bold (and adds semantic importance), and <em> italicizes text.
3. Paragraphs: Text is divided into separate blocks using the <p> tag.
4. Line Breaks: The <br> tag is used to force new lines within a paragraph.
Emphasizing Text
You can emphasize text in different ways using tags like <strong>, <em>, <b>, and <i>.
Headings help structure your content. <h1> is the most important, and <h6> is the least.
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
Use the <hr> tag to insert a horizontal line that separates sections.
4. Lists
HTML supports two types of lists: unordered (bulleted) and ordered (numbered).
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
You can customize the font size, face, and color using the style attribute or the deprecated <font> tag. However,
using CSS is the modern and recommended approach.
<font size="5" face="Verdana" color="red">This is some text in Verdana font, size 5, and red
color.</font>
6. Text Alignment
You can align text using the align attribute (deprecated) or CSS.
7. Links (<a>)
Basic Link
HTML TABLE:
<table>
<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>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
TABLE CELLS
Everything between <td> and </td> are the content of the table cell.
Example:
<table>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
</table>
TABLE ROWS
Each table row starts with a <tr> and ends with a </tr> tag.
tr stands for table row.
Example:
<table>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
TABLE HEADERS
Sometimes you want your cells to be table header cells. In those cases use the <th> tag instead of the <td> tag:
Example
<table>
<tr>
<th>Person 1</th>
<th>Person 2</th>
<th>Person 3</th>
</tr>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
HTML TABLE TAGS
Tag Description
<table> Defines a table
<th> Defines a header cell in a table
<tr> Defines a row in a table
<td> Defines a cell in a table
<caption> Defines a table caption
<colgroup> Specifies a group of one or more columns in a table for formatting
<col> Specifies column properties for each column within a <colgroup> element
<thead> Groups the header content in a table
<tbody> Groups the body content in a table
<tfoot> Groups the footer content in a table
TABLES:
The HTML tables allow web authors to arrange data like text, images, links, other
tables, etc. into rows and columns of cells.
The HTML tables are created using the <table> tag in which the <tr> tag is used to
create table rows and <td> tag is used to create data cells. The elements under
<td> are regular and left aligned by default.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Tables</title>
</head>
<body>
<table border = "1">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
</body>
</html>
This will produce the following result –
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000
There are two attributes called cellpadding and cellspacing which you will use toadjust the
white space in your table cells.
The cellspacing attribute defines space between table cells, while cellpaddingrepresents
the distance between cell borders and the content within a cell.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Cellpadding</title>
</head>
<body>
<table border = "1" cellpadding = "5" cellspacing = "5">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</body>
</html>
This will produce the following result –
Name Salar
y
Ramesh Raman
5000
Shabbir Hussein
7000
Use colspan attribute if you want to merge two or more columns into a singlecolumn.
Similar way you will use rowspan if you want to merge two or more rows.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Colspan/Rowspan</title>
</head>
<body>
<table border = "1">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td rowspan = "2">Row 1 Cell 1</td>
<td>Row 1 Cell 2</td>
<td>Row 1 Cell 3</td>
</tr>
<tr>
<td>Row 2 Cell 2</td>
<td>Row 2 Cell 3</td>
</tr>
<tr>
<td colspan = "3">Row 3 Cell 1</td>
</tr>
</table>
</body>
</html>
This will produce the following result –
Tables Backgrounds
You can set table background using one of the following two ways −
bgcolor attribute − You can set background color for whole table or just for onecell.
background attribute − You can set background image for whole table or just forone cell.
You can also set border color also using bordercolor attribute.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border = "1" bordercolor = "green" bgcolor = "yellow">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td rowspan = "2">Row 1 Cell 1</td>
<td>Row 1 Cell 2</td>
<td>Row 1 Cell 3</td>
</tr>
<tr>
<td>Row 2 Cell 2</td>
<td>Row 2 Cell 3</td>
</tr>
<tr>
<td colspan = "3">Row 3 Cell 1</td>
</tr>
</table>
</body>
</html>
OUTPUT:
Column 1 Column 2 Column 3
Row 1 Cell 2 Row 1 Cell 3
Row 1 Cell 1
Row 2 Cell 2 Row 2 Cell 3
Row 3 Cell 1
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border = "1" bordercolor = "green" background = "/images/[Link]">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td rowspan = "2">Row 1 Cell 1</td>
<td>Row 1 Cell 2</td><td>Row 1 Cell 3</td>
</tr>
<tr>
<td>Row 2 Cell 2</td>
<td>Row 2 Cell 3</td>
</tr>
<tr>
<td colspan = "3">Row 3 Cell 1</td>
</tr>
</table>
</body>
</html>
Column 1 Column 2 Column 3
Row 1 Cell 2 Row 1 Cell 3
Row 1 Cell 1
Row 2 Cell 2 Row 2 Cell 3
Row 3 Cell 1
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Caption</title>
</head>
<body>
<table border = "1" width = "100%">
<caption>This is the caption</caption>
<tr>
<td>row 1, column 1</td><td>row 1, columnn 2</td>
</tr>
<tr>
<td>row 2, column 1</td><td>row 2, columnn 2</td>
</tr>
</table>
</body>
</html>
OUTPUT
<thead>
<tr>
<td colspan = "4">This is the head of the table</td>
</tr>
</thead>
<tfoot>
<tr>
<td colspan = "4">This is the foot of the table</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</tbody>
</table>
</body>
</html>
This will produce the following result –
Nested Tables
You can use one table inside another table. Not only tables you can use almost all the tags inside
table data tag <td>.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<table border = "1" width = "100%">
<tr>
<td>
<table border = "1" width = "100%">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Output:
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000
FRAMES:
HTML frames are used to divide your browser window into multiple sectionswhere
each section can load a separate HTML document.
Introducing Frameset:
A collection of frames in the browser window is known as a frameset. The window is
divided into frames in a similar way the tables are organized: into rowsand columns.
SYNTAX:
<frameset cols=" "> ............ </frameset>
Example:
!DOCTYPE html>
<html>
<head>
<title>Frame tag</title>
</head>
<frameset cols="50%,50%">
<frame src="[Link]
<frame src="[Link]
</frameset>
</html>
Output:
<Frame> elements: Tag-specific attribute
cols Pixels It specifies the number and size of column spaces in theframeset.
% (Not Supported in HTML5)
*
rows Pixels It specifies the number and size of the rows spaces in the
% frameset. (Not Supported in HTML5)
*
[Link] Attribute & Description
src
This attribute is used to give the file name that should be loaded in the frame. Its value
1
can be any URL. For example, src = "/html/top_frame.htm" will load an HTML file
available in html directory.
name
This attribute allows you to give a name to a frame. It is used to indicate which frame a
document should be loaded into. This is especially important when you want to create
2
links in one frame that load pages into an another frame, in which case the second frame
needs a name to identify itself as the target of the link.
frameborder
This attribute specifies whether or not the borders of that frame are shown; it overrides
3
the value given in the frameborder attribute on the <frameset> tag if one is given, and
this can take values either 1 (yes) or 0 (no).
marginwidth
This attribute allows you to specify the width of the space between the left and right of
4
the frame's borders and the frame's content. The value is given in pixels. For example
marginwidth = "10".
marginheight
5
This attribute allows you to specify the height of the space between the top
and bottom of the frame's borders and its contents. The value is given inpixels. For
example marginheight = "10".
noresize
By default, you can resize any frame by clicking and dragging on the borders of a frame.
6
The noresize attribute prevents a user from being able to resize the frame. For example
noresize = "noresize".
scrolling
This attribute controls the appearance of the scrollbars that appear on the frame. This
7
takes values either "yes", "no" or "auto". For example scrolling = "no" means it should
not have scroll bars.
longdesc
This attribute allows you to provide a link to another page containing a long description
8
of the contents of the frame. For example longdesc = "[Link]"
<head>
<base target="_self">
<title>
HTML Base target Attribute
</title>
</head>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksForGeeks
</h1>
<a href="[Link]/"
alt="GFG"> Geeks Link
</a>
</body>
</html>
Output:
UNIT I COMPLETED
Unit II
Forms & Images Using Html: Graphics:Introduction-How to work efficiently
with images inweb pages, image maps, GIF animation, addingmultimedia, data
collection with html forms textbox,password, list box, combo box, text area, tools
for building web page front page.
Forms
Forms Design is used to create interactive forms on web pages that allow users to
input and submit data to a server for processing.
The <form> tag defines the form structure.
Form elements like <input>, <button>, and <select> are used to collect data.
HTML forms are essential for tasks such as login, registration, and surveys.
<html>
<body>
<label for="name">Name:</label>
<br><br>
<label for="email">Email:</label>
<br><br>
<label for="message">Message:</label>
<br><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
<form> defines a section for collecting user inputs with attributes
specifying where (action) and how (method) to send the data.
<label>, <input>, and <button> create a simple field for text input and a
button to submit the form.
Input Elements in HTML Forms
Input elements are the building blocks of HTML forms, allowing users
to enter and submit various types of data. Common input elements
include:
1. Text Field: Allows the user to input single-line text. It is created
using the <input> element with type=”text”
<!DOCTYPE html>
<html>
<body>
<h3>Example of Text Field</h3>
<form>
<label for="email">Email ID:</label><br>
<input type="text" name="email" id="email"><br>
</form>
</body>
</html>
The <input type=”text”> element creates a single-line text field for user
input.
The <label> element provides a descriptive label for the text field,
enhancing accessibility and usability.
2. Number Field: This field accepts numeric input. It is created using the
<input> element with type=”number”.
<html>
<body>
<form>
<label for="age">Age:</label><br>
<input type="number" name="age" id="age">
</form>
</body>
</html>
The <input type=”number”> element creates a numeric input field,
allowing users to enter their age.
The <label> element provides a descriptive label (“Age:”) for the input
field, enhancing accessibility and usability.
3. Password Field: A password field masks the user’s input (e.g.,
asterisks or dots). It is created using the <input> element with
type=”password”.
<html>
<body>
<form>
<label for="password">Password:</label><br>
</form>
</body>
</html>
<body>
<form>
<label>Select Gender:</label><br>
id="male" value="Male">
<label for="male">Male</label><br>
id="female" value="Female">
<label for="female">Female</label>
</form>
</body>
</html>
<body>
<form>
<b>Select Subjects:</b><br>
id="maths" value="Maths">
<label for="maths">Maths</label><br>
id="science" value="Science">
<label for="science">Science</label><br>
id="english" value="English">
<label for="english">English</label>
</form>
</body>
</html>
File Select Box: Allows users to select a file from their local device and
upload it. It is created using the <input> element with type=”file”.
<html>
<body>
<form>
</form>
</body>
</html>
The <input type=”file”> element creates a file upload field, allowing users
to select a file from their device for submission.
The <label> element provides a descriptive label (“Upload a file:”) for the
file input field, enhancing accessibility and usability.
Select Boxes: Used to present a dropdown list of options. Select boxes are
created using the <select> element, and the individual options are defined
using the <option> element.
<html>
<body>
<form>
<label for="country">Country:</label>
<option value="India">India</option>
<option value="Australia">Australia</option>
</select>
</form>
</body>
</html>
<body>
<label for="username">Username:</label>
</form>
</body>
</html>
The <img> tag is empty, it contains attributes only, and does not have a closing
tag.
Syntax
<img src="url" alt="alternatetext">
Example
<img src="img_chania.jpg" alt="Flowers in Chania">
Example
<img src="img_chania.jpg" alt="Flowers in Chania">
Example
<img src="img_girl.jpg" alt="Girl in a
jacket" style="width:500px;height:600px;">
Alternatively, you can use the width and height attributes:
However, we suggest using the style attribute. It prevents styles sheets from
changing the size of images:
Example
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 100%;
}
</style>
</head>
<body>
</body>
</html>
Graphics
<body>
fill="green" xmlns="[Link]
<svg>
</body>
</html>
Output:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<img src="[Link]
[Link]" >
</img>
</body>
</html>
Output:
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<img src="[Link]
[Link]">
</img>
</body>
</html>
OutPut:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="star"></div>
</body>
</html>
.star {
position: absolute;
width: 423px;
height: 384px;
left: 456.7px;
top: 80.34px;
background: #346d33;
transform: rotate(18.69deg);
}
Output:
Canvas API
Has no DOM and uses vector based methods to create objects, graphics
and shapes.
Canvas API applications can be standalone or integrated with HTML or
SVG.
Widely used for games
Client-side scripting with native modern browser support.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
</canvas>
</body></html>
OUTPUT:
Image Maps
The HTML <map> tag defines an image map. An image map is an image with
clickable areas. The areas are defined with one or more <area> tags.
Try to click on the computer, phone, or the cup of coffee in the image below
Example
Here is the HTML source code for the image map above:
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer" href="co
[Link]">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="pho
[Link]">
<area shape="circle" coords="337,300,44" alt="Coffee" href="coffe
[Link]">
</map>
The Image
The image is inserted using the <img> tag. The only difference from other
images is that you must add a usemap attribute:
The usemap value starts with a hash tag # followed by the name of the image
map, and is used to create a relationship between the image and the image
map.
The <map> element is used to create an image map, and is linked to the image
by using the required name attribute:
<map name="workmap">
The name attribute must have the same value as the <img>'s usemap attribute
The Areas
Then, add the clickable areas.
Shape
You must define the shape of the clickable area, and you can choose one of
these values:
Shape="rect"
The coordinates for shape="rect" come in pairs, one for the x-axis and one for
the y-axis.
So, the coordinates 34,44 is located 34 pixels from the left margin and 44 pixels
from the top:
The coordinates 270,350 is located 270 pixels from the left margin and 350
pixels from the top:
Example
<area shape="rect" coords="34, 44, 270, 350" href="[Link]">
This is the area that becomes clickable and will send the user to the page
"[Link]":
Shape="circle"
To add a circle area, first locate the coordinates of the center of the circle:
337,300
GIF animations
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
What is Multimedia?
Multimedia comes in many different formats. It can be almost anything you can
hear or see, like images, music, sound, videos, records, films, animations, and
more.
Web pages often contain multimedia elements of different types and formats.
Browser Support
The first web browsers had support for text only, limited to a single font in a
single color.
Later came browsers with support for colors, fonts, images, and multimedia!
Multimedia Formats
Multimedia elements (like audio or video) are stored in media files.
The most common way to discover the type of a file, is to look at the file
extension.
Example
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="[Link]" type="video/ogg">
Your browser does not support the video tag.
</video>
How it Works
The controls attribute adds video controls, like play, pause, and volume.
It is a good idea to always include width and height attributes. If height and
width are not set, the page might flicker while the video loads.
The <source> element allows you to specify alternative video files which the
browser may choose from. The browser will use the first recognized format.
The text between the <video> and </video> tags will only be displayed in
browsers that do not support the <video> element.
HTML <video> Autoplay
To start a video automatically, use the autoplay attribute:
Example
<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>
Tag Description
The <source> element allows you to specify alternative audio files which the
browser may choose from. The browser will use the first recognized format.
The text between the <audio> and </audio> tags will only be displayed in
browsers that do not support the <audio> element.
Example
<audio controls autoplay>
<source src="[Link]" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Example
<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>
HTML Forms are used to send data across the web, like
login, signup, search etc. Forms are often used as contact
form to convert information input by a user into
leads. Forms includes many inputs controls like text, password,
file, radio, checkbox etc
The elements used in HTML form are form tag as
parent, input, textarea,, select, button and label.
Input Tag
Label
Radio Buttons
Checkbox
Select Dropdown
Textarea
Button
Fieldset
/* Content */
</form>
</form>
f we want to create the text box in Html document for inserting the characters by the user on
the web page then we have to follow the steps which are given below. Using these steps,
any user can easily create a text box.
Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html
file in the text editor in which we want to create the text box.
1. <!Doctype Html>
2. <Html>
3. <Head>
4. <Title>
5. Create the Text Box
6. </Title>
7. </Head>
8. <Body>
9. Hello User! <br>
10. </Body>
11. </Html>
Step 2: For creating the text box, firstly we have to define the <form> tag, if not defined in
the code. Now, we have to place the cursor at that point in the <form> tag where we want to
create the text box. And, then we have to type the <input> tag at that point.
1. <form>
2. Student Name:
3. <input >
4. <br> <br>
5. Course:
6. <input >
7. </form>
Step 3: After writing the <input> tag, we have to use its attribute whose name
is type. This attribute specifies what type of data is to be entered. So, to create the text box
we have to give the value "text" in the type attribute.
1. <form>
2. Student Name:
3. <input type="text" name="Name">
4. <br> <br>
5. Course:
6. <input type="text" name="Course">
7. </form>
Step 4: If we want to define the width of the text box, then we can define it with the help of
the size attribute.
1. <form>
2. Student Name:
3. <input type="text" name="Name" size="20">
4. <br> <br>
5. Course:
6. <input type="text" name="Course" size="15">
7. </form>
Step 5: And, at last, we have to save the Html file and then run the file in the browser.
1. <!Doctype Html>
2. <Html>
3. <Head>
4. <Title>
5. Create the Text Box
6. </Title>
7. </Head>
8. <Body>
9. Hello User! <br>
10. <form>
11. Student Name:
12. <input type="text" name="Name" size="20">
13. <br> <br>
14. Course:
15. <input type="text" name="Course" size="15">
16. </form>
17. </Body>
18. </Html>
<!DOCTYPE html>
<html>
<body>
<label for="email">Email:</label>
placeholder="Email Address"
required pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$">
<br>
<br>
<label for="paswword">Password:</label>
placeholder="Password" required>
<br>
<br>
</form></body>
</html>
List Box
The list box is a graphical control element in the HTML document that allows a user to
select one or more options from the list of options. HTML listboxes, otherwise called
dropdown lists or select elements, give a helpful method for introducing a list of choices to
clients on a webpage. They are broadly utilized in forms, permitting clients to select one or
different things from a predefined set of decisions. In this article, we'll investigate the HTML
<select> element and its different attributes, alongside reasonable guides to outline their
use.
Syntax:
To create a list box, use the HTML element <select> which contains two
attributes Name and Size. The Name attribute is used to define the name for calling the list
box, and size attribute is used to specify the numerical value that shows the how many
options it contains.
1. <!DOCTYPE html>
2. <html>
3. <title>
4. Example of List Box
5. </title>
6. <body>
7. Customer Name: <input type="text" Placeholder="Enter the Customer Name"/>
8. <br>
9. <br>
10. <select name="Cars" size="5">
11. <option value="Merceders"> Merceders </option>
12. <option value="BMW"> BMW </option>
13. <option value="Jaguar"> Jaguar </option>
14. <option value="Lamborghini"> Lamborghini </option>
15. <option value="Ferrari"> Ferrari </option>
16. <option value="Ford"> Ford </option>
17. </select>
18. </body>
19. </html>
Combobox HTML
We will discuss the Combobox HTML in this article. The name "Combobox" itself contains
the word "combo" which means combination. So, from its name, a combobox is a
combination of boxes. In HTML, it is the element that we can construct with a combination
of tags such as <select> tag and <option> tag. It is mostly utilized inside forms in HTML. It
is utilized to construct the dropdown list.
o The <label for="name"> tag is utilized to provide the name of the element. This tag
uses the "for" attribute that provides more accessibility.
o The <input type="text"> tag is utilized to define the single-line text field where the user
can input.
o The <select> tag is utilized to make a dropdown list.
o The <option> tag is utilized inside the <select> tag to define the options in a list.
o <!DOCTYPE html>
o <html lang="en">
o <head>
o <title>Demonstration of Combobox in HTML</title>
o </head>
o <body>
o <h2>It is the demonstration of Comboxbox in HTML</h2>
o <label for="name">Full Stack Web Development Languages</label> <br> <br>
o <select>
o <option value="HTML">HTML</option>
o <option value="CSS">CSS</option>
o <option value="JavaScript">JavaScript</option>
o <option value="PHP">PHP</option>
o <option value="Scala">Scala</option>
o <option value="Ruby">Ruby</option>
o <option value=".NET">.NET</option>
o <option value="Angular">Angular</option>
o <option value="React">React</option>
o <option value="SQL">SQL</option>
o <option value="C++">C++</option>
o <option value="C#">C#</option>
o <option value="Java">Java</option>
o <option value="Python">Python</option>
o <option value="OC">Objective C</option>
o </select>
o </body>
o </html>
o Output:
o Here is the output in which we can witness the combobox that shows full-stack web
o o
Textarea
The HTML <textarea> tag is used to define a multi-line text input control.
It can hold unlimited number of characters and the texts are displayed in a fixed-width font (usually
courier).
The size of the HTML textarea is defined by <cols> and <rows> attribute, or it can also be defined
through CSS height and width properties.
Textarea
1. <textarea rows="9" cols="70">
2. JavaTpoint textarea tag example with rows and columns.
3. </textarea>
Output:
UNIT III:
CSS
1
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
USES OF CSS
o CSS Stands for "Cascading Style Sheet." Cascading style sheets are
used to format the layout of Web pages.
o They can be used to define text styles, table sizes, and other aspects of
Web pages that previously could only be defined in a page's HTML,
o CSS are a powerful way to separate content from design in our Web
Forms applications.
o CSS helps Web developers create a uniform look across several pages
of a Web site.
o Instead of defining the style of each table and each block of text
within a page's HTML, commonly used styles need to be defined only
once in a CSS document.
o Once the style is defined in cascading style sheet, it can be used by
any page that references the CSS file.
o CSS makes it easy to change styles across several pages at once.
o CSS is used to define styles for your web pages, including the design,
layout and variations in display for different devices and screen sizes.
ADVANTAGES OF CSS
Lightweight code.
Greater accessibility.
Browser Compatibility:
o CSS stylesheets increase your websi adaptability and ensure that more
visitors will be able to view you website.
o -It can control the layout of multiple web pages all at once.
CSS SYNTAX
3
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
EXAMPLE
<html>
<head>
<style>
body
{
background-color: lightblue;
}
h1
{
color: white;
text-align: center;
}
p
{
font-family: verdana;
font-size: 20px;
}
</style>
</head>
<body>
</body>
</html>
4
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
When a browser reads a style sheet, it will format the HTML document
according to the information in the style sheet.
[Link] CSS
o An internal style sheet may be used if one single HTML page has a
unique style.
o The internal style is defined inside the <style> element, inside the
head section.
o Internal styles are defined within the <style> element, inside the
<head> section of an HTML page:
o Place the CSS styles within a <style> tag inside the HTML file,
usually inside the <head> section.
5
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
<html>
<head>
<!-- Using Internal CSS -->
<style>
h3 {
color: red;
}
</style>
</head>
<body>
<!-- CSS is applied here -->
<h3>Welcome To Internal CSS </h3>
<p>CSS </p>
</body>
</html>
OUTPUT
2. INLINE CSS
To use inline styles, add the style attribute to the relevant element.
The style attribute can contain any CSS property.
6
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
EXAMPLE
Inline styles are defined within the "style" attribute of the relevant element:
Use the style attribute on the HTML element to add styles to the web page.
It is used for small projects.
<html>
<body>
<!-- Using Inline CSS -->
<h3 style="text-align: center;">
Welcome To CSS
</h3>
OUTPUT
[Link] CSS
With an external style sheet, you can change the look of an entire website by
changing just one file!
Each HTML page must include a reference to the external style sheet file
inside the <link> element, inside the head section.
7
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
EXAMPLE
<html>
<head>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
o An external style sheet can be written in any text editor, and must be
saved with a .css extension.
o The external .css file should not contain any HTML tags.
Body
{
background-color: lightblue;
}
h1
{
color: navy;
margin-left: 20px;
}
OUTPUT
8
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
CSS SELECTORS
The element selector selects HTML elements based on the element name.
EXAMPLE
<html>
<head>
<style>
p{
text-align: center;
color: red;
}
</style>
</head>
<body>
<p>Every paragraph will be affected by the style.</p>
<p id="para1">Me too!</p>
<p>And me!</p>
</body>
</html>
9
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
CSS ID SELECTOR
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
10
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
</body>
</html>
11
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
The universal selector (*) selects all HTML elements on the page.
EXAMPLE
<html>
<head>
<style>
*{
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
12
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
The grouping selector selects all the HTML elements with the same style
definitions.
Look at the following CSS code (the h1, h2, and p elements have the same
style definitions):
h1
{
text-align: center;
color: red;
}
h2
{
text-align: center;
color: red;
}
p
{
text-align: center;color: red;
}
13
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
EXAMPLE
<html>
<head>
<style>
h1, h2, p
{
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<h2>Smaller heading!</h2>
<p>This is a paragraph.</p>
</body>
</html>
OUTPUT
GROUPING STYLES
14
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
EXAMPLE:
h1, h2, h3
{
font-size: 10px;
color: green;
}
It improves the performance by reducing page loading time and save storage
space.
15
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
XML
Extensible Markup Language (XML) is a type of markup language that
establishes a set of guidelines for encoding texts in a way that is both machine-
and human-readable.
For storing and transferring data on the web and in many other applications,
XML is widely used. XML steps in as a versatile tool for encoding and
organizing data in a way that both humans and machines can comprehend.
SYNTAX
EXAMPLE
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The XML above does not DO anything. XML is just information wrapped in
tags.
Someone must write a piece of software to send, receive, store, or display it:
16
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Note
To: Tove
From: Jani
Reminder
Don't forget me this weekend!
<book>
<title>Harry Potter and the Sorcerer's Stone</title>
<author>[Link]</author>
<year>1997</year>
</book>
The tags in the example above (like <to> and <from>) are not defined in any
XML standard. These tags are "invented" by the author of the XML document.
HTML works with predefined tags like <p>, <h1>, <table>, etc.
With XML, the author must define both the tags and the document structure.
17
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
APPLICATIONS OF XML
FEATURES OF XML
Flexibility: XML is a flexible data format as it allows you to create your own
custom tags to meet your specific needs.
Extensibility: XML is extensible as it enables you to add new features to
XML without breaking existing applications.
Platform-independence: XML files can be read and processed on any
platform, regardless of the operating system or programming language.
Human-readability: XML files are also human-readable, which makes them
easy to edit and maintain.
Machine-readability: XML files can be easily parsed and processed by
computers. This makes XML ideal choice to store and exchange.
ADVANTAGES OF XML
18
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
It uses the Dynamic Object Model to modify settings, properties, and methods.
HTML:
HTML stands for Hypertext Markup Language and it is a client-side
markup language. It is used to build the block of web pages.
Javascript:
It is a Client-side Scripting language. Javascript is supported by most of
browsers, and also has cookie collection to determine the user’s needs.
CSS:
The abbreviation of CSS is Cascading Style Sheet. It helps in the styling of
the web pages and helps in designing of the pages. The CSS rules for DHTML
will be modified at different levels using JS with event handlers which adds a
significant amount of dynamism with very little code.
DOM:
It is known as a Document Object Model which acts as the weakest link in
it. The only defect in it is that most of the browsers does not support DOM. It is a
way to manipulate the static content.
19
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Uses of DHTML
o It is used for designing the animated and interactive web pages that
are developed in real-time.
o DHTML helps users by animating the text and images in their
documents.
o It allows the authors for adding the effects on their pages.
o It also allows the page authors for including the drop-down menus or
rollover buttons.
o This term is also used to create various browser-based action games.
Features of DHTML
Its simplest and main feature is that we can create the web page
dynamically.
Dynamic Style is a feature, that allows the users to alter the font, size,
color, and content of a web page.
20
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
It provides the facility for using the events, methods, and properties.
And, also provides the feature of code reusability.
It also provides the feature in browsers for data binding.
Using DHTML, users can easily create dynamic fonts for their web
sites or web pages.
With the help of DHTML, users can easily change the tags and their
properties.
The web page functionality is enhanced because the DHTML uses
low-bandwidth effect.
21
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
A DTD defines the structure and the legal elements and attributes of an
XML document.
XML DTD
The purpose of a DTD is to define the structure and the legal elements and
attributes of an XML document:
[Link]:
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
!DOCTYPE note - Defines that the root element of the document is note
22
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
!ELEMENT note - Defines that the note element must contain the elements: "to,
from, heading, body"
!ELEMENT to - Defines the to element to be of type "#PCDATA"
!ELEMENT from - Defines the from element to be of type "#PCDATA"
!ELEMENT heading - Defines the heading element to be of type "#PCDATA"
!ELEMENT body - Defines the body element to be of type "#PCDATA"
Document Type Definition and XML Schema Definition both contain a set
of rules that control the structure and elements of XML files, but they are different
in syntax and usage. They check whether an XML document has a valid structure
or not.
DTD stands for Document Type Definition and DTD contains a set of rules
that control the structure and elements of XML files. It is used to describe the
attributes of XML language precisely. It can be classified into two types namely
internal DTD and external DTD. It can be specified inside a document or outside a
document. DTD mainly checks the grammar and validity of an XML document.
Features of DTD
It defines the compulsory and optional elements in the XML document.
It validates the structure of the XML document.
It checks for the grammar of the XML document.
It describes the order in which the element occurs.
Advantages of DTD
We can define our own format for the XML files by DTD.
It helps in validation of XML file.
It provides us with a proper documentation.
It enables us to describe a XML document efficiently.
Disadvantages of DTD
DTDs are hard to read and maintain if they are large in size.
It is not object oriented.
The documentation support is limited.
DTD doesn’t support namespaces.
23
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
The DOM can be used to build documents, navigate their structure, and add,
modify, or delete elements and content.
The Document Object Model (DOM) is a programming API for HTML and
XML documents. It defines the logical structure of documents and the way a
document is accessed and manipulated.
When a web page is loaded, the browser creates a Document Object Model
of the page.
The HTML DOM model is constructed as a tree of Objects:
The HTML DOM Tree of Objects
24
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
HTML DOM methods are actions you can perform (on HTML Elements).
HTML DOM properties are values (of HTML Elements) that you can set or
change.
The HTML DOM can be accessed with JavaScript (and with other
programming languages).
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).
<html>
<body>
<h2>My First Page</h2>
<p id="demo"></p>
<script>
[Link]("demo").innerHTML = "Hello World!";
</script>
</body>
</html>
25
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
My First Page
Hello World!
The easiest way to get the content of an element is by using the innerHTML
property.
The innerHTML property can be used to get or change any HTML element,
including <html> and <body>.
The HTML DOM document object is the owner of all other objects in your web
page.
If you want to access any element in an HTML page, you always start with
accessing the document object.
Below are some examples of how you can use the document object to access and
manipulate HTML.
26
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Method Description
Dynamic content
The HTML DOM allows JavaScript to change the style of HTML elements.
27
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Example
<html>
<body>
<p id="p2">Hello World!</p>
<script>
[Link]("p2").[Link] = "blue";
</script>
</body>
</html>
OUTPUT
Using Events
The HTML DOM allows you to execute code when an event occurs.
An element is clicked on
The page has loaded
Input fields are changed
This example changes the style of the HTML element with id="id1", when the user
clicks a button:
<html>
<body>
<h1 id="id1">My Heading 1</h1>
<button type="button"
onclick="[Link]('id1').[Link] = 'red'">
28
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Click Me!</button>
</body>
</html>
OUTPUT
CSS POSITIONING
Position
Property Description
29
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Position
Property Description
1. Static Positioning
Static is the default position of an element. It does not accept properties
like top, left, right, or bottom.
<html>
<head>
<style>
div {
border: 1px solid black;
padding: 10px;
margin: 10px;
}
</style>
</head>
<body>
<div>Box 1</div>
<div>Box 2</div>
</body>
</html>
30
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
2. Relative Positioning
Relative positioning places an element relative to its normal position.
You can move it using top, left, right, or bottom.
<html>
<head>
<style>
div {
border: 1px solid black;
padding: 10px;
margin: 10px;
}
.relative {
position: relative;
top: 20px;
left: 30px;
}
</style>
</head>
<body>
<div>Box 1</div>
<div class="relative">Box 2</div>
</body>
</html>
OUTPUT
31
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
3. Absolute Positioning
Absolute positioning removes the element from the document flow and
places it relative to the nearest ancestor with a positioning context (relative,
absolute, or fixed).
<html>
<head>
<style>
.container {
position: relative;
width: 300px;
height: 200px;
border: 2px solid black;
margin: 20px auto;
}
.absolute {
position: absolute;
top: 50px;
left: 50px;
background-color: pink;
padding: 10px;
}
</style>
</head>
<body>
<div class="container">
<p>Container with Relative Positioning</p>
<div class="absolute">Absolutely Positioned Element</div>
</div>
</body>
</html>
OUTPUT
32
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
The pink box (.absolute) is positioned 50px down and 50px right within the
.container.
It does not affect other elements in the flow.
4. Fixed Positioning
Fixed positioning removes the element from the flow and positions it
relative to the viewport. It remains in place even when the page scrolls.
<html>
<head>
<style>
.fixed {
position: fixed;
top: 10px;
right: 10px;
background-color: lightgreen;
padding: 20px;
border: 2px solid black;
}
.content {
height: 1200px;
padding: 10px;
}
</style>
</head>
<body>
33
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
The fixed element stays at the top-right corner of the viewport even as the user
scrolls.
5. Sticky Positioning
Sticky positioning switches between relative and fixed based on the scroll
position
<html>
<head>
<style>
.sticky {
position: sticky;
top: 0;
background-color: yellow;
padding: 10px;
}
</style>
</head>
<body>
<div class="sticky">I am sticky</div>
<p>Scroll down to see the effect.</p>
<div style="height: 1000px;"></div>
</body>
34
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
</html>
OUTPUT
The sticky element stays at the top of the viewport as you scroll but only
within its containing element.
EVENT BUBBLING
<html>
<head>
<title>Event Bubbling Example</title>
</head>
<body>
<div id="parent" style="padding: 20px; background-color: lightblue;">
Parent Div
<button id="child">Click Me</button>
35
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
</div>
<script>
[Link]("parent").addEventListener("click", function()
{
alert("Parent Div Clicked!");
});
[Link]("child").addEventListener("click", function()
{
alert("Button Clicked!");
});
</script>
</body>
</html>
OUTPUT
If you click the button, the event fires on the button first (child).
Then, it bubbles up and triggers the event on the parent <div>.
36
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
[Link]("child").addEventListener("click", function(event) {
alert("Button Clicked!");
[Link](); // Prevents bubbling to parent
});
Event bubbling helps in event delegation, reducing the need to add multiple event
listeners.
Use stopPropagation() if you don’t want events to propagate to parent elements.
DATA BINDING
Data binding is the process that couples two data sources together and
synchronizes them. With data binding, a change to an element in a data set
automatically updates in the bound data set.
Data binding may be used for many reasons, such as to link an application's
user interface (UI) and the data it displays, for data entry, reporting and in text box
elements. It also lets internet users manipulate the representation of data in the
elements of a web page without needing to use a complicated programming or
scripting processes.
Data and data objects of different logic functions can be bound together in
data binding. Data types with different languages can also be bound, such as data
binding Extensible Markup Language (XML) and UI.
Each data change in one data set automatically reflects in the other bound
data set. In binding syntax, the data source is the data provider, and the other data
set is the data consumer. The binding forms the link between the data provider and
the data consumer, enabling the connection between visual element data and a data
source.
Data binding eliminates the need for Document Object Model (DOM)
manipulation. DOM is an application programming interface, or API, for
Hypertext Markup Language (HTML) and XML.
37
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Types of data binding are typically defined by their data flow and include
the following:
One-way binding is a relatively simple type of data binding. Changes to the data
provider update automatically in the data consumer data set, but not the other way
around.
Two-way binding is where changes to either the data provider or the data consumer
automatically updates the other.
One-way-to-source binding is the reverse of one-way binding. Changes to the data
consumer automatically update the data provider but not the other way around.
One-time binding is where changes to the data provider do not automatically
update the data consumer. This approach is useful when only a snapshot of the data
is needed, and the data is static.
Data binding can be simple or complex. Microsoft defines simple data
binding as the ability to bind to a single data element. Complex data binding is
when multiple elements are bound together.
38
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Reporting. Binding is a common way to compile reports that display data from
a data source to a screen or printer.
Data entry. Data binding is also a common way to enter large amounts of data
and keep it updated and synchronized to a data source.
Lookup tables. Lookup tables are information tables that are typically a part of
larger data displays. Data binding and controls are used to display and change
data.
Master-detail formats. This is a model for communication protocols where
one device or process controls another. These formats may have two tables of
data bound together.
Data binding tools
Data binding tools include the following:
Visual Studio is a Microsoft product that provides design tools for working
with custom objects as a data source in applications. Visual Studio is also used
to bind UI controls. Changes made to objects are automatically made in a
database.
Data Binding Library is a support library for Android developers that binds
UI components to data sources.
39
UNIT V:- Advance script: JavaScript and objects, JavaScript own objects, the
DOM and web browser environments, forms and validations.
<script>
emp={id:102,name:"Shyam Kumar",salary:40000}
[Link]([Link]+" "+[Link]+" "+[Link]);
</script>
<script>
var emp=new Object();
[Link]=101;
[Link]="Ravi Malik";
[Link]=50000;
[Link]([Link]+" "+[Link]+" "+[Link]);
</script>
By using an object constructor (using new keyword)
you need to create function with arguments. Each argument value can beassigned in
the current object by using this keyword.
<script>
function emp(id,name,salary){
[Link]=id;
[Link]=name;
[Link]=salary;
}
e=new emp(103,"Vimal Jaiswal",30000);
person = {
firstName:
'John',lastName:
'Doe'
};
The person object has two properties: firstName and lastName.a property
A property that is defined directly on an object is own while a property that theobject receives
from its prototype is inherited.
The following creates an object called employee that inherits from the personobject:
The employee object has its own property job, and inherits firstName andlastName
properties from its prototype person.
When html document is loaded in the browser, it becomes a document object. Itis the root
element that represents the html document.
It has properties and methods. By the help of document object, we can add dynamic
content to our web page.
“The W3C Document Object Model (DOM) is a platform and language-neutral interface
that allows programs and scripts to dynamically access and update thecontent, structure,
and style of a document."
Properties of document object
getElementsByName() - returns all the elements having the given name value.
<script type="text/javascript">
function printvalue(){
var name=[Link];
alert("Welcome: "+name);
}
</script>
<form name="form1">
Enter Name:<input type="text" name="name"/>
<input type="button" onclick="printvalue()" value="print name"/>
</form>
Browser environments
JavaScript was created for web browsers. But, since then, it has expanded andbecome a
language with different platforms and uses.
A host environment has its own objects and functions in addition to thelanguage
core.
function welcome() {
[Link]("Welcome to W3Docs");
}
// global functions are global object methods:
[Link]();
Document Object Model (DOM)
Document Object Model (DOM) is targeted at representing the overall pagecontent as
objects that can be transformed.
The document object is considered the primary “entry point” to the page. It allows you to
change or create anything on the page.
The Browser Object Model (BOM) represents extra objects provided by the hostenvironment
to work with anything excluding the document.
The following are the most common and practical ways you might want tomanipulate
the Element object:
Next, you select the element and change its innerText valueconst p =
is dawning';
Manipulate the Class Attribute
You can add a new class attribute to an Element by using the add() method ofthe classList
object:
[Link]('myClass');
you can control the style of an element by adding or removing classes thatchange the
style rules applied to an element.
.color-primary
{color:
#007bff;
}
.color-secondary
{color:
#6c757d;
}
.bold {
font-weight: 700;
}
If you have an element with the color-primary class applied, you can replace itwith color-
secondary class, or add the bold class.
<p class="myParagraph">A new day is dawning</p>const p
= [Link]('.myParagraph');
// replace a class
[Link]('color-primary', 'color-secondary');
// remove a class
[Link]('color-secondary');
or
const p = [Link]('.myParagraph');
Besides creating a DOM tree out of your HTML file, you also have the ability tocreate
DOM elements programmatically using JavaScript.
const p = [Link]('p');
[Link] = 'This paragraph is created using JavaScript';const
body = [Link]('body');
[Link](p);
let p2 = [Link]('p');
let p1=[Link]('#first');
[Link](p2, p1);
[Link]('#profile-pic');
[Link]('src', '[Link]');
The data attribute is used to store extra information on HTML elements. How you use the
data is up to you.
// Use camelCase when your data attribute is more than one word
[Link]([Link]) // light
The code gets the values of various form fields (name, email, what, password,address)
using Form.
Data Validation:
Name Validation: Checks if the name field is empty or contains any digits.
Email Validation: Checks if the email field is empty or lacks the „@‟ [Link]
Validation: Checks if the password field is empty or less than 6 characters long.
eturns true if all validation checks pass, indicating that the form can besubmitted.
Otherwise, it returns false, preventing form submission.
Sets focus to the first field that failed validation, ensuring the user‟s attention isdrawn to the
problematic field.
Ex.
if (address === "")
{[Link]
("Please enter your address.");
[Link]();
return false;
}
if ([Link] < 6) {
alert ("Password should be atleast 6 character long");
[Link]();
return false;
DHTML combines HTML, CSS, JavaScript, and the Document Object Model(DOM)
to create dynamic content.
It uses the Dynamic Object Model to modify settings, properties, and [Link] is
supported by some versions of Netscape Navigator and Internet Explorer
4.0 and higher.
CSS: The abbreviation of CSS is Cascading Style Sheet. It helps in the styling of the web
pages and helps in designing of the pages. The CSS rules for DHTML willbe modified at
different levels using JS with event handlers which adds a significant amount of dynamism
with very little code.
DOM: It is known as a Document Object Model which acts as the weakest link in it. The only
defect in it is that most of the browsers does not support DOM. It is away to manipulate the
static content.
Advantages:
Size of the files are compact in compared to other interactional media like Flashor
Shockwave, and it downloads faster.
Disadvantages:
It is not supported by all the browsers. It is supported only by recent browserssuch as
Netscape 6, IE 5.5, and Opera 5 like browsers.
It is compulsory to add the events in the DHTML page. Without events, therewill be no
dynamic content on the HTML page.
1 onchange - It occurs when the user changes or updates the value of an object.
7 onmouseover - It occurs when a user moves the cursor over an HTML object.
Ex.
<script type="text/javascript">
function ChangeText(ctext)
{
[Link]=" Hi Gopal! ";
}
</script>
<body>
<font color="red"> Click on the Given text for changing it: <br>
</font>
<font color="blue">
<h1 onclick="ChangeText(this)"> Hello Gopal! </h1>
</font>
</body>
buttons
In dhtml we can create button using <button> Tag.
<body>
<p id="demo"> This text changes color when click on the following differentbuttons.
</p>
<button onclick="change_Color('green');"> Green </button>
<button onclick="change_Color('blue');"> Blue </button>
<script type="text/javascript">
function change_Color(newColor) {
var element = [Link]('demo').[Link] = newColor;
}
</script>