web design unit 2
web design unit 2
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="http://www.w3.org/2000/svg">
<svg>
</body>
</html>
Output:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<img src="https://media.geeksforgeeks.org/wp-content/uploads/20210729182205/
Component1-300x258.png" >
</img>
</body>
</html>
Output:
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<img src="https://media.geeksforgeeks.org/wp-content/uploads/20210729183033/Component2-
300x189.jpg">
</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
mputer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="pho
ne.htm">
<area shape="circle" coords="337,300,44" alt="Coffee" href="coffe
e.htm">
</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="computer.htm">
This is the area that becomes clickable and will send the user to the page
"computer.htm":
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="movie.ogg" 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="movie.ogg" 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="horse.ogg" 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="horse.ogg" 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: