HTML Basics: Structure and Styles
HTML Basics: Structure and Styles
What is HTML?
An HTML element is defined by a start tag, some content, and an end tag:
Web Browsers
HTML Headings
HTML headings are titles
HTML headings are defined with the <h1> to <h6> tags.
<!DOCTYPE html>
<html>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
</body>
</html>
Homework
Interview Questions:
1) Describe about HTML
2) Write the structure of HTML Program
3) Explain about Web Browser and give examples
4) Execute HTML Headings program
HTML Styles
The HTML style attribute is used to add styles to an element, such as color, font, size, and
more.
Syntax of HTML style attribute
<tagname style="property:value;">
Example:
<body style="background-color:blue;">
The CSS background-color property defines the background color for an HTML element
Example1 on Background Color property: Apply Blue color background to body tag:
<!DOCTYPE html>
<html>
<body style="background-color:blue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Example2 on Background color attribute: Apply yellow color background to body tag
<!DOCTYPE html>
<html>
<body style="background-color:yellow;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Exercises: Apply the following colors to body tag one-by-one
Example3 on Background color attribute:
1) Apply chocolate background color to body tag
2) Apply yellow background color to paragraph tag
<!DOCTYPE html>
<html>
</body>
</html>
<!DOCTYPE html>
<html>
<body style="background-color:blue;">
</body>
</html>
Home work:
Interview Questions:
Task1:
Task2:
Task3:
Task4:
The CSS “Text color” property defines the text color for an HTML element.
Syntax:
<tagname style=”color: color name;”> Content </tagname>
Example: <h1 style=”color:green;”> This is a heading </h1>
Example1:
a) Apply red color to heading1
b) Apply green color to heading2
c) Apply blue color to heading3
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Example2:
a) Apply red color to heading1
b) Apply green color to paragraph
c) Apply blue color to heading2
d) Apply orange color to paragraph
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Example3:
a) Apply yellow background color to heading 1 and apply blue color as text color
b) Apply blue background color to heading2 and apply yellow color as text color
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Home Work:
Interview Questions:
Task1:
Task2:
a) Apply “DarkOrange” background color to paragraph1 and apply “DarkGreen” as text color
b) Apply “DarkOrchid” background color to paragraph2 and apply “DarkOrange” as text color
HTML Styles: Fonts
The CSS font-family property defines the font to be used for an HTML element.
Syntax:
<tagname style=”font-family: font name;”> Content </tagname>
Ex: <h1 style=”font-family: arial;”> This is heading 1</h1>
Example1:
a) Apply “arial” font to h1 tag
b) Apply “arial black” font to h2 tag
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Example2:
a) Apply “Calibri” font to h3 tag
b) Apply “Agency FB” font to h4 tag
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Example3:
a) Apply “orange” background color to body tag
b) Apply “agency fb” font to h1 tag
c) Apply “Algerian” font to paragraph
<!DOCTYPE html>
<html>
<head>
</head>
<body style="background-color:orange;">
</body>
</html>
Home work:
Interview Questions:
Task1:
Task2:
The CSS font-size property defines the text size for an HTML element.
Syntax:
<tagname style=”font-size: percentage;”> Content </tagname>
Ex: <h1 style=”font-size:200%;”> This is Heading 1 </h1>
Example:
a) Apply 200% font size to h1 tag
b) Apply 150% font size to h2 tag
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Example 2:
a) Apply 400% font size to h1 tag
b) Apply 200% font size to paragraph tag
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Example3:
a) Apply background color as blue to body tag
b) Apply background color as yellow to h1 tag, apply Arial Black font, 500% font size
c) Apply orange background color to paragraph tag, apply Arial font, 400% font size
<!DOCTYPE html>
<html>
<head>
</head>
<body style="background-color:blue;">
</body>
</html>
The CSS text-align property defines the horizontal text alignment for an HTML element.
Syntax:
<tagname style=”text-align: alignment type;”> Content </tagname>
Ex: <h1 style=”text-align:center;”> This is Heading 1</h1>
<h2 style=”text-align:right;”>This is Heading 2</h2>
Note: left side alignment is the default alignment.
Example1:
a) Apply Center alignment to h1 tag
b) Apply right alignment to paragraph tag
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Home work:
Interview questions:
Task1:
a) To h1 tag, apply blue background color, yellow text color, arial font and 350% font size
b) To h2 tag, apply green background color, white text color, arial black font and 300% font
size
c) To h3 tag, apply brown background color, yellow text color, agency fb font, and 250% font
size
d) To h4 tag, apply black background color, white text color, algerian font and 200% font size
e) To h5 tag, apply yellow background color, green text color, Impact font and 150% font size
f) To h6 tag, apply pink background color, red text color, High Tower Text font and 100% font
size
HTML Formatting Elements
Example1:
a) Apply orange background color to body tag
b) Apply blue background color to first paragraph and apply bold style
c) Apply pink background color to second paragraph and apply italic style
<!DOCTYPE html>
<html>
<head>
</head>
</body>
</html>
Note: <p> is block-level element, where as <b> and <i> elements are Inline elements
A block-level element starts on new line.
Other examples of block-level elements:
o <h1> to <h6>
o <article>
o <div>
o <hr>
o <li>
o <ol>
o <ul>
o <table>
o <video>
An Inline element does not start on a new line.
Ex: <b> and <i> elements do not start on a new line.
Other examples of inline elements:
o <a>
o <big>
o <button>
o <code>
o <img>
o <input>
o <label>
o <map>
o <script>
o <select>
o <small>
o <sub>
o <sup>
o <textarea>
o <time>
Example2:
a) Apply yellow background color to body tag
b) Apply blue background color to h1 tag, orange text color, agency fb font, 150% font size
and both bold and Italic styles
c) Apply green background color to h2 tag, white text color, Calibri font, 100% font size and
Italic style
<!DOCTYPE html>
<html>
<head>
<title> bgcolor, text color, font type, font size, bold and italic </title>
</head>
<body style="background-color:yellow;">
<h1 style="background-color: blue; color: orange; font-family: agency fb; font-size: 150%;"><b><i>
This is Heading 1</i></b></h1>
<h2 style="background-color: green; color: white; font-family: calibri; font-size: 100%;"><i> This is
Heading 2 </i></h2>
</body>
</html>
Example1:
a) Apply orange background color to body tag
b) Display first paragraph as normal paragraph and apply green background color
c) To second paragraph, apply pink background color, apply “small” style
d) To third paragraph, apply blue background color, apply “mark” style
Ex: HTML stands for Hyper Text Markup Language
In this text, highlight Hyper Text Markup Language
<!DOCTYPE html>
<html>
<head>
</head>
<p style="background-color: blue;"> HTML stands for <mark>Hyper Text Markup Language
</mark></p>
</body>
</html>
Example2:
a) Apply pink background color to body tag
b) To paragraph tag, apply blue background color, yellow text color, arial font, 200% font
size and apply “mark” style green background color
<!DOCTYPE html>
<html>
<head>
</head>
<p style="background-color: blue; color: yellow; font-family: arial; font-size:200%;"> CSS stands for
<mark style="background-color: green;"> Cascading Style Sheets </mark></p>
</body>
</html>
Example3:
a) Apply blue background color to body tag
b) To paragraph tag, apply gold background color, red text color, arial black font, 250% font
size, and apply “mark” style with orange background color
<!DOCTYPE html>
<html>
<head>
</head>
<p style="background-color:gold; color: red; font-family: arial black; font-size: 250%"> SQL stands for
<mark style="background-color: orange;"> Structured Query Language </mark> </p>
</body>
</html>
The HTML <del> element defines text that has been deleted from a document.
Syntax:
<del> Content to delete </del>
Ex: <p> Product Discount <del> 10% </del></p>
The HTML <ins> element defines text that has been inserted into a document.
Syntax:
<ins> Content to insert </ins>
Ex: <p> Product Discount <del> 10% </del><ins> 20% </ins></p>
Example1:
a) Apply pink background color to body tag
b) Apply orange background color to <p> tag and apply <del>, <ins> tags
Ex: Content is: delete 5% discount and insert 10% discount on Samsung Galaxy S24
<!DOCTYPE html>
<html>
<head>
</head>
</body>
</html>
Example:
a) Apply green background color to body tag
b) Apply yellow background color to paragraph tag and create the following formula by
using superscript tag
<!DOCTYPE html>
<html>
<head>
</head>
<body style="background-color: green;">
</body>
</html>
Interview Questions:
Task1:
Task2:
a) Apply blue background color to body tag
b) Apply orange background color to <p> tag and apply <del>, <ins> tags
Ex: Content is: delete 10% discount and insert 20% discount on Cosmetics
Task3:
Example:
a) Apply brown background to body tag
b) Apply blue background to h1 tag, apply white text color, apply 250% font size and give “
Web Development” heading
c) Apply yellow background color to paragraph tag, apply 150% font-size and underline “
Web Development” word in the following paragraph:
Web Development is the act of building, creating and maintaining websites. Web
Development encompasses broad range of tasks including everything from coding, to
technical design, to the performance of a website or application running on the internet.
Web Development consists of front-end and back-end components.
<!DOCTYPE html>
<html>
<head>
</head>
<u>Web Development</u> is the act of building, creating and maintaining websites. <u>Web
Development</u> encompasses broad range of tasks including everything from coding, to technical
design, to the performance of a website or application running on the internet. <u>Web
Development</u> consists of front-end and back-end components.
</p>
</body>
</html>
Interview questions:
Task:
HTML comments are used for writing explanations about the code, which can be useful for
anyone for reading or editing the HTML document.
Comments are not displayed in the browser.
By using HTML Comments, we can hide the code or content which need not be displayed in
the browser.
There are two types of HTML comments:
o Single-line comments
o Multi-line comments
Syntax of Single-line comment:
<!-- Comment here -->
Syntax of Multi-line comment:
<!--
Comment line1
Comment line2
-->
<html>
<head>
</head>
</body>
</html>
<head>
</head>
<!--
-->
</body>
</html>
Homework:
Interview Questions:
Task1:
Task2:
HTML Links are used to go from one web page to another web page.
HTML Links are technically called as Hyperlinks.
The HTML <a> tag defines hyperlink. Here <a> tag stands for anchor tag.
Syntax:
<a href=”url”> Link text </a>
Here, “href” stands for Hypertext Reference. “href” is one attribute of <a> tag.
“url” stands for “Uniform Resource Locator”
“url” is the address of another HTML page
Ex: <a href=”[Link] Amazon Website </a>
www:
o www stands for World Wide Web
o World Wide Web is an information System which is used to share the information
over the internet
https:
o https stands for Hyper Text Transfer Protocol Secure
o https is used for secured communication over the internet.
Example1:
a) Apply gold background color to body tag
b) Write first <a> tag and open Amazon website
c) Write second <a> tag and open Flipkart website
<!DOCTYPE html>
<html>
<head>
</head>
<body style="background-color:gold;">
</body>
</html>
Example2:
a) Apply orange background color to body tag
b) To first <a> tag, apply text color as blue, apply font-family as arial and open “Amazon
Website”
c) To second <a> tag, apply text color as green, apply font-family as arial and open “Flipkart
Website”
d) To third <a> tag, apply text color as purple, apply font-family as arial and open “Big
Basket Website”
<!DOCTYPE html>
<html>
<head>
</head>
</body>
</html>
Home work:
Interview Questions:
Task1:
Task2:
<!DOCTYPE html>
<html>
<head>
</head>
</body>
</html>
By default, the linked page will be displayed in the current browser window or same tab of
same window. To change this, we must specify another target for the link.
The target attribute specifies where to open the linked document.
The target attribute can have one of the following values:
o _self opens the document in the same tab. _self is default target. So, no need to
mention in the code.
o _blank opens the document in new tab.
Syntax of _blank
<a href=”url” target=”_blank”> Link Text </a>
Ex: <a href=”[Link] target=”_blank”> Amazon Website </a>
Here, Amazon website will open in new tab.
Example1:
a) Apply orange background color to body tag
b) To <a> tag, apply text color as green, apply font-family as arial, apply 200% font-size and
open “Tata website”, apply _blank target
<!DOCTYPE html>
<html>
<head>
</head>
</body>
</html>
Example2:
a) Apply purple background color to body tag
b) To <a> tag, apply background color as pink, apply text color as blue, apply font style as
Calibri and apply font size as 250% and open Mercedes benz website in another tab.
<!DOCTYPE html>
<html>
<head>
</head>
<body style="background-color:purple;">
</body>
</html>
Home work:
Interview Questions:
Task:
To use an image as a link, then put the <img> tag inside the <a> tag.
Syntax:
<a href=”url”> <img src=”image” alt=”alternate text” height=”size” width=”size”></a>
Here, in <img> tag
Src: specifies the path to the image file (or) Source of image file
Alt: provides alternative text for the image if it cannot be displayed.
Height and width: Define the dimensions of the image.
Example1:
a) Apply “blue” background to body tag
b) Use <a> tag
c) Use “amazon [Link]” with 150 size as height and width
d) Use “amazon [Link]” as Hyperlink to open “amazon” website.
<!DOCTYPE html>
<html>
<head>
</head>
</body>
</html>
Example2:
a) Apply orange background color to body tag
b) Use <a> tag
c) Use “flipkart [Link]” with 100 size as height and width and use “flipkart image” to
open “flipkart website”
d) Use “bigbasket [Link]” with 100 size as height and width and use “bigbasket image”
to open “bigbasket website”
<!DOCTYPE html>
<html>
<head>
<title> Using image as a link </title>
</head>
<body style="background-color:orange;">
</body>
</html>
Example1:
a) Apply yellow background color to body tag
b) Use <a> tag, apply 200% font size
c) Link <a> tag to your Email address
<!DOCTYPE html>
<html>
<head>
</head>
</body>
</html>
Home work:
Interview questions:
Task2:
Example1:
a) Apply blue background color to body tag
b) Use button tag to open Amazon website
<!DOCTYPE html>
<html>
<head>
</head>
</body>
</html>
Example2:
a) Apply orange background color to body tag
b) To first button, apply blue background color, apply pink text color, apply font type as
arial black, apply 200% font size and use this first button to open “Flipkart website”
c) To second button, apply black background color, apply white text color, apply font type
as arial black, apply 200% font size and use this button to open “bigbasket website”
<!DOCTYPE html>
<html>
<head>
</head>
<body style="background-color: orange;">
</body>
</html>
HTML Tables
Sample Table
<html>
<head>
</head>
<table border>
<tr>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 2 </td>
</tr>
</table>
</body>
</html>
Homework
Interview questions:
Columns:
College ID
College Name
College Address
College Email ID
Columns:
Book ID
Book Name
Book Author
No. of pages
Book Price
Example2:
a) Apply pink background color to body tag
b) Use <table> tag, apply blue background color, apply yellow text color, apply arial black
font type, apply 200% font size
c) Display the following customer table:
<!DOCTYPE html>
<html>
<head>
</head>
<body style="background-color:pink;">
<table border style="background-color: blue; color: yellow; font-family: arial black; font-size: 200%;">
<tr>
<th>Customer ID</th>
<th>Name</th>
<th>Ph No.</th>
</tr>
<tr>
<td>1</td>
<td>Susan</td>
<td>9988776655</td>
</tr>
<tr>
<td>2</td>
<td>Suresh</td>
<td>8877665544</td>
</tr>
</table>
</body>
</html>
1. Inline style
2. Internal style
3. External style
Inline Style: If we use Style attribute within tag then it is called as Inline Style
Ex: <table style=”background-color: blue; color: yellow; font-family: arial black; font-size:200%;”>
Internal Style:
<!DOCTYPE html>
<html>
<head>
<style>
table{
background-color: blue;
color: yellow;
font-family: arial black;
font-size:200;
</style>
</head>
<body>
<table border>
<tr>
<th>Customer ID</th>
<th>Name</th>
<th>Phone</th>
</tr>
<tr>
<td>1</td>
<td>Ramesh</td>
<td>9988776655</td>
</tr>
<tr>
<td>2</td>
<td>Suresh</td>
<td>8877665544</td>
</tr>
</table>
</body>
</html>
When we will go for inline style and internal style and external style?
Ans:
a) If we want to apply the style to a tag individually then we will go for inline style
b) If we want to apply the style to a tag throughout the document then we will go for internal
style
c) If we want to apply the style to a tag throughout multiple documents then we will go for
external style
Home work:
Interview questions:
a) What is the fundamental difference between inline style, internal style and external style?
b) Write the syntaxes for inline and internal styles
If we want to apply the style to a tag throughout multiple documents then we will
go for External Style
Syntax for using external Style:
<head>
<title> Some title goes here </title>
<link rel=”stylesheet” href=”[Link]”>
</head>
Ex:
<head>
<title> External Style Example </title>
<link rel=”stylesheet” href=”[Link]”>
</head>
Note: file name is your choice. Ex: [Link]
Interview Questions:
Task1:
Task2:
Task3:
a) Apply purple background color to body tag
b) Apply external style to Department table
Columns: Dept ID, Name, Location, phone, Email ID
HTML Table Borders
Example1:
Create a table with 2 pixels border size and with blue border color with following columns:
a) First Name
b) Last Name
c) Age
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
</style>
</head>
<body>
<table>
<tr>
</tr>
<tr>
<td> Anitha </td>
<td> 25 </td>
</tr>
<tr>
<td> VH </td>
<td> 25 </td>
</tr>
</table>
</body>
</html>
Example2:
Create passenger table with the following properties:
a) Border size: 4px
b) Border color: green
c) Font-family: verdana
d) Font-size: 100%
e) Background color: yellow
f) Text color: blue
g) Columns are:
1) Passenger ID
2) Name
3) Destination
4) Date Of Journey
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
font-family: verdana;
font-size: 100%;
background-color: yellow;
color: blue;
</style>
</head>
<body>
<table>
<tr>
</tr>
<tr>
<td> 11 </td>
</tr>
<tr>
<td> 12 </td>
</tr>
</table>
</body>
</html>
HTML Table Borders: Collapsed Table Borders
To avoid double borders in a table, we have to use “Collapsed table borders” concept.
We use border-collapse property to avoid double borders in a table.
Syntax:
<head>
<style>
table, th, td {
border-collapse: collapse;
}
</style>
</head>
Example:
Display the clear difference between with “border-collapse” and without “border-collapse” on
Employees table
Columns are:
a) Emp ID
b) Emp Name
c) Emp Salary
d) Table font family: Calibri
e) Table font size: 200%
<!DOCTYPE html>
<html>
<head>
<style>
table{
border-collapse: collapse;
font-family: calibri;
font-size: 200%;
</style>
</head>
<body>
<table border>
<tr>
<th>Emp ID</th>
<th>Emap Name</th>
<th>Emp Salary</th<
</tr>
<tr>
<td>1</td>
<td>Mahesh</td>
<td>Rs.50,000</td>
</tr>
<tr>
<td>2</td>
<td>Kumar</td>
<td>Rs.60,000</td>
</tr>
</table>
</body>
</html>
Example:
a) Apply orange background color to body tag
b) Apply round table borders to Employee table
Columns: Emp ID, Emp Name, Emp Salary
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border-radius: 10px;
</style>
</head>
<table>
<tr>
<th>Emp ID</th>
<th>Emap Name</th>
<th>Emp Salary</th>
</tr>
<tr>
<td>1</td>
<td>Mahesh</td>
<td>Rs.50,000</td>
</tr>
<tr>
<td>2</td>
<td>Kumar</td>
<td>Rs.60,000</td>
</tr>
</table>
</body>
</html>
Interview Questions:
Task1:
Task2:
Example:
Apply dotted table border to Employee table.
Columns: Emp ID, Emp Name, Emp Salary
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border-style: dotted;
}
</style>
</head>
<body>
<table>
<tr>
</tr>
<tr>
<td> 1 </td>
<td> Anitha </td>
</tr>
<tr>
<td> 2 </td>
</tr>
<tr>
<td> 3 </td>
</tr>
</table>
</body>
</html>
Example:
Apply dashed border to Employee table
Columns: Emp ID, Emp Name, Emp Salary
<!DOCTYPE html>
<html>
<head>
<style>
table,th,td{
border-style: dashed;
</style>
</head>
<body>
<table>
<tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 2 </td>
</tr>
<tr>
<td> 3 </td>
<td> Ganga </td>
</tr>
</table>
</body>
</html>
HTML Table Borders: Groove Table borders
Groove border means: Outer thick border and inner thin border
To get groove border to a table, we have to use border-style: groove;
Code:
<head>
<style>
table, th, td {
border-style: groove;
}
</style>
</head>
Example:
Apply groove border style to Employee table
Columns: Emp ID, Emp Name and Emp Salary
<!DOCTYPE html>
<html>
<head>
<style>
table,th,td{
border-style: groove;
</style>
</head>
<body>
<table>
<tr>
<th> Emp ID </th>
<td> 1 </td>
</tr>
<tr>
<td> 2 </td>
<tr>
<td> 3 </td>
</tr>
</table>
</body>
</html>
Example:
Apply inset border style to Employee table
Columns: Emp ID, Emp Name, Emp Salary
<!DOCTYPE html>
<html>
<head>
<title> Inset Table Border </title>
<style>
table,th,td{
border-style: inset;
}
</style>
</head>
<body>
<table>
<tr>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 2 </td>
</tr>
<tr>
<td> 3 </td>
</tr>
</table>
</body>
</html>
HTML tables can have different sizes for each row and column.
The following are the sample sizes of rows and columns in a table.
Sample Table:
Code:
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table style=”width: 100%;”>
Remaining code is as it is………
Complete Code
<head>
<style>
table, th, td {
</style>
</head>
<body>
<table style="width: 100%">
<tr>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 2 </td>
<tr>
<td> 3 </td>
</tr>
</table>
</body>
</html>
HTML Table Sizes: Set the first column to 70% of table width
Sample Table:
Code to set the first column to 70% of the table width (use same Employee table):
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<tr>
<th style="width: 70%"> Emp ID </th>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 2 </td>
<tr>
<td> 3 </td>
</tr>
</table>
</body>
</html>
HTML Table Sizes: Set the height of the second row to 200 pixels
Sample Table:
Code:
<head>
<style>
table, th, td {
border-collapse: collapse;
}
</style>
</head>
<body>
</tr>
<tr style="height:200px">
<td> 1 </td>
<tr>
<td> 2 </td>
</tr>
<tr>
<td> 3 </td>
</table>
</body>
</html>
Homework:
Interview Questions:
a) How to apply dotted border to a table?
b) Apply dashed border to Customer table (Columns are: Customer ID, Name, Address)
c) Display Groove style of border to Employee table
d) Write the syntax to apply inset border to a table
e) Write the syntax to display 70% width for first column of Student table (Columns are: Student ID, Name,
Course)
f) How to give 100% wide table width?
g) How to increase the row size in a table?
Task1:
a) Apply Groove style of border to college table (Columns are: College ID, Name, Address)
b) Apply 50% width to first column
c) Apply 200 pixels height to second row
HTML Tables: Cell Padding & Cell Spacing
Ex:
th, td {
padding: 15px;
}
Sample Code:
<head>
<style>
table, th, td {
th, td {
padding: 15px;
</style>
</head>
Example:
a) Apply orange background to body tag
b) Put <h1> tag with “Employees Table” heading
c) Create Employee Table
Columns: Emp ID, Emp Name, Emp Salary
d) To Employee table, give 1pixel solid black border and 15 pixels of Cell padding
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
th, td{
padding: 30px;
</style>
</head>
<body style="background-color: orange;">
<table border>
<tr>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 2 </td>
</tr>
</table>
</body>
</html>
Cell Spacing:
Example:
a) Apply orange background to body tag
b) Put <h1> tag with “Employees Table” heading
c) Create Employee Table
Columns: Emp ID, Emp Name, Emp Salary
d) To Employee table, give 1pixel solid black border and 30 pixels of Cell Spacing
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
table{
border-spacing: 30px;
</style>
</head>
<table border>
<tr>
</tr>
<tr>
<td> 1 </td>
</tr>
<tr>
<td> 2 </td>
</tr>
</table>
</body>
</html>
Homework
Interview Questions:
Task1:
Task2:
Name Age
Ravi Kumar 21
Raj Kumari 20
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border-collapse: collapse;
</style>
</head>
<body>
<table style="width:50%">
<tr>
<th colspan="2">Name</th>
<th>Age</th>
</tr>
<tr>
<td>Ravi</td>
<td>Kumar</td>
<td>21</td>
</tr>
<tr>
<td>Raj</td>
<td>Kumari</td>
<td>20</td>
</tr>
</table>
</body>
</html>
Example2:
Time Table
Mon Tue Wed Thu Fri Sat
C# ASP SQL Server MVC .Net Core Angular
Angular .Net Core MVC SQL Server ASP C#
C# ASP SQL Server MVC .Net Core Angular
Angular .Net Core MVC SQL Server ASP C#
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border-collapse: collapse;
text-align: center;
</style>
</head>
<body>
<tr>
</tr>
<tr>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td>C#</td>
<td>ASP</td>
<td>SQL Server</td>
<td>MVC</td>
<td>.Net Core</td>
<td>Angular</td>
</tr>
<tr>
<td>Angular</td>
<td>.Net Core</td>
<td>MVC</td>
<td>SQL Server</td>
<td>ASP</td>
<td>C#</td>
</tr>
<tr>
<td>C#</td>
<td>ASP</td>
<td>SQL Server</td>
<td>MVC</td>
<td>.Net Core</td>
<td>Angular</td>
</tr>
<tr>
<td>Angular</td>
<td>.Net Core</td>
<td>MVC</td>
<td>SQL Server</td>
<td>ASP</td>
<td>C#</td>
</tr>
</table>
</body>
</html>
Example3:
Time Table
Mon Tue Wed Thu Fri Sat
C# ASP SQL Server MVC .Net Core Angular
Angular .Net Core MVC SQL Server ASP C#
Lunch Break
C# ASP SQL Server MVC .Net Core Angular
Angular .Net Core MVC SQL Server ASP C#
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
</style>
</head>
<body>
<tr>
</tr>
<tr>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td>C#</td>
<td>ASP</td>
<td>SQL Server</td>
<td>MVC</td>
<td>.Net Core</td>
<td>Angular</td>
</tr>
<tr>
<td>Angular</td>
<td>.Net Core</td>
<td>MVC</td>
<td>SQL Server</td>
<td>ASP</td>
<td>C#</td>
</tr>
<tr>
</tr>
<tr>
<td>C#</td>
<td>ASP</td>
<td>SQL Server</td>
<td>MVC</td>
<td>.Net Core</td>
<td>Angular</td>
</tr>
<tr>
<td>Angular</td>
<td>.Net Core</td>
<td>MVC</td>
<td>SQL Server</td>
<td>ASP</td>
<td>C#</td>
</tr>
</table>
</body>
</html>
Homework:
Interview Questions:
<!DOCTYPE html>
<html>
<head>
<style>
border-collapse: collapse;
text-align: center;
</style>
</head>
<table style="width:50%">
<tr>
</tr>
<tr>
<th>Sub1</th>
<th>Sub2</th>
<th>Sub3</th>
</tr>
<tr>
<td>1</td>
<td>Ravi</td>
<td>70</td>
<td>80</td>
<td>90</td>
</tr>
<tr>
<td>1</td>
<td>Raj</td>
<td>60</td>
<td>70</td>
<td>80</td>
</tr>
</table>
</body>
</html>
Room Tariff
Room Deluxe Executive
Type AC Non-AC AC Non-AC
2000 1000 3000 2000
<!DOCTYPE html>
<html>
<head>
<style>
border-collapse: collapse;
text-align: center;
</style>
</head>
<body>
<table style="width:50%">
<tr>
</tr>
<tr>
</tr>
<tr>
<th>AC</th>
<th>Non-AC</th>
<th>AC</th>
<th>Non-AC</th>
</tr>
<tr>
<td>2000</td>
<td>1000</td>
<td>3000</td>
<td>2000</td>
</tr>
</table>
</body>
</html>
HTML Lists
Unordered Lists
Unordered lists are used to present a collection of related items when sequence of items is not
important.
Ex:
List of Fruits
Apple
Banana
Cherry
Grapes
Mangoes
Watermelon
<body>
<ul>
</ul>
</body>
Here, “ul” stands for unordered list and “li” stands for list item.
Ex:
<body>
<ul>
</ul>
</body>
Example:
<!DOCTYPE html>
<html>
<head>
<head>
<body style="background:orange;">
<ul>
</ul>
</body>
</html>
Homework
Interview Questions:
a) When we will go for Colspan and when we will go for rowspan in a table?
b) In a table, maximum how many colspans and rowspans can be created?
c) What is HTML list?
d) How many types of lists are available in HTML? And what are they?
e) When we will go for unordered lists?
f) When we will go for ordered lists?
If an unordered list is existed in another unordered list then it is called as Nested unordered
list
Syntax of Nested unordered list:
<body>
<ul>
<li>Item1</li>
<ul>
<li>Item1</li>
<li>Item2</li>
</ul>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</body>
Example:
Apples
o Green Apples
o Red Apples
Grapes
o Light green grapes
o Black grapes
Mangoes
o Green Mangoes
o Yellow Mangoes
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ul>
<li>Apples</li>
<ul>
<li>Green Apples</li>
<li>Red Apples</li>
</ul>
<li>Grapes</li>
<ul>
<li>Black grapes</li>
</ul>
<li>Mangoes</li>
<ul>
<li>green mangoes</li>
<li>yellow mangoes</li>
</ul>
</ul>
</body>
</html>
Output:
Ordered Lists
Ordered lists are used to display a list of items in a specific sequence which are marked with
numbers or letters.
By default, ordered list will be displayed with numbers.
Ordered lists can be displayed with:
o Numbers
o Uppercase letters
o Lowercase letters
o Uppercase Roman Numbers
o Lowercase Roman Numbers
<body>
<ol>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ol>
</body>
Example1:
1. C#
2. ASP
3. SQL Server
4. MVC
5. .Net Core
6. HTML
7. CSS
8. Javascript
9. Bootstrap
10. Typescript
11. Angular
Complete Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2> .Net Full stack </h2>
<ol>
<li>C#</li>
<li>ASP</li>
<li>SQL Server</li>
<li>MVC</li>
<li>.Net Core</li>
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>Bootstrap</li>
<li>Typescript</li>
<li>Angular</li>
</ol>
</body>
</html>
Output:
Syntax of ordered list with Uppercase letters:
<body>
<ol type=”A”>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ol>
</body>
Example:
A. C#
B. ASP
C. SQL Server
D. MVC
E. .Net Core
F. HTML
G. CSS
H. Javascript
I. Bootstrap
J. Typescript
K. Angular
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol type="A">
<li>C#</li>
<li>ASP</li>
<li>SQL Server</li>
<li>MVC</li>
<li>.Net Core</li>
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>Bootstrap</li>
<li>Typescript</li>
<li>Angular</li>
</ol>
</body>
</html>
Output:
<body>
<ol type=”a”>
<li> Item1</li>
<li> Item2</li>
<li> Item3</li>
<li> Item4</li>
</ol>
</body>
Example:
a. C#
b. ASP
c. SQL Server
d. MVC
e. .Net Core
f. HTML
g. CSS
h. Javascript
i. Bootstrap
j. Typescript
k. Angular
Compete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol type="a">
<li>C#</li>
<li>ASP</li>
<li>SQL Server</li>
<li>MVC</li>
<li>.Net Core</li>
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>Bootstrap</li>
<li>Typescript</li>
<li>Angular</li>
</ol>
</body>
</html>
Output:
<body>
<ol type=”I”>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ol>
</body>
Example:
I. C#
II. ASP
III. SQL Server
IV. MVC
V. .Net Core
VI. HTML
VII. CSS
VIII. Javascript
IX. Bootstrap
X. Typescript
XI. Angular
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol type="I">
<li>C#</li>
<li>ASP</li>
<li>SQL Server</li>
<li>MVC</li>
<li>.Net Core</li>
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>Bootstrap</li>
<li>Typescript</li>
<li>Angular</li>
</ol>
</body>
</html>
Output:
Syntax of ordered list with lowercase roman numbers:
<body>
<ol type=”i”>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ol>
</body>
Example:
i. C#
ii. ASP
iii. SQL Server
iv. MVC
v. .Net Core
vi. HTML
vii. CSS
viii. Javascript
ix. Bootstrap
x. Typescript
xi. Angular
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol type="i">
<li>C#</li>
<li>ASP</li>
<li>SQL Server</li>
<li>MVC</li>
<li>.Net Core</li>
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>Bootstrap</li>
<li>Typescript</li>
<li>Angular</li>
</ol>
</body>
</html>
Output:
“start” attribute of <ol> tag:
Complete Code
<!DOCTYPE html>
<html>
<head>
<title> ordered list start with 5th number </title>
</head>
<body>
<h2> .Net Full stack </h2>
<ol start="5">
<li>C#</li>
<li>ASP</li>
<li>SQL Server</li>
<li>MVC</li>
<li>.Net Core</li>
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>Bootstrap</li>
<li>Typescript</li>
<li>Angular</li>
</ol>
</body>
</html>
Output:
Homework
Interview Questions:
a) What is the fundamental difference between unordered list and ordered list?
b) Write the syntax of unordered list and ordered list
c) Write the code for displaying Nested unordered list
d) Display Numbered ordered list
e) Explain about “type” attribute of <ol> tag
f) How to start with desired number in <ol> tag?
Task3: Create any two ordered list with lowercase letters sequence
Task4: Create any two ordered lists with Uppercase roman numbers sequence
Task5: Create any two ordered lists with lowercase roman numbers sequence
If one ordered list is placed in another ordered list then it is called as Nested ordered list.
Syntax:
<body>
<ol>
<li>Item1</li>
<ol>
<li>Item1</li>
<li>Item2</li>
</ol>
<li>Item2</li>
<li>Item3</li>
</ol>
</body>
Example:
1. Item1
1. Item1
2. Item2
2. Item2
3.Item3
Complete Code
<!DOCTYPE html>
<html>
<head>
<title> Nested Ordered list </title>
</head>
<body>
<ol>
<li>Item1</li>
<ol>
<li>Item1</li>
<li>Item2</li>
</ol>
<li>Item2</li>
<li>Item3</li>
</ol>
</body>
</html>
Output:
Example2:
1. Apples
a. Green Apples
b. Red Apples
2. Grapes
a. Light Green Grapes
b. Black Grapes
3. Mangoes
a. Green Mangoes
b. Yellow Mangoes
Complete Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ol>
<li>Apples</li>
<ol type="a">
<li>Green Apples</li>
<li>Red Apples</li>
</ol>
<li>Grapes</li>
<ol type="a">
<li>Black Grapes</li>
</ol>
<li>Mangoes</li>
<ol type="a">
<li>Green Mangoes</li>
<li>Yellow Mangoes</li>
</ol>
</ol>
</body>
</html>
Output:
HTML Forms
To collect the user input, the following input types (or input controls) will be used:
o Label
o Text box
o Button
o Checkbox
o Radio button etc…
Label:
Ex:
In the above example, “First Name” is label. By seeing this label, user will enter “First name” in the
text box.
Textbox:
Textbox is used to take single-line text such as First name, middle name, last name, email id etc….
Syntax of Label:
Syntax of Textbox:
<input type=”text”>
Ex:
<label>First name</label>
<input type=”text”>
<input type=”text”>
<label>Last Name</label>
<input type=”text”>
Button
Button is used to perform the action or operation such as submit operation, insert operation, update
operation, display operation, delete operation etc…
Syntax of button:
<input type=”submit”>
Ex:
Complete Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<label>First Name</label>
<input type="text"><br><br>
<label>Last Name</label>
<input type="text"><br><br>
<label>Phone Number</label>
<input type="text"><br><br>
<label>Email ID</label>
<input type="text"><br><br>
<label>Address</label>
<input type="text"><br><br>
<input type="submit">
</form>
</body>
</html>
Output:
Example2:
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<label>Emp ID</label>
<input type="text"><br><br>
<label>Emp Name</label>
<input type="text"><br><br>
<label>Emp Dept</label>
<input type="text"><br><br>
<label>Emp Salary</label>
<input type="text"><br><br>
<input type="submit">
</form>
</body>
</html>
Output:
Homework
Interview Questions:
Task2: Create any three HTML forms like Student Details form, Customer details form, College
details form
Textarea:
Example:
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<input type="text"><br><br>
<label> Emp Name </label>
<input type="text"><br><br>
<input type="text"><br><br>
<input type="text"><br><br>
<input type="submit">
</form>
</body>
</html>
Output:
Password Field
<input type=”password”>
Example:
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<input type="text"><br><br>
<input type="password"><br><br>
<input type="submit">
</form>
</body>
</html>
Output:
Homework
Interview Questions:
Task2: Create any two login forms. Ex: Admin login form, user login form, student login form
Reset Button
Reset button is used to reset the initial values to the input fields. (OR) Reset button is used to
make all input fields empty.
Syntax of reset button:
<input type=”reset”>
Example:
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<input type="text"><br><br>
<input type="text"><br><br>
<input type="text"><br><br>
<input type="submit">
<input type="reset">
</form>
</body>
</html>
Output:
Radio Button
Radio button allows the user to select ONLY ONE option from the given options.
Ex:
Ex:
<input type=”radio” name=”gender”>Male <br>
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
<label>First Name</label>
<input type="text"><br><br>
<label>Last Name</label>
<input type="text"><br><br>
<label>Gender</label><br>
<label>Phone Number</label>
<input type="text"><br><br>
<label>Email ID</label>
<input type="email"><br><br>
<input type="submit">
</form>
</body>
</html>
Output:
Homework
Interview Questions:
Task1: Create any two forms with submit and reset buttons
Checkboxes allow the user to select ONE or MORE options from given options.
Ex:
Syntax of Checkbox:
<input type=”checkbox”>
Ex:
<input type=”checkbox”>
<label> Telugu </label>
<input type=”checkbox”>
<label> English </label>
<input type=”checkbox”>
<label> Hindi </label>
<html>
<head>
<title> Checkbox Example </title>
</head>
<body>
<input type="checkbox">
<label> English </label><br>
<input type="checkbox">
<label> Hindi </label><br>
<input type="SUBMIT">
</form>
</body>
</html>
Output:
Drop-down list
Drop-down list allows the user to choose one value from a list.
Ex:
Complete Code:
<!DOCTYPE html>
<html>
<head>
<title> Drop down list example </title>
</head>
<body>
<br>
<input type="submit”>
</form>
</body>
</html>
Output:
Date input
Complete Code:
<!DOCTYPE html>
<html>
<head>
<input type="date"><br>
<input type="submit">
</form>
</body>
</html>
Output
Homework
Interview Questions
a) What is Checkbox?
b) What is the difference between radio button and checkbox?
c) How to give date input in HTML form?
d) Write the syntaxes for checkbox, radio button with two examples
e) Write the syntax for date input with two examples
Task1: Design any two forms with labels, text boxes, radio buttons, checkboxes
Task2: Desing any one form with date input
File input
In HTML, file type of input allows the user to select one or more files.
Example for selecting one file:
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h3> Person Details </h3>
<form>
<input type="text"><br><br>
<input type="text"><br><br>
<input type="file"><br><br>
<input type="submit">
</form>
</body>
</html>
Output
Like this we can select any one file.
Example:
Syntax to select multiple files:
Complete Code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="text"><br><br>
<input type="text"><br><br>
<input type="submit">
</form>
</body>
</html>
Output
Like this we can select multiple files.
Field set is a collection of Fields (OR) Set of Fields (OR) Group of related elements
<fieldset> tag is used to create Field set
Legend is a caption of Field set (OR) heading of field set
<legend> tag is used to give legend to the Field set
Ex:
Tomorrow, we will see coding part of fieldset and legend.
Homework
Interview Questions:
a) How to upload one file in HTML page and write the syntax with two examples
b) How to upload multiple files in HTML page and write the syntax with two examples
c) Explain about Field set and legend
<input type="submit">
</fieldset>
</form>
</body>
</html>
Output:
Div tag
Article tag
The <section> tag is used to group related content. Such as group of chapters, group
of topics etc..
The advantage of <section> tag is organizing the content into sections and
subsections, making it easier for both developers and browsers to understand the
structure of the document.
Syntax of <section> tag:
<section>
Content goes here…
</section>
Note: we can use <hr> tag to have one horizontal line after every section.
Ex:
HTML Content
CSS Content
Javascript Content
Complete Code
<!DOCTYPE html>
<html>
<head>
<title> section tag example </title>
</head>
<body>
<section>
HTML CONTENT
</section>
<hr>
<section>
CSS CONTENT
</section>
<hr>
<section>
JAVASCRIPT CONTENT
</section>
<hr>
</body>
</html>
Output:
Homework
Interview Questions:
a) Explain about <section> tag and write two examples
Task: Design any two HTML pages with <section> tag