Unit 2 Web Design
Unit 2 Web Design
4 Example
The HTML code <ul><li>Item 1</li><li>Item 2</li></ul>
2</li></ul> creates a list with two items.
HTML Ordered Lists with tags
1 Definition
Ordered lists present items in a numbered format, using the <ol> tag for the list and <li> for
<li> for individual items.
2 Numbering
The numbering can be customized, including using Roman numerals, letters, or even custom
even custom values.
3 Applications
Ordered lists are helpful for steps in a procedure, ranked lists, or any content requiring a specific
requiring a specific sequence.
4 Example
The code <ol><li>Step 1</li><li>Step 2</li></ol> creates a numbered list with two steps.
two steps.
HTML Definition Lists with tags
1 Definition
Definition lists are used to present terms and their corresponding definitions, using the <dl> tag for
<dl> tag for the list, <dt> for terms, and <dd> for definitions.
2 Structure
Each <dt> element is a term, and its corresponding <dd> element provides its definition.
definition.
3 Applications
Definition lists are suitable for glossaries, dictionaries, or any content that requires pairing terms
pairing terms with explanations.
4 Example
The code <dl><dt>HTML</dt><dd>HyperText Markup Language</dd></dl> creates a definition list
a definition list for the term "HTML."
Creating HTML Tables
1 Purpose
Tables are used to organize information into rows and columns, providing a structured
structured format for data presentation.
2 Structure
The <table> tag defines the table, <tr> defines rows, and <td> defines cells within rows and
within rows and columns.
3 Applications
Tables are used for displaying data, creating layouts, or presenting information in a tabular
in a tabular format.
4 Example
The code
<table><tr><td>Name</td><td>Age</td></tr><tr><td>John</td><td>30</td></tr></table>
</td></tr></table> creates a simple table with two rows and two columns.
Table Structure and Attributes
Attribute Description
The <frameset> tag defines a frame The <frame> tag defines each frame This code divides the window into
set, which divides the browser within the frameset. It specifies the into two frames, each displaying a
window into multiple frames. source document for each frame. a different HTML document.
2 Structure
The <iframe> tag has a src attribute to specify the URL of the embedded document.
3 Applications
IFrames are used for embedding videos, maps, or other interactive content within a webpage.
webpage.
4 Example
The code <iframe src=“" width="600" height="450" style="border:0;" allowfullscreen=""
allowfullscreen="" loading="lazy">
difference between iframe and framset
Frameset
Framesets divide the entire browser window into multiple frames, each displaying a separate HTML document.
document.
Iframe
IFrames embed a separate HTML document within the current document, allowing for more flexible integration of
content.
Control
Framesets offer less control over individual frame behavior compared to iframes, which provide more granular
granular control.
Navigation
Framesets can cause navigation issues as each frame has its own history, while iframes maintain a single history for
single history for the entire page.
SEO
Framesets can negatively impact SEO due to content duplication and navigation issues, while iframes generally have
less SEO impact.
An HTML form is used to collect user input. The user input is most often sent to a server
for processing.
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form action="">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"
value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname"
value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
The action attribute defines the action to be performed when the form is
submitted.
Example
On submit, send form data to "action_page.php":
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John
"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"
><br><br>
<input type="submit" value="Submit">
</form>
The Target Attribute
The target attribute specifies where to display the response that is received after submitting
the form.
The target attribute can have one of the following values:
The default value is _self which means that the response will open in the current window.
Value Description
_blank The response is displayed in a new window or tab
_self The response is displayed in the current window
_parent The response is displayed in the parent frame
_top The response is displayed in the full body of the window
framename The response is displayed in a named iframe
The Method Attribute
The method attribute specifies the HTTP method to be used when submitting the form data.
The form-data can be sent as URL variables (with method="get") or as HTTP post
transaction (with method="post").
The default HTTP method when submitting form data is GET.
Example
This example uses the GET method when submitting the form data:
<form action="/action_page.php" method="get">
This example uses the POST method when submitting the form data:
Notes on POST:
•Appends the form data inside the body of the HTTP request (the submitted form data is
not shown in the URL)
•POST has no size limitations, and can be used to send large amounts of data.
•Form submissions with POST cannot be bookmarked
Tip: Always use POST if the form data contains sensitive or personal information!
HTML Form Elements
Tag Description
<form> Defines an HTML form for user input
<input> Defines an input control
<textarea> Defines a multiline input control (text area)
<label> Defines a label for an <input> element
<fieldset> Groups related elements in a form
<legend> Defines a caption for a <fieldset> element
<select> Defines a drop-down list
<optgroup> Defines a group of related options in a drop-down
list
<option> Defines an option in a drop-down list
<button> Defines a clickable button
<datalist> Specifies a list of pre-defined options for input
controls
<output> Defines the result of a calculation
The <input> Element
One of the most used form elements is the <input> element.
The <input> element can be displayed in several ways, depending on the type attribute.
Example
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname">
Here are the different input types you can use in HTML:
•<input type="button">
•<input type="checkbox">
•<input type="color">
•<input type="date">
•<input type="datetime-local">
•<input type="email">
•<input type="file">
•<input type="hidden">
•<input type="image">
•<input type="month">
•<input type="number">
•<input type="password">
•<input type="radio">
•<input type="range">
•<input type="reset">
•<input type="search">
•<input type="submit">
•<input type="tel">
•<input type="text">
•<input type="time">
•<input type="url">
•<input type="week">
The <form> element is a container for different types of input elements, such as:
text fields, checkboxes, radio buttons, submit buttons, etc.
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
Example
<label for="cars">Choose a car:</label>
<select id="cars" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
Example
<label for="cars">Choose a car:</label>
<select id="cars" name="cars" size="3">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
Allow Multiple Selections:
Use the multiple attribute to allow the user to select more than one value:
<label for="cars">Choose a car:</label>
<select id="cars" name="cars" size="4" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
The <textarea> Element
The <textarea> element defines a multi-line input field (a text area):
Example
<textarea name="message" rows="10" cols="30">
The cat was playing in the garden.
</textarea>
The rows attribute specifies the visible number of lines in a text area.
The cols attribute specifies the visible width of a text area.
The <button> Element
The <button> element defines a clickable button:
<form action="/action_page.php">
<fieldset>
<legend>Personalia:</legend>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
1.<!DOCTYPE html>
2. <html>
3. <head>
4. <title>Form in HTML</title>
5.</head>
6. <body>
7. <h2>Registration form</h2>
8. <form>
9. <fieldset>
10. <legend>User personal information</legend>
11. <label>Enter your full name</label><br>
12. <input type="text" name="name"><br>
13. <label>Enter your email</label><br>
14. <input type="email" name="email"><br>
15. <label>Enter your password</label><br>
16. <input type="password" name="pass"><br>
17. <label>confirm your password</label><br>
18. <input type="password" name="pass"><br>
19. <br><label>Enter your gender</label><br>
20. <input type="radio" id="gender" name="gender" value="male"/>Male <br>
1. <input type="radio" id="gender" name="gender" value="female"/>Female <br/>
2. <input type="radio" id="gender" name="gender" value="others"/>others <br/>
3. <br>Enter your Address:<br>
4. <textarea></textarea><br>
5. <input type="submit" value="sign-up">
6. </fieldset>
7. </form>
8. </body>
9.</html>
1.<form action="#">
2.<table>
3.<tr>
4. <td class="tdLabel"><label for="register_name" class="label">Enter name:</label></td>
5. <td><input type="text" name="name" value="" id="register_name" style="width:160px"/></td>
6.</tr>
7.<tr>
8. <td class="tdLabel"><label for="register_password" class="label">Enter password:</label></td>
9. <td><input type="password" name="password" id="register_password" style="width:160px"/></td>
10.</tr>
11.<tr>
12. <td class="tdLabel"><label for="register_email" class="label">Enter Email:</label></td>
13. <td>
14.<input type="email" name="email" value="" id="register_email" style="width:160px"/></td>
15.</tr>
16.<tr>
17. <td class="tdLabel"><label for="register_gender" class="label">Enter Gender:</label></td>
18. <td>
19.<input type="radio" name="gender" id="register_gendermale" value="male"/>
20.<label for="register_gendermale">male</label>
21.<input type="radio" name="gender" id="register_genderfemale" value="female"/>
22.<label for="register_genderfemale">female</label>
23. </td>
24.</tr>
1.<tr>
2. <td class="tdLabel"><label for="register_country" class="label">Select Country:</label></td>
3. <td>
4. <select name="country" id="register_country" style="width:160px">
5. <option value="india">india</option>
6. <option value="pakistan">pakistan</option>
7. <option value="africa">africa</option>
8. <option value="china">china</option>
9. <option value="other">other</option>
10. </select>
11.</td>
12.</tr>
13.<tr>
14. <td colspan="2"><div align="right"><input type="submit" id="register_0" value="register"/>
15.</div></td>
16.</tr>
17.</table>
18.</form>
Difference between radio button and checkbox
It is used when only one option to be selected out Checkbox allows one or many options to be
of several available options. selected.
It is created by using HTML <input> tag but type It is also created using HTML <input> tag but type
attribute is set to radio. attribute is set to checkbox.
It is used when you want to limit the users choice It is used when you want to allow user to select
to just one option from the range provided. multiple choices.
Why Use CSS?
CSS is used to define styles for your web pages, including the design, layout and variations in display for
different devices and screen sizes.
CSS Example
body {
background-color: lightblue;
}
h1 {
color: white;
text-align: center;
}
p {
font-family: verdana;
font-size: 20px;
}
Try it Yourself
CSS Syntax
In this example all <p> elements will be center-aligned, with a red text color:
p{
color: red;
text-align: center;
}
Example Explained
•p is a selector in CSS (it points to the HTML element you want to style: <p>).
•color is a property, and red is the property value
•text-align is a property, and center is the property value
CSS Selectors
The CSS element Selector
The element selector selects HTML elements based on the element name.
Example
Here, all <p> elements on the page will be center-aligned, with a red text color:
p{
text-align: center;
color: red;
}
The CSS id Selector
• The id selector uses the id attribute of an HTML element to select a specific element.
• The id of an element is unique within a page, so the id selector is used to select one unique element!
• To select an element with a specific id, write a hash (#) character, followed by the id of the element.
Example
The CSS rule below will be applied to the HTML element with id="para1":
#para1 {
text-align: center;
color: red;
}
The CSS class Selector
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by the class name.
Example
In this example all HTML elements with class="center" will be red and center-aligned:
.center {
text-align: center;
color: red;
}
Example
In this example only <p> elements with class="center" will be red and center-aligned:
p.center {
text-align: center;
color: red;
}
The CSS Universal Selector
The universal selector (*) selects all HTML elements on the page.
Example
The CSS rule below will affect every HTML element on the page:
*{
text-align: center;
color: blue;
}
The CSS Grouping Selector
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; Example
color: red; In this example we have grouped the selectors from the code
} above:
h1, h2, p {
h2 { text-align: center;
text-align: center; color: red;
color: red; }
}
p {
text-align: center;
color: red;
}
Three Ways to Insert CSS
There are three ways of inserting a style sheet:
•External CSS
•Internal CSS
•Inline CSS
External 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.
Example
External styles are defined within the <link> element, inside the <head> section of an HTML page:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
An external style sheet can be written in any text editor, and must be saved with a .css extension.
The external .css file should not contain any HTML tags.
Here is how the "mystyle.css" file looks:
"mystyle.css"
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
Internal CSS
An internal style sheet may be used if one single HTML page has a unique style.
The internal style is defined inside the <style> element, inside the head section.
Example
Internal styles are defined within the <style> element, inside the <head> section of an HTML page:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Inline CSS
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style attribute to the relevant element. The style attribute can contain any CSS
property.
Example
Inline styles are defined within the "style" attribute of the relevant element:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
CSS Colors
CSS Background Color
CSS background-color
body {
background-color: lightblue;
}
CSS background-image
The background-image property specifies an image to use as the background of an element.
By default, the image is repeated so it covers the entire element.
body {
background-image: url("paper.gif");
}
If the image above is repeated only horizontally (background-repeat: repeat-x;), the
background will look better:
body {
background-image: url("gradient_bg.png");
background-repeat: repeat-x;
}
Showing the background image only once is also specified by the background-repeat property:
The background-position property is used to specify the position of the background image.
The border-style property can have from one to four values (for the top border, right border, bottom
border, and the left border).
Example
Example
p.one {
border-style: solid;
border-width: 5px 20px; /* 5px top and bottom, 20px on the sides
*/
}
p.two {
border-style: solid;
border-width: 20px 5px; /* 20px top and bottom, 5px on the sides
*/
}
p.three {
border-style: solid;
border-width: 25px 10px 4px 35px; /* 25px top, 10px right, 4px
bottom and 35px left */
}
CSS Margins
The CSS margin properties are used to create space around elements, outside of any defined borders.
With 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).
Example
Use the margin shorthand property with three values:
p {
margin: 25px 50px 75px;
}
If the margin property has two values:
•margin: 25px 50px;
•top and bottom margins are 25px
•right and left margins are 50px
Example
Use the margin shorthand property with two values:
p {
margin: 25px 50px;
}
If the margin property has one value:
•margin: 25px;
•all four margins are 25px
Example
Use the margin shorthand property with one value:
p {
margin: 25px;
}
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.
Example
Use margin: auto:
div {
width: 300px;
margin: auto;
border: 1px solid red;
}