HTML Notes
HTML Notes
Introduction to HTML
What is HTML?
HTML (Hypertext Markup Language) is the standard language used to create web pages. It uses
tags to structure content, such as text, images, and links, on the web.
Uses of HTML
7. <a>: Hyperlink.
8. <img>: Image.
9. <ul> and <ol>: Unordered and ordered lists.
10. <li>: List item.
11. <div>: Division or section.
12. <span>: Inline section.
13. <table>, <tr>, <td>, <th>: Table and its components.
HTML Attributes
Attributes provide additional information about elements. They are included in the opening tag.
Common HTML Attributes
Example
<!DOCTYPE html>
<html>
<head>
<title>Simple Example</title>
</head>
<body>
<h1>Welcome to My Page</h1>
<p>This is a simple paragraph.</p>
<a href="https://www.example.com">Visit Example</a>
<img src="image.jpg" alt="Description of image">
</body>
</html>>
This example shows basic HTML tags and attributes in use.
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my first HTML document.</p>
</body>
</html>
To view, Double-click the saved index.html file. It will open in your default web browser (e.g., Chrome,
Firefox, Edge).
Comments in HTML
The comment tag is used to insert a comment in the HTML source code. Browser will not display
comment. We can use comment to explain tag/code. Which can help us when we edit the source code
later.
Comment tag requires ! after opening bracket, but not before the closing bracket.
<html>
<head> <title>Comments</title> </head>
<body>
3
HOPE COMPUTER INSTITUTE, Rajbiraj
COMPUTER
</body>
</html>
Paragraph
Paragraphs are defined with the <P> tags. It denotes a paragraph. HTML automatically adds an extra
blank line before and after a paragraph.
By default, the text is left-aligned. You can use an attribute ALIGN to change the alignment of the
text.
For example,
Heading
The heading tag is used to create heading in documents. HTML supports 6 different levels of
headings. The highest-level header format is <H1> and the lowest level is <H6>.
For example,
<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>
By default, the headings are left-aligned. You can use an attribute ALIGN to change the alignment of
the headings
For example,
Line Breaks
A tag <BR> can be used to end line. <BR> is a singular tag and has no closing tag.
4
HOPE COMPUTER INSTITUTE, Rajbiraj
For Example,
This is
a paragraph
with line breaks
Horizontal Rule
The <HR> Horizontal rule tag allows adding horizontal line across the webpage. It is a singular tag.
Example:
<HTML>
<HEAD>
<TITLE>
Inserting horizontal rule
</TITLE>
</HEAD>
<BODY>
<H1> Hope Computer Institute </H1> <BR>
<B> Deal with best Quality Education </B> <BR>
<I> Rajbiraj-5, Near Sanima Bank, Saptari, Nepal BR>
<P>
<B> <U> Computer : </B> </U> It is an advance electronic device, through which user can do any
types of work with maximum 100% accuracy and very fast speed. It can do any work within a second.
<P>
<HR>
IT is an EDP (Electronic Data Processing) system by which computer can process all given instructions
according to requirements.
</BODY>
</HTML>
Text Formatting:
The processing of changing the appearance of HTML Document is known as text formatting or Text
element formatting. The web browser only identified the single space between the words or text for
giving line break, paragraph break, formatting tags are used.
• Physical tags
• Logical tags
Physical Tags
Physical Tags affect the appearance of the text. These tags are used to specify the exact way in which
text/characters are to be formatted and displayed in the browser.
5
HOPE COMPUTER INSTITUTE, Rajbiraj
Logical tags are inbuilt commands in the browsers to render certain features of the content in a specific
style. Browser use these logical tags to display feature like definitions, citations and computer codes in a
specific style.
For example,
<html>
<head> <title> Demonstration of text formatting tags </head> </title>
<body>
<b> This text is bold</b>
<br> <Strong> This text is strong </Strong>
<br> <big> This text is big </big>
<br> <em> This text is emphasized </em>
<br> <i> This text is Italic </i>
<br> <small> This text is small </small>
<br> subscript H <sub> 2 </sub> SO <sub> 4 </sub> = Sulphuric Acid
<br> superscript (a+b) <sup> 2 </sup> = a<sup>2</sup> +2ab +b<sup>2</sup>
<br> <code> Computer code </code>
<br> <kbd> Keyboard input </kbd>
<br> <samp> Sample text </samp>
<br> <var> Computer Variable </var>
</body>
</html>
6
HOPE COMPUTER INSTITUTE, Rajbiraj
Font Tags
The <font> tag was used in HTML to specify the font face, font size, and color of text. It has attributes
like SIZE, COLOR AND FACE.
The list of colors and their associated hexadecimal RGB values are:
Color Name Hexadecimal RGB Color Name Hexadecimal RGB
Value Value
Black #000000 Silver #C0C0C0
White #FFFFFF Gray #808080
Red #FF0000 Maroon #800000
Lime #00FF00 Olive #808000
Blue #0000FF Green #008000
Yellow #FFFF00 Purple #800080
Cyan / Aqua #00FFFF Teal #008080
Magenta / Fuchsia #FF00FF Navy #000080
Creating Lists
HTML supports several types of list elements that cab be included within the <BODY> tags of the
documents. The different types of lists that can be created in HTML are :
• Ordered list
• Unordered list
• Definition list
1. Ordered List or Numbered list
In HTML, all the list items in an ordered list are marked with numbers by default instead of
bullets. An HTML ordered list starts with the <ol> tag and ends with the </ol> tag. The list items
start with the <li> tag and end with </li> tag.
7
HOPE COMPUTER INSTITUTE, Rajbiraj
Syntax
<ol>List of Items</ol>
Instead of numbers, you can mark your list items with the alphabet: A, B, C or a,b,c, or roman
numerals: i, ii, iii, etc. You can do this by using the <ol> tag type attribute
To mark the list items with letters A, B, C, etc., you must specify A as the type attribute’s value in
the <ol> tag.
Here is an example
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<h2>List of Fruits</h2>
<ol type="A">
<li>Apple</li>
<li>Mango</li>
<li>Banana</li>
</ol>
</body>
</html>
Write a HTML code to show the use of Roman numerals to list the items.
2. Unordered List or Bulleted List
8
HOPE COMPUTER INSTITUTE, Rajbiraj
In HTML unordered list, the list items have no specific order or sequence. An unordered list is also called
a Bulleted list. It begins with the <ul> tag and and closes with a </ul> tag. The list items begin with the
<li> tag and end with </li> tag.
Syntax
<ul>List of Items</ul>
<html>
<head> <title>HTML Unordered List</title> </head>
<body>
<h2>List of Fruits</h2>
<ul>
<li>Apple</li>
<li>Mango</li>
<li>Banana</li>
<li>Grapes</li>
<li>Orange</li>
</ul>
</body>
</html>
In an HTML Description list or Definition List, the list items are listed like a dictionary or encyclopedia.
The tags used for creating a definition list are:
<html>
<head> <title>HTML Description List</title> </head>
<body>
<dl>
<dt><b>Apple</b></dt>
<dd>A red colored fruit</dd>
<dt><b>Honda</b></dt>
<dd>A brand of a car</dd>
<dt><b>Spinach</b></dt>
<dd>A green leafy vegetable</dd>
</dl>
</body>
9
HOPE COMPUTER INSTITUTE, Rajbiraj
Attribute Explanation
width provides the width or breadth of a marquee. For
example width="10" or width="20%"
height provides the height or length of a marquee. For
example height="20" or height="30%"
direction provides the direction or way in which your marquee will allow you to scroll.
The value of this attribute can be: left, right, up, or down
scrolldelay provides a feature whose value will be used for delaying each jump.
scrollamount provides value for speeding the marquee feature
behavior provides the scrolling type in a marquee. That scrolling can be like sliding,
scrolling, or alternate
loop provides how many times the marquee will loop
bgcolor provides a background color where the value will be either the name of the
color or the hexadecimal color code.
vspace provides a vertical space, and its value can be
like vspace="20" or vspace="30%"
hspace provides a horizontal space, and its value can be
like hspace="20" or hspace="30%"
Scroll Up
<marquee width="60%" direction="up" height="100px">
This is a sample scrolling text that has scrolls in the upper direction.
</marquee>
Scroll Down
<marquee width="60%" direction="down" height="100px">
</marquee>
This is a sample scrolling text that has scrolls texts to the right.
</marquee>
10
HOPE COMPUTER INSTITUTE, Rajbiraj
Scrolling Speed
<marquee behavior="scroll" direction="up" scrollamount="1">Slow Scrolling</marquee>
<marquee behavior="scroll" direction="right" scrollamount="12">Little Fast Scrolling</marquee>
<marquee behavior="scroll" direction="left" scrollamount="20">Fast Scrolling</marquee>
<marquee behavior="scroll" direction="right" scrollamount="50">Very Fast Scrolling</marquee>
Creating Links
Link are the most important part of the World Wide Web. HTML links, or hyperlinks, connect
web pages and are created using the `<a>` tag with the `href` attribute. Links can be text,
images, or other elements. Users can click on links to navigate between different pages.
These links are provided by URLs (Uniform Resource Locator), which give the location and
filename of a document.
Link Types
There are three major types of links:
• Internal Links
• Local Links
• External Links
11
HOPE COMPUTER INSTITUTE, Rajbiraj
1. Internal link is a hyperlink that points to another location within the same webpage or
website. It allows users to navigate to different sections of a page without leaving the current
page.
Links within a same page is created in two steps:
<html>
<head> <title> Using Hyperlink </head> </title>
<Body>
Local Hyperlink
<a name =”Top”> </a>
<a href=”#Top”> Go To Top </a>
Internal Hyperlink
<a href=https://hopecomputercenter.com.np> Hope Computer Center </a>
</BODY>
</html>
12
HOPE COMPUTER INSTITUTE, Rajbiraj
Link Targets
By default, links open in the current window. If you want the link to open in another window, you
need to add a target.
For Example:
<A HREF="http://www.nepal.gov.np" target="_blank">Nepal</A>
This will open the page in a new window.
The different values of attributes target are:
Value Explanation
_blank It loads the page in a new window.
+
_self It loads the page in the current window
Inserting Images
Graphics, pictures, and images can also be inserted in an HTML document to make it more
interesting and attractive. There are number of formats supported by most web browsers. The
most widely used amongst them are the JPEG and GIF format.
Inserting an image on the Webpage is implemented by using tag <IMG>. The tag <IMG> can
have attributes like: SRC, ALIGN, BORDER, HEIGHT, WIDTH, ALT, HSPACE, and VSPACE.
13
HOPE COMPUTER INSTITUTE, Rajbiraj
Note:
To insert the image, the image and the webpage must be in the same location (i.e. same folder)
otherwise, you have to provide detailed link.
Setting HEIGHT and WIDTH attributes allow the browser to reserve space for the image on the
webpage.
Example:
<HTML>
<HEAD> <TITLE> Inserting Image </TITLE> </HEAD>
<BODY>
<IMG SRC="computer.jpg" HEIGHT="200" WIDTH="300" border=1>
<! - Comment => some of the options, we use, may not be supported on other browsers. As
most of the servers use "Microsoft Internet Explorer", on "Mozilla Firefox" will work around
this browser.
</BODY>
Tag Description
<TABLE> It is the main tag. All other tags are placed within this tag.
<TR> Table Row. It defines a horizontal row or cell. It is used to add rows to the
table.
<TD> Table Data. It specifies the individual block or cell in the table. It is used to add
column to the table.
<TH> Table Header. It defines a table header cell and emphasizes the data in
boldface.
<CAPTION> It specifies the caption (heading/title) to the table. The default position is
centered at the top of the table.
14
HOPE COMPUTER INSTITUTE, Rajbiraj
Attributes Explanation
ALIGN Specify the alignment of the table. Its value can be LEFT, CENTER, and
RIGHT.
BACKGROUND To insert the image at the background of the table.
BGCOLOR Specify the background color of the table
BORDER Specify the thickness of the border. To specify the table border, specify
BORDER="0".
BORDERCOLOR Specify the color of the table border.
CELLPADDING Specify the distance between the cell and the content.
CELLSPACING Specify the space between cells.
VALIGN Specify the alignment of the content in the cells. Its value can be TOP or
BOTTOM.
WIDTH Specify the minimum width of the table. The values can be in pixels or in
percentage of the window size.
The following attributes can be added to <TR>, <TD> and <TH>
Attributes Explanation
ALIGN Specify the alignment of the cell. Its value can be LEFT, CENTER, and
RIGHT.
BACKGROUND To insert the image at the background of the cell.
BGCOLOR Specify the background color of the cell.
BORDERCOLOR Specify the color of the cell border.
VALIGN Specify the alignment of the content in the cells. Its value can be TOP,
MIDDLE or BOTTOM.
WIDTH Specify the minimum width of the cell. The values can be in pixels or in
percentage of the table width.
HEIGHT Specify the minimum height of the cell. The values can be in pixels or in
percentage of table height.
Note:
1. The table properties are set for the entire table.
2. If a certain property is set for a single cell, it will have higher priority that the setting for the
table as a whole.
15
HOPE COMPUTER INSTITUTE, Rajbiraj
<HTML>
<HEAD><TITLE> Creating Table </TITLE> </HEAD>
<BODY>
<TABLE BORDER="1">
<TR>
<TH> Column 1 Header </TH> <TH> Column 2 Header </TH>
</TR> .
<TR>
<TD> Row 1 - Col 1 </TD> <TD> Row 1 - Col 2 </TD>
</TR>
<TR>
<TD> Row 2 - Col 1 </TD> <TD> Row 2 - Col 2 </TD>
</TR>
</TABLE>
</BODY>
</HTML>
<html>
<head> <title> Merging column </title> </head> <body>
<table border="1">
<tr> <td colspan="3"> Telephone numbers </td>
</tr>
<tr>
<td>100</td> <td>101</td> <td>103</td>
</tr>
</table>
</body>
</html>
16
HOPE COMPUTER INSTITUTE, Rajbiraj
<html>
<head> <title> Merging Rows </title> </head>
<table border="1">
<tr>
<td rowspan="3">Telephone numbers </td>
<td>100</td>
</tr>
<tr>
<td>101</td>
</tr>
<tr>
<td>103</td>
</tr>
</table>
</body>
</html>
17
HOPE COMPUTER INSTITUTE, Rajbiraj
<option value="usa">USA</option>
<option value="australia">Australia</option>
</select><br><br>
<label for="message">Message:</label><br>
<textarea name="message" id="message" cols="30" rows="4"></textarea><br><br>
<input type="checkbox" name="newsletter" id="newsletter">
<label for="newsletter">Subscribe?</label><br><br>
<input type="submit" value="Submit">
</form>
The HTML form elements that can be specified as attributes to the <input>tags are:
Elements Type Description Syntax
Text A text field <input name="text1"
type="text" size="25"
18
HOPE COMPUTER INSTITUTE, Rajbiraj
maxlenght="50"
value="Nepal computer">
<input name="pass"
A password test field in which each keystroke
Password type="password" size="12"
appears as an asterisk (*).
maxlenght="10">
<input name="hobby"
Checkbox allows the users to select more
Checkbox type="checkbox"
than one option.
value="football" checked>
<textarea name="message"
TEXTAREA A multi line text entry field. cols="30"rows="10">default
text</textarea>
<select name="choice"
size="5" multiple> <option
Select (Drop
The two following examples are<select></ value="1" selected>item 1
Down List, List
select> elements, where the attributes are set <option value="2">item 2
box)
differently. <option value="2">item
3</select>
<input name="h_text"
A field that may contain a value but is not
Hidden type="hidden"
displayed within a form.
value="anything">
19
HOPE COMPUTER INSTITUTE, Rajbiraj
Create an HTML Form to Input the Basic Details of a Student for new admission.
<HTML>
<HEAD> <TITLE> Form Elements </TITLE> </HEAD>
<BODY>
<H3> Text Box </H3>
<form>
First name: <input type="text" name="firstname" /><br>
Last name: <input type="text" name="lastname">
</form>
<H3> Text Box for Password </H3>
<form>
Password: <input type="password" name="pwd" />
</form>
<H3> Radio Button </H3>
<form>
<input type="radio" name=" 'sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</form>
<H3> Checkbox </H3>
<form>
<input type="checkbox" name="aubject" value="Computer" />Computer science
<br>
<input type="checkbox" name="subject" value="Hotel Management" />Hotel Management
</form>
<H3> Submit button </H3>
<form name="input" action="html_form_action.asp" method="get">
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
<H3> Drop down menu </H3>
<form action="">
<select name="Stream">
<option value=”Science”>Science</option>
<option value=”Management”>Management</option>
<option value=”Humanities”> Humanities </option>
<option value=”Education”> Education </option>
20
HOPE COMPUTER INSTITUTE, Rajbiraj
</select>
</form>
</body>
</html>
21
HOPE COMPUTER INSTITUTE, Rajbiraj
22
HOPE COMPUTER INSTITUTE, Rajbiraj
</p>
</fieldset>
</form>
</body>
</html>
23
HOPE COMPUTER INSTITUTE, Rajbiraj
<html>
<body>
<form>
<div class="container">
<Right> <h1> Student Registeration Form</h1> </center>
<hr>
<label> Firstname </label>
<input type="text" name="firstname" placeholder= "Firstname" size="35" required
/><br></br>
<label> Middlename: </label>
<input type="text" name="middlename" placeholder="Middlename" size="15" required
/><br></br>
<label> Lastname: </label>
<input type="text" name="lastname" placeholder="Lastname" size="15"required
/><br></br>
<div>
<label>
Course :
</label>
<select>
<option value="Course">Course</option>
<option value="BCA">BCA</option>
<option value="BBA">BBA</option>
<option value="B.Tech">B.Tech</option>
<option value="MBA">MBA</option>
<option value="MCA">MCA</option>
<option value="M.Tech">M.Tech</option>
</select><br></br>
</div>
24
HOPE COMPUTER INSTITUTE, Rajbiraj
<div>
<label>
Gender :
</label><br>
<input type="radio" value="Male" name="gender" checked > Male
<input type="radio" value="Female" name="gender"> Female
<input type="radio" value="Other" name="gender"> Other
</div><br>
<label>
Phone :
</label>
<input type="text" name="country code" placeholder="Country Code" value="+977"
size="2"/>
<input type="text" name="phone" placeholder="phone no." size="10"/
required><br></br>
Current Address :<br>
<textarea cols="80" rows="5" placeholder="Current Address" value="address" required>
</textarea><br></br>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required> <br></br>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw"
required><br></br>
26