HTML Notes
HTML Notes
Use a simple text editor like Notepad (Windows) or TextEdit (Mac). You can also use
more advanced editors like VS Code or Sublime Text.
Save the document with an .html extension. For example, you could name
it index.html.
In Notepad, go to File > Save As..., choose All Files in the “Save as type” dropdown,
and type index.html as the file name. Make sure you select UTF-8 encoding if
available.
Use any web browser like Google Chrome, Firefox, Safari, or Edge.
Drag and drop your saved index.html file into the browser window, or use the
browser’s Open File option:
o Safari: Use File > Open File... from the menu and select your HTML file.
Your browser will display the content of your HTML file. You should see the “Hello,
World!” heading and the paragraph text you created. This is your first web page!
Empty
Container
Container tags have opening tag and a closing tag.
<html>…</html
<head>..</head>
<title>..</title
<body>..</body>
<h1>…</h1> to <h6>…</h6>
<p>….</p>
<b>….</b>
<i>…</i
HTML Tags
Here's a simple breakdown of the essential HTML tags: <html>, <head>, <title>, and <body>, along
with their roles and examples:
1. <html> Tag
Purpose: This is the root element that wraps all the content on your web page. It tells the
browser that everything inside it is an HTML document.
2. <head> Tag
Purpose: Contains metadata and other information about the document that isn’t displayed
directly on the web page. This includes the title, character set, and links to stylesheets.
3. <title> Tag
Purpose: Sets the title of the web page, which appears in the browser's title bar or tab. It’s
crucial for search engines and user bookmarks.
4. <body> Tag
Purpose: Contains the content of the web page that is visible to users, such as text, images,
links, and other elements.
Example:
<body>
<h1>Welcome to My Website</h1>
<p>This is a paragraph of text on my web page.</p>
<a href="https://www.example.com">Visit Example</a>
</body>
Purpose: This attribute was used to set the color of the text on the page
2. background Attribute
Purpose: This attribute was used to set a background image for the entire page
<body background="background-image.jpg">
3. bgcolor Attribute
Purpose: This attribute was used to set the background color of an element.
Example:<body bgcolor="GREEN”>
4. link Attribute
Purpose: This attribute was used to set the color of unvisited links. It is used within
the <body> tag.
5. vlink Attribute
Purpose: This attribute was used to set the color of visited links. It is also used within
the <body> tag.
Example:
6. alink Attribute
Purpose: This attribute was used to set the color of active links (links that are clicked on). It is
used within the <body> tag.
Example:
Here’s a guide on how to use the <br> tag (line break), <hr> tag (horizontal rule), inserting
comments, and heading tags (<h1> to <h6>) in HTML:
Purpose: Inserts a line break in the text, moving the content that follows it to the next line.
This is useful for formatting text within paragraphs or creating space between lines.
o Result: The text “This is the second line.” appears below “This is the first line.” with a
line break in between.
3. Inserting Comments
Purpose: Adds notes or explanations within your HTML code that are not visible on the web
page. Comments are useful for documentation or leaving notes for yourself or others who
may read your code.
Syntax:
<p>This is a paragraph.</p>
<!-- The following section contains a horizontal rule -->
<hr>
<p>Another paragraph after the horizontal rule.</p>
o Result: The comment is visible only in the HTML source code, not on the web page.
Purpose: Define headings of different levels, with <h1> being the highest (or most
important) and <h6> the lowest. These tags help organize content and improve readability.
They also play a role in SEO by indicating the structure of the content.
Examples:
<h1>Main Heading</h1>
<h2>Subheading Level 1</h2>
<h3>Subheading Level 2</h3>
<h4>Subheading Level 3</h4>
<h5>Subheading Level 4</h5>
<h6>Subheading Level 5</h6>
o Result: Each heading level is displayed with decreasing size and importance. <h1> is
the largest and most prominent, while <h6> is the smallest.
p (paragraph), b (bold), i (italics), u (underline), ul (unordered list), ol (ordered list), and li (list item)
Here's a detailed guide on HTML tags for formatting text and creating lists:
Purpose: Defines a paragraph of text. Browsers automatically add space before and after
each <p> element to separate it from other content.
Example:
<p>This is a paragraph. It is used to display blocks of text with some space around it.</p>
Example:
Purpose: Displays text in italics. Like <b>, the <i> tag is for styling purposes without adding
semantic meaning. Use <em> for emphasized text.
Example:
Purpose: Underlines text. This tag is also used for styling rather than semantic meaning. For
semantic emphasis, use <ins> for inserted text.
Example:
Example:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
o Result: Displays a bulleted list:
o Item 1
o Item 2
o Item 3
1. type Attribute
Purpose: Specifies the type of bullet for the unordered list. Possible values include:
Example:
<ul type="square">
<li>Item 1</li>
<li>Item 2</li>
</ul>
Result: The list items will be displayed with square bullets:
o Item 1
o Item 2
Example:
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
1. First item
2. Second item
3. Third item
1. start Attribute
Purpose: Specifies the starting number of the ordered list. This is useful if you want
to begin numbering from a number other than 1.
Example:
<ol start="3" TYPE=”a”>
<li>Item 1</li>
<li>Item 2</li>
</ol>
5.ITEM1
6.ITEM2
Result: The list will start numbering from 5: 5. Item 1
6. Item 2
2. type Attribute
Purpose: Defines the numbering type for the ordered list. Possible values include:
Example:
<ol type="A">
<li>Item 1</li>
<li>Item 2</li>
</ol>
Purpose: Defines an item in a list. It is used inside both <ul> (unordered list)
and <ol> (ordered list).
Example:
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Cherry</li>
</ul>
Here’s a guide on HTML description lists and the attributes for ordered and unordered lists:
Purpose: Defines a description list, which is a list of terms and their descriptions.
This is used for creating glossaries, lists of definitions, or metadata.
Example:
<dl>
<DT>COMPUTER
<DD>AN ELECTRONIC DEVICE
<DT>KEYBOARD
<DD>
</DL>
COMPUTER
AN HCSDHCBHDBCJBDS
KEYBOARD
BDHCBHBDCDHCHD
2. <dt> Tag (Description Term)
Purpose: Specifies a term in the description list. This tag is used to define the term or
name being described.
Example:
<dt>HTML</dt>
Example:
<dd>Hypertext Markup Language, the standard language for creating web pages.</dd>
The <font> tag in HTML was used to style text with specific fonts, sizes, and colors. However, it's
considered obsolete in modern HTML and has been replaced by CSS for styling purposes. Here’s a
brief overview of the <font> tag and its attributes:
Purpose: The <font> tag was used to define the font, size, and color of text. It allowed for
inline styling within HTML documents, but it’s no longer recommended for use in modern
web design.
1. face Attribute
Purpose: Specifies the font family to be used for the text. Multiple font names can
be provided as a fallback in case the first choice is unavailable.
Example:
2. size Attribute
Purpose: Sets the size of the text. It can be a number from 1 to 7, where 1 is the
smallest and 7 is the largest. Alternatively, you can use relative sizes like +1 or -2 to
adjust the font size relative to the default size.
Example:
3. color Attribute
Purpose: Defines the color of the text. It can be specified using color names,
hexadecimal values, or RGB values.
Example:
Insert Images: img (attributes: src, width, height, alt), sup (super script), sub (subscript)
The <img> tag is used to display images on a web page. It is a self-closing tag, meaning it does not
need a closing tag.
Attributes:
o src: Specifies the path to the image file. It can be a relative path or a URL.
o alt: Provides alternative text for the image if it cannot be displayed. This is important
for accessibility and SEO.
Example:
o Explanation:
The <sup> tag is used to display text as superscript, which means the text appears slightly above the
baseline and is usually smaller.
Example:
X2 X<SUP>2</SUP>
E = mc<sup>2</sup></p>
o Result: Displays the “2” as superscript in the
equation E = mc².
3. Subscript with <sub> Tag
The <sub> tag is used to display text as subscript, meaning the text appears slightly below the
baseline and is usually smaller.
Example:
<p>H<sub>2</sub>O</p>
Here’s an example of an HTML table with header cells, data cells, and merged rows and columns:
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Example</title>
</head>
<body>
<h1>My HTML Table</h1>
<table border="1">
<!-- Table Header -->
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
<!-- Table Row 1 -->
<tr>
<td>Row 1, Cell 1</td>
<td colspan="2">Row 1, Cell 2 (spans 2 columns)</td>
</tr>
Explanation
1. Table Header:
<th> elements are used for headers. In this example, three header cells are defined
in the first row.
2. Row 1:
The first cell uses <td> with colspan="2", merging two columns into one cell.
3. Row 2 and 3:
The first cell in Row 2 uses rowspan="2", merging it with the cell directly below it in
Row 3.
4. Row 4:
HTML Forms
HTML forms are essential for collecting user input on web pages. HTML Forms utilize
the <form> element as a powerful tool to collect user input through a variety of interactive controls.
These controls range from text fields, numeric inputs, email fields, password fields, to checkboxes,
radio buttons, and submit buttons. In essence, an HTML Form serves as a versatile container for
numerous input elements, thereby enhancing user interaction.
Syntax:
<form>
<!--form elements-->
</form>
Example: This HTML forms collects the user personal information such as username and password
with the button to submit the form.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Html Forms</title>
</head>
<body>
<h2>HTML Forms</h2>
<form>
<label for="username">Username:</label><br>
<label for="password">Password:</label><br>
</form>
</body>
</html>
Output:
HTML Form
Here’s a breakdown of different form elements like textboxes, radio buttons, checkboxes,
passwords, lists, and combo boxes, along with examples for each:
1. Textbox
Attributes:
Example:
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter your username">
o Explanation: Creates a textbox where users can type their username, with a
placeholder text indicating what to enter.
2. Radio Buttons
Attributes:
o name: Groups radio buttons to ensure only one can be selected at a time.
o value: Represents the value sent when the form is submitted.
Example:
o Explanation: Creates two radio buttons allowing the user to select either "Male" or
"Female."
3. Checkbox
Attributes:
Example:
o Explanation: Creates checkboxes for "Coding" and "Gaming," allowing the user to
select one or both interests.
4. Password
Purpose: Allows users to enter a password. The input is obscured for privacy.
Attributes:
Example:
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password">
o Explanation: Creates a password field where users can enter their password, and it
will be hidden with dots.
Attributes:
Example:
Purpose: Allows users to select from a dropdown list or enter their own text.
Attributes:
Example:
<label for="city">City:</label>
<input type="text" id="city" name="city" list="cities">
<datalist id="cities">
<option value="New York">
<option value="Los Angeles">
<option value="Chicago">
</datalist>
o Explanation: Creates a textbox with a dropdown list of city options. Users can either
select from the list or enter their own city.
Here’s a simple HTML form that includes textboxes, radio buttons, checkboxes, a password field, a
dropdown list, and a combo box:
<!DOCTYPE html>
<html>
<head>
<title>HTML Form Example</title>
</head>
<body>
<h1>Form Example</h1>
<form>
<!-- Textbox -->
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter your
username"><br><br>
1. Embedding Audio
The <audio> tag is used to embed audio files in an HTML document. You can specify multiple audio
formats to ensure compatibility across different browsers.
Attributes:
o controls: Adds playback controls (play, pause, volume) to the audio player.
o autoplay: Automatically starts playing the audio when the page loads (use with
caution as it can be intrusive).
Example:
o Explanation: Embeds an audio file with playback controls. If the browser doesn’t
support the <audio> tag, the text "Your browser does not support the audio
element" is displayed.
2. Embedding Video
The <video> tag is used to embed video files. Like <audio>, you can include multiple video formats to
ensure compatibility.
Attributes:
o controls: Adds playback controls (play, pause, volume, fullscreen) to the video player.
o autoplay: Automatically starts playing the video when the page loads (use with
caution).
o loop: Repeats the video indefinitely.
Example:
HYPERLINKS
Links: Significance of Linking, anchor element (attributes: href, mailto), targets
Links are a fundamental part of the web, allowing users to navigate between pages and access
various resources.
1. Significance of Linking
Navigation: They allow users to move from one page to another or to different sections
within the same page, making navigation seamless.
Access to Resources: Links can direct users to external websites, documents, or multimedia
resources.
Improved User Experience: They provide a way to connect related content, helping users
find relevant information quickly.
Example: Clicking on a link to a tutorial page while reading an article about web design.
The <a> element, also known as the anchor tag, is used to create hyperlinks. Here’s how you can use
it:
href="https://www.example.com">Visit
Example</a>
o Explanation: This link directs users to "https://www.example.com" when clicked.
mailto: Opens the default email client to send an email to the specified email address.
o <a href="mailto:[email protected]">Email
Example:
Us</a>
o Explanation: Clicking this link opens the user's email client with
"[email protected]" as the recipient.
o _self: Opens the link in the same frame or tab (default behavior).
o _parent: Opens the link in the parent frame (if the page is within an iframe).
o _top: Opens the link in the full body of the window, replacing any frames.
o Example:
<!DOCTYPE html>
<html>
<head>
<title>HTML Links Example</title>
</head>
<body>
<h1>Welcome to My Website</h1>
Significance: Links help users navigate between web pages and access various online
resources.
o target: Defines where the link will open (same tab, new tab, etc.).
Understanding these basics allows you to create effective and user-friendly links in your web pages.
Cascading Style Sheets (CSS) are used to style and layout web pages. They control the look and feel
of HTML elements, making web pages not only functional but also visually appealing. CSS,
or Cascading Style Sheets, is a language used to style and enhance websites. It controls how HTML
elements such as text, images, and buttons—are displayed on a webpage.
With CSS, you can adjust font sizes and colors, add backgrounds, and manage the layout,
transforming a basic webpage into a visually appealing and user-friendly experience. CSS also
simplifies layout management across multiple web pages by using external stylesheets stored in CSS
files.
Here’s a basic introduction to key CSS properties and how they can be applied:
1. Introduction to CSS
CSS is a language used to describe the presentation of a document written in HTML or XML. It allows
you to:
HTMLCSS
<html>
<head>
<style>
h2 {
color: green;
</style>
</head>
<body>
</body>
</html>
OUTPUT:
o Example: font-family: 'Times New Roman', serif; (Times New Roman font)
text-align: Aligns the text inside an element (left, right, center, justify).
float: Allows an element to float to the left or right of its container, enabling text to wrap
around it.
3. Practical Application
Here’s a practical example to see how these properties are used in context:
<!DOCTYPE html>
<html>
<head>
<title>CSS Properties Example</title>
<style>
.container {
width: 100%;
background-color: #f9f9f9;
padding: 20px;
}
.box {
width: 150px;
height: 150px;
background-color: #3498db;
border: 3px solid #2980b9;
margin: 10px;
padding: 10px;
color: white;
font-family: 'Arial', sans-serif;
font-size: 18px;
font-style: italic;
text-align: center;
float: left;
}
.box:last-child {
background-color: #e74c3c;
border-style: dashed;
outline: 4px solid #c0392b;
}
</style>
</head>
<body>
<div class="container">
<div class="box">Box 1</div>
<div class="box">Box 2</div>
</div>
</body>
</html>
Properties: Control text color, background, borders, margins, sizes, fonts, and layout.
Usage: Apply CSS in <style> tags or external stylesheets to format and design web pages
effectively.