Module 5-HTML
Module 5-HTML
Tag Description
<col> It is used with <colgroup> element to specify column properties for each column.
HTML Table with cell padding:specify padding for table header and table data by two ways:
1. By cellpadding attribute of table in HTML 2. By padding property in CSS
HTML Table width: We can specify the HTML table width using the CSS width property. It can be specify
in pixels or percentage.We can adjust our table width as per our requirement. Following is the example to display
table with width. table{ width: 100%; } <html>
<head> <title>table</title>
<style>
table{
border-collapse: collapse;
width: 100%;
}
th,td{
border: 2px solid green;
padding: 15px;
}
</style>
</head>
<body>
<table>
<tr>
<th>1 header</th>
<th>1 header</th>
<th>1 header</th>
</tr>
<tr>
<td>1data</td>
<td>1data</td>
<td>1data</td>
</tr>
<tr>
<td>2 data</td>
<td>2 data</td>
<td>2 data</td>
</tr>
<tr>
<td>3 data</td>
<td>3 data</td>
<td>3 data</td>
</tr>
</table>
</body>
</html>
HTML Table with colspan :If you want to make a cell span more than one column, you can use the colspan
attribute.It will divide one cell/row into multiple columns, and the number of columns depend on the value of
colspan attribute.
HTML Table with rowspan :If you want to make a cell span more than one row, you can use the rowspan
attribute.It will divide a cell into multiple rows. The number of divided rows will depend on rowspan values.
Form Controls
An HTML form is a section of a document which contains controls such as text fields, password fields, checkboxes,
radio buttons, submit button, menus etc.An HTML form facilitates the user to enter data that is to be sent to the
server for processing such as name, email address, password, phone number, etc. .
Why use HTML Form :HTML forms are required if you want to collect some data from of the site visitor.
HTML <form> element :The HTML <form> element provide a document section to take input from user.It
provides various interactive controls for submitting information to web server such as text field, text area, password
field, etc.
Syntax: <form> //Form elements </form>
HTML <input> element :The HTML <input> element is fundamental form element. It is used to create form
fields, to take input from user. We can apply different input filed to gather different information form user.
Following is the example to show the simple text input.
<body>
<form> Enter your name <br>
<input type="text" name="username">
</form>
/body>
HTML TextField Control :The type="text" attribute of input tag creates textfield control also known as single
line textfield control. The name attribute is optional, but it is required for the server side component such as JSP,
ASP, PHP etc.
<form>
First Name: <input type="text" name="firstname"/> <br/>
Last Name: <input type="text" name="lastname"/> <br/>
</form>
HTML <textarea> tag in form:The <textarea> tag in HTML is used to insert multiple-line text in a form. The
size of <textarea> can be specify either using "rows" or "cols" attribute or by CSS.
<html> <head> <title>Form in HTML</title> </head>
<body>
<form>
Enter your address:<br>
<textarea rows="2" cols="20"></textarea>
</form>
</body>
</html>
Label Tag in Form :It is considered better to have label in form. As it makes the code parser/browser/user
friendly.If you click on the label tag, it will focus on the text control. To do so, you need to have for attribute in
label tag that must be same as id attribute of input tag.
<form>
<label for="firstname">First Name: </label> <br/>
<input type="text" id="firstname" name="firstname"/> <br/>
<label for="lastname">Last Name: </label>
<input type="text" id="lastname" name="lastname"/> <br/>
</form>
HTML Password Field Control :The password is not visible to the user in password field control.
<form>
<label for="password">Password: </label>
<input type="password" id="password" name="password"/> <br/>
</form>
HTML 5 Email Field Control :The email field in new in HTML 5. It validates the text for correct email
address. You must use @ and . in this field.
<form>
<label for="email">Email: </label> <input type="email" id="email" name="email"/> <br/
>
</form>
Radio Button Control :The radio button is used to select one option from multiple options. It is used for selection of
gender, quiz questions etc.If you use one name for all the radio buttons, only one radio button can be selected at a time.Using
radio buttons for multiple options, you can only choose a single option at a time.
<form>
<label for="gender">Gender: </label>
<input type="radio" id="gender" name="gender" value="male"/>Male
<input type="radio" id="gender" name="gender" value="female"/>Female <br/>
</form>
Checkbox Control :The checkbox control is used to check multiple options from given checkboxes.
<form> Hobby:<br>
<input type="checkbox" id="cricket" name="cricket" value="cricket"/>
<input type="checkbox" id="football" name="football" value="football"/>
<input type="checkbox" id="hockey" name="hockey" value="hockey"/>
</form>
Submit button control :HTML <input type="submit"> are used to add a submit button on web page. When user clicks on
submit button, then form get submit to the server. Syntax: <input type="submit" value="submit">
The type = submit , specifying that it is a submit button.
The value attribute can be anything which we write on button on web page.
<form>
<label for="name">Enter name</label><br>
<input type="text" id="name" name="name"><br>
<label for="pass">Enter Password</label><br>
<input type="Password" id="pass" name="pass"><br>
<input type="submit" value="submit">
</form>
HTML <fieldset> element: The <fieldset> element in HTML is used to group the related information of a form.
This element is used with <legend> element which provide caption for the grouped elements.
<form>
<fieldset> <legend>User Information:</legend>
<label for="name">Enter name</label><br><input type="text" id="name" name="name"><br>
<label for="pass">Enter Password</label><br><input type="Password" id="pass" name="pass">
<input type="submit" value="submit"> </fieldset>
</form>
Reset And Submit Buttons :The Submit Button allows the user to send the form data to the web server. The
Reset Button is used to reset the form data and use the default values.
<html>
<h3>Example of a Submit And Reset Button</h3>
<body>
<form action="test.php" method="post" id="users">
<label for="username">Username:</label>
<input type="text" name="username" id="Username">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
Hidden controls : HTML Hide Element- You can hide an element by using the Boolean attribute hidden with the
element. When you specify the hidden attribute in the HTML file, then the browser will not display that element,
which is specified with this attribute.
Syntax :<element or tag hidden> Any statement or content </element or tag>
The Target Attribute in HTML Forms : The Target attribute is used to specify whether the submitted result will
open in the current window, a new tab or on a new frame. The default value used is “self” which results in the form
submission in the same window. For making the form result open in a new browser tab, the value should be set to
“blank”.
Name Attribute in Html Forms : The name attribute is required for each input field. If the name attribute is not
specified in an input field then the data of that field would not be sent at all.
The Method Attribute :It is used to specify the HTTP method used to send data while submitting the form.There
are two kinds of HTTP Methods, which are GET and POST.
In the GET method, after the submission of the form, the form values will be visible in the address bar of the new
browser tab.
In the post method, after the submission of the form, the form values will not be visible in the address bar of the
new browser tab as it was visible in the GET method.
<html>
<body>
<form action="/test.php" target="_blank" method="post">
Username:<br> <input type="text" name="username"> <br>
Password:<br> <input type="password" name="password"> <br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
HTML <frame> tag (Not supported in HTML5)
HTML <frame> tag define the particular area within an HTML file where another HTML web page can be
displayed.A <frame> tag is used with <frameset>, and it divides a webpage into multiple sections or frames, and
each frame can contain different web pages.
Note: Do not use HTML <frame> tag as it is not supported in HTML5, instead you can use <iframe> or <div>
with CSS to achieve similar effects in HTML. Syntax :< frame src = "URL" >
Note: Do not use HTML <frameset> element as it is deprecated and not supported by HTML5, but you can use
<iframe> tag instead. Syntax : <frameset cols=" ">............</frameset>
Iframe Syntax : An HTML iframe is defined with the <iframe> tag: <iframe src="URL"></iframe>
Here, "src" attribute specifies the web address (URL) of the inline frame page.
Set Width and Height of iframe :You can set the width and height of iframe by using "width" and "height"
attributes. By default, the attributes values are specified in pixels but you can also set them in percent. i.e. 50%,
60% etc.
Iframe Target for a link :You can set a target frame for a link by using iframe. Your specified target attribute of
the link must refer to the name attribute of the iframe.
<html> <body> <h2>Iframe - Target for a Link</h2>
<iframe height="300px" width="100%" src="new.html" name="iframe_a"></iframe>
<p><a href="https://www.javatpoint.com" target="iframe_a">JavaTpoint.com</a></p>
<p>The name of iframe and link target must have same value else link will not open as a frame.
</body>
</html>
Embed YouTube video using iframe :You can also add a YouTube video on your webpage using the <iframe>
tag. The attached video will be played at your webpage and you can also set height, width, autoplay, and many
more properties for the video.Following are some steps to add YouTube video on your webpage:
o Goto YouTube video which you want to embed.
o Click on SHARE ➦ under the video.
o Click on Embed <> option.
o Copy HTML code.
o Paste the code in your HTML file
o Change height, width, and other properties (as per requirement).
Concept of CSS
CSS (Cascading Style Sheets) is a stylesheet language used to design the webpage to make it attractive. The reason
of using CSS is to simplify the process of making web pages presentable. CSS allows you to apply styles to web
pages. More importantly, CSS enables you to do this independent of the HTML that makes up each web page.
Internal CSS :An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML page, within a <style> element.
The following example sets the text color of ALL the <h1> elements (on that page) to blue, and the text color of
ALL the <p> elements to red. In addition, the page will be displayed with a "powderblue" background color:
External CSS :An external style sheet is used to define the style for many HTML pages.To use an external style
sheet, add a link to it in the <head> section of each HTML page:
The external style sheet can be written in any text editor. The file must not contain any HTML code, and must be
saved with a .css extension.
"styles.css":
body { background-color: powderblue; }
h1 { color: blue; }
p { color: red; }
CSS Properties
List Properties
Property Description Values
list-style Sets all the properties for a list in one declaration list-style-type, list-style-position, list-style-image, inherit
list-style-position Specifies where to place the list-item marker inside, outside, inherit
none, disc, circle, square, decimal, decimal-leading-zero,
list-style-type Specifies the type of list-item marker armenian, georgian, lower-alpha, upper-alpha, lower-greek,
lower-latin, upper-latin, lower-roman, upper-roman, inherit
Border Properties
Property Description Values
border-color Sets the color of the four borders color_name, hex_number, rgb_number, transparent, inherit
border-width Sets the width of the four borders thin, medium, thick, length, inherit
Font Properties
Property Description Values
font-family Specifies the font family for text family-name, generic-family, inherit
font-style Specifies the font style for text normal, italic, oblique, inherit
CSS Padding :The CSS padding property defines a padding (space) between the text and the border.
CSS Margin : The CSS margin property defines a margin (space) outside the border.
Font Selection is Important Choosing the right font has a huge impact on how the readers experience a website.
Generic Font Families In CSS there are five generic font families:
1. Serif fonts have a small stroke at the edges of each letter. They create a sense of formality and elegance.
2. Sans-serif fonts have clean lines (no small strokes attached). They create a modern and minimalistic look.
3. Monospace fonts - here all the letters have the same fixed width. They create a mechanical look.
4. Cursive fonts imitate human handwriting.
5. Fantasy fonts are decorative/playful fonts.
Sans-serif Arial
Verdana
Helvetica
Fantasy
Copperplate
Papyrus
We can apply a class to various elements so that it could be The Id is unique in a page, and we can only apply
numerous times on a single page. it to one specific element.
The class is assigned to an element and its name starts with "." The name of the Id starts with the "#" symbol
followed by the name of the class. followed by a unique id name.
We can attach multiple class selectors to an element. We can attach only one ID selector to an element.
Syntax: Syntax:
#id{ .class{
// declarations of CSS // declarations of CSS
} }
ID Selector :The id selector is used to select the id attribute of an HTML element for selecting a particular
element. An id is always unique within the page, so it is chosen to select a single, unique element.
It is written with the hash character (#), followed by the id of the element.
Class Selector :The class selector is used to select the HTML elements with a specific class attribute. It is written
with a period character . (full stop symbol) followed by the class name. A class name should not be started with a
number.
*****************************************