HTML Notes
HTML Notes
HTML, or HyperText Markup Language, is the fundamental building block of the web. It's used to
structure content on the internet. Below is an overview of the history of HTML, tracing its
development from its inception to the present.
Modern HTML
2016 and beyond : HTML5.1 and HTML5.2 have been released, introducing minor
improvements and clarifications. The development of HTML now follows a "living standard"
model by WHATWG, meaning it is continuously updated based on practical needs and
implemented features. W3C and WHATWG agreed in 2019 to pursue a joint effort to produce
a living HTML and DOM standard to avoid the bifurcation of the web standards.
HTML has grown from a simple document formatting language to a complex system capable
of supporting a wide range of web applications. Its evolution is closely tied to the growth of
the internet itself, reflecting new technological advancements and changing web usage
patterns.
HTML Introduction
HTML, which stands for HyperText Markup Language, is the standard markup language used to
create web pages. It forms the structural foundation of all websites and is crucial for creating and
visually structuring content on the internet. HTML documents are the building blocks of a website,
allowing developers to organize text, images, videos, forms, and other elements into a coherent
layout that users can interact with via a web browser.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Welcome to My Website</h1>
</body>
</html>
Why Learn HTML?
1. Foundation of Web Development : HTML is the starting point for web development.
Understanding HTML is essential before moving on to more complex web technologies like
CSS (for styling) and JavaScript (for interactive elements).
2. Ease of Learning : HTML is considered one of the easiest languages to learn in the coding
community, making it a great starting point for those new to programming.
3. Universal Tool : The skills learned in HTML are applicable across all platforms that use web
technology, whether for creating websites, designing email templates, or developing web
applications.
By mastering HTML, developers can effectively communicate their ideas and content through the
vast network of the World Wide Web, laying the groundwork for more advanced technologies and
interactive experiences.
List Tags
<ul> : Defines an unordered list.
<ol> : Defines an ordered list.
<li> : Defines a list item.
Table Tags
<table> : Defines a table.
<tr> : Defines a row in a table.
<td> : Defines a cell in a table.
<th> : Defines a header cell in a table.
Form Tags
<form> : Creates an HTML form for user input.
<input> : Defines an input field within a form.
<textarea> : Defines a multi-line text input control.
<button> : Defines a clickable button.
These tags, used together, help structure the content on web pages, making it understandable and
navigable for both users and search engines. Understanding how to use these tags effectively is the
foundation of learning to create web pages.
Meta Tags
Meta tags are snippets of text that describe a page's content; they don't appear on the page itself,
but only in the page's code. While they are invisible to visitors, they are critically important to search
engines and browsers. Meta tags can affect how documents are displayed, how they are handled by
browsers, and how they are indexed by search engines.
6. HTTP-Equiv Tags
These tags can act like HTTP header responses sent from the server and can control
caching, set cookies, specify the content type, etc.
Example for refreshing the page every 30 seconds :
<meta http-equiv="refresh" content="30">
Properly used, meta tags play a crucial role in enhancing the visibility and functionality of web pages,
ensuring they work well across various environments and are accurately indexed by search engines.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Resume</title>
</head>
<body>
</body>
</html>
<header>
<h1>Your Name</h1>
<p>Email : [email protected]</p>
</header>
<section>
<h2>Objective</h2>
</section>
<section>
<h2>Education</h2>
<ul>
</ul>
</section>
<section>
<h2>Work Experience</h2>
<ul>
</ul>
</section>
Step 6: Skills
Create a list of your professional skills that are relevant to the job you are applying for.
<section>
<h2>Skills</h2>
<ul>
</ul>
</section>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Resume</title>
</head>
<body>
<header>
<h1>Your Name</h1>
<p>Email : [email protected]</p>
</header>
<section>
<h2>Objective</h2>
</section>
<section>
This simple HTML resume can be enhanced further with CSS for better styling and layout, making it
more visually appealing and professional.
Media Tags
<audio> and <video>: Simplify the process of embedding audio and video content on web
pages without the need for proprietary plugins like Flash. These tags support native controls
and can be manipulated via the HTML DOM API.
<source>: Used within <video> and <audio> to specify multiple media resources, allowing
the browser to choose the format it supports.
<track>: Used with <audio> and <video> elements to specify timed text tracks (like subtitles
and captions).
Others
<canvas>: Allows dynamic rendering of bitmap graphics via scripting (e.g., JavaScript). This is
commonly used for graphical applications, games, and data visualization.
These tags make HTML5 a powerful tool for developing more intuitive, media-rich, and semantically
meaningful web pages. HTML5 has significantly improved the web's ability to handle multimedia and
graphical content natively, enhancing user experience and accessibility.
<ul> and <ol> Tags (And how are they used for
Nested List?)
In HTML, lists are a fundamental way to structure a series of related items. HTML provides three
types of lists: unordered lists (<ul>), ordered lists (<ol>), and description lists (<dl>). The <ul> and
<ol> tags are especially useful for creating hierarchical or nested lists, which are lists within lists.
Here's a breakdown of how these tags are used :
<li>Item 1</li>
<li>Item 2
<li>Subitem 2a </li>
<li>Subitem 2b</li>
</ul>
</li>
<li>Item 3
<li>Subitem 3a </li>
<li>Subitem 3b</li>
</ol>
</li>
</ol>
In this example :
The main list is an ordered list (<ol>), meaning each item is numbered.
Within the second item of the main list, there is a nested unordered list (<ul>), which uses
bullets for its items.
Inside the third item of the main list, there is another nested ordered list, continuing the
numeric sequence but starting fresh from one, as it pertains specifically to the context of
"Item 3".
Practical Usage
Nested lists are particularly useful in web content for:
Understanding and using nested lists can significantly improve the structure and readability of your
web content, making it more accessible and user-friendly.
Table Tag
The <table> tag in HTML is used to create a table, which is a means of arranging data in rows and
columns, making it easier to read and understand. Tables are widely used on the web for displaying
tabular data like schedules, statistics, or financial information.
border : Specifies the border thickness around the table and its cells.
cellpadding : Controls the spacing between the cell walls and the cell content.
cellspacing : Controls the spacing between individual cells.
colspan : Used in <th> or <td> to indicate that a cell should span multiple columns.
rowspan : Used in <th> or <td> to indicate that a cell should span multiple rows.
<!DOCTYPE html>
<html lang="en”>
<head>
<meta charset="UTF-8">
<title>Sample Table</title>
</head>
<body>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
In this example :
The <table> tag sets up the table with a border.
The <thead> element contains a single row <tr> with header cells <th> that label each
column.
The <tbody> element contains the main data of the table with three rows, each including a
number, a name, an age, and a city.
The <tfoot> element is used for a footer row that spans all columns using colspan="4",
indicating some kind of summary or conclusion.
This basic table layout is useful for a wide range of applications on the web, from displaying data in a
clear, grid-like format to organizing content in a visually structured way.
Form Tag
The <form> tag in HTML is used to create an HTML form for user input. Forms are essential for
interactive web pages, allowing users to submit data to a web server for processing, which could be
for logging in, registration, searching, booking, and more.
<form> : The container for all the form elements. It defines how to send the data and where
to send it.
Input Elements : These can be <input>, <textarea>, <button>, <select>, and others, each
serving different purposes for different kinds of user input.
Attributes :
action : Specifies the URL where the form's data is sent when submitted.
method : Defines the HTTP method used when submitting the form. Common methods
are GET (data appended to the URL) and POST (data sent in the body of the request).
<!DOCTYPE html>
<html lang="en”>
<head>
<meta charset="UTF-8">
</form>
</body>
</html>
In this form :
The form data will be sent to "submit.php" using the POST method when submitted.
Various <input> types are used: text, email, date, file, and buttons for submitting and
resetting the form.
A <select> dropdown lets the user choose a department.
Each input is paired with a <label> for better accessibility; the for attribute in the label is
associated with the id of the corresponding input element.
Use Case
Forms are used across the web for a variety of purposes:
HTML forms are fundamental to interactive and functional websites, enabling web developers to
gather and process data efficiently while providing users with a seamless interaction experience.
1. Text
Type : text
Description : A single-line text field.
Attributes :
maxlength : Specifies the maximum number of characters allowed.
placeholder : Provides a hint to the user about what to enter in the input.
required : Indicates that the field must be filled out before submitting the form.
2. Email
Type : email
Description : A field for entering an email address. The browser can validate the entered
text to ensure it conforms to the standard email format.
Attributes :
multiple : Allows multiple email addresses to be entered.
3. Password
Type : password
Description : A text field that masks user input, suitable for passwords.
Attributes :
autocomplete : Can be set to "new-password" to hint to the browser to generate a
password.
4. Radio
Type : radio
Description : Allows the user to select one of a limited number of choices.
Attributes :
checked : Specifies whether a radio button is selected when the page loads.
name : Radio buttons sharing the same name are considered as part of one group.
5. Checkbox
Type : checkbox
Description : Allows the user to select zero or more options from a set.
Attributes :
checked : Indicates whether the checkbox is checked by default.
6. File
Type : file
Description : Lets the user select one or more files from their device storage to be
uploaded to a server.
Attributes :
accept : Specifies a filter for what file types the user can pick from the file input
dialog.
7. Submit
Type : submit
Description : A button that submits the form.
Attributes :
value : Specifies the text on the submit button.
8. Reset
Type : reset
Description : A button that resets all form fields to their initial values.
9. Button
Type : button
Description : A clickable button that can be used with JavaScript to perform an action on
the client side.
Attributes :
onclick : Often used with JavaScript to specify what should happen when the button
is clicked.
11. Number
Type : number
Description : Allows the user to enter a numeric value. Browsers will provide interfaces
to increase or decrease the number.
Attributes :
min and max : The minimum and maximum values allowed.
step : The interval between valid numbers in the control.
12. Range
Type : range
Description : Lets the user specify a numeric value which must be no less than a given
value, and no more than another given value. Often rendered as a slider.
Attributes :
min, max, step : Controls the range of values by setting the minimum, maximum,
and step values.
13. Color
Type : color
Description : Provides a control for specifying a color. A color picker interface is typically
provided in the browser.
Attributes : (Generally does not have special attributes beyond the standard ones
applicable to <input>.)
Each of these input types is designed to handle specific data formats, ensuring that the data entered
is appropriate and valid, thereby enhancing data integrity and the user experience on web forms.
Preformatted Text
<pre>: Preserves both spaces and line breaks as written in the HTML source. This is useful for
displaying code or poetry where the formatting is significant.
Quotations
<blockquote> : Used to indicate extended quotations. Usually, browsers indent text inside a
<blockquote>.
<q> : For shorter quotes, browsers may render this with quotation marks.
Code
<code>: Displays its contents styled in a way that indicates the text is a short fragment of
computer code.
<samp>: Intended for output from a computer program. Typically displayed in a font that
distinguishes it from the surrounding text.
<kbd>: Indicates text to be input by the user. Often displayed in a monospace font which
simulates the text as it would appear on a keyboard.
Deprecated Tags
Some tags, like <font>, <strike>, and <center>, were commonly used in earlier versions of
HTML but are now deprecated in favor of CSS for styling. These tags are not recommended
for use in modern web development.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
This code snippet demonstrates the use of strong, emphasis, underlined, deleted, inserted, subscript,
and superscript tags to format text according to its semantic meaning, while also providing stylistic
adjustments. Remember, for extensive styling, it's better to use CSS.
Quotation Tags
1. <blockquote>
Usage : The <blockquote> tag is used for longer block quotations from another source. It
is typically used to represent content that is quoted from another source, encompassing
multiple sentences, a paragraph, or a series of paragraphs.
Attributes :
cite : Specifies a URL that points to the source of the quotation or more information
about the quote.
Presentation : Web browsers usually indent text within a <blockquote> from both the
left and right margins.
Example :
<blockquote cite="https://example.com">
<p>This is a long block quote example. It can span multiple sentences and is typically
used for more extended passages that are quoted verbatim from another source.</p>
</blockquote>
2. <q>
Usage : The <q> tag is used for shorter inline quotations that sit within the surrounding
text. It is ideal for inserting brief quotes within a sentence or paragraph.
Attributes :
cite : Similarly to <blockquote>, it specifies the source URL of the quote.
Presentation : Most browsers will automatically enclose the content of <q> in quotation
marks.
Example :
<p>As Albert Einstein once said, <q cite="https://example.com">Imagination is more
important than knowledge.</q></p>
Citation Tag
1. <cite>
Usage : The <cite> tag is used to reference a creative work. It can be used to cite a book,
a paper, a poem, a song, a film, or any other creative work.
Presentation : Content within <cite> is typically rendered in italic to denote that it is a
title of a work.
Example :
<p>One of the most influential books in science is <cite>On the Origin of Species</cite>
by Charles Darwin.</p>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>As mentioned in <cite> The Art of Computer Programming </cite>by Donald Knuth :</p>
<p>“Beware of bugs in the above code; I have only proved it correct, not tried it.”</p>
</blockquote>
This example shows how to use <blockquote> for a longer quote, <cite> to reference the title of a
book, and <q> could be used similarly for shorter quotes within the narrative. These semantic tags
enhance the readability and accessibility of web content by clearly distinguishing quotations and
sources.
Here's a breakdown of the key HTML tags used to design the layout of a web page :
1. <header>
Usage : Used to define the introductory content or navigational links at the top of a web
page or section.
Example :
<header>
<h1>Website Title</h1>
<nav>
<ul>
<li><a href="#home”>Home</a></li>
<li><a href="#about”>About</a></li>
<li><a href="#services”>Services</a></li>
</ul>
</nav>
</header>
2. <footer>
Usage : Represents the footer of a page or section, typically containing copyright
information, contact details, or links to legal or privacy information.
Example :
<footer>
</footer>
3. <nav>
Usage : Designed for navigational links, this tag indicates that the enclosed links are part
of the main or subsidiary navigation of a site.
Example :
<nav>
<ul>
<li><a href="#home”>Home</a></li>
</ul>
</nav>
4. <section>
Usage: Defines a section in a document, such as chapters, headers, footers, or any other
sections of the document.
Example :
<section>
<h2>About Us<h2>
</section>
5. <article>
Usage: Specifies independent, self-contained content that could be distributed
independently of the rest of the site, such as blog posts, news articles, etc.
Example :
<article>
<h2>Blog Title<h2>
</article>
6. <aside>
Usage: Used for tangentially related content that serves as a sidebar to the main
content.
Example :
<aside>
<h3>Related Posts<h3>
<ul>
</ul>
</aside>
7. <main>
Usage: Specifies the main content of the document, which is unique to the document
and excludes content repeated across documents such as sidebars, navigation links, and
footers.
Example :
<main>
<article>
<h1>Article Title<h1>
<p>Article content…</p>
</article>
</main>
8. <div>
Usage: A generic container for flow content, which does not inherently represent
anything. It can be useful for styling purposes or as a container for dynamic scripting.
Example :
<section>
<h2>Section Title<h1>
</section>
</div>
These tags, when used in conjunction with CSS, enable developers to create structured, accessible,
and visually appealing web pages. The semantic nature of these tags also helps with SEO and ensures
better accessibility standards.
<!DOCTYPE html>
<html lang="en”>
<head>
<meta charset="UTF-8">
<title>My Resume</title>
<style>
table {
width: 100%;
border-collapse: collapse;
Step 2: Add Personal Information
Within the <table> tag, create a row for personal information :
<tr>
</tr>
<tr>
<td>Name</td>
<td>John Doe</td>
</tr>
<tr>
<td>Email</td>
Step 3: Add an Objective
Next, include a section for your career objective :
<tr>
<th colspan="2”>Objective</th>
</tr>
<tr>
</tr>
<tr>
<th colspan="2”>Education</th>
</tr>
<tr>
<td>2018-2022</td>
</tr>
Step 5: Work Experience
Include your work experience :
<tr>
</tr>
<tr>
<td>2022-Present</td>
</tr>
<tr>
<td>2021-2022</td>
</tr>
Step 6: Skills
Finally, list some relevant professional skills :
<tr>
<th colspan="2”>Skills</th>
</tr>
<tr>
</tr>
Full HTML Code with the Resume Table
Combining all the parts, the complete HTML for the resume will look like this:
<!DOCTYPE html>
<html lang="en”>
<head>
<meta charset="UTF-8">
<title>My Resume</title>
<style>
table {
<tr>
<td>Email</td>
<td>[email protected]</td>
</tr>
<tr>
<td>Phone</td>
<td>(123) 456-7890</td>
</tr>
<td>2021-2022</td>
</tr>
<tr>
<th colspan="2”>Skills</th>
</tr>
<tr>
</tr>
</table>
Basic Syntax
<img src="url" alt="description">
Key Attributes
1. src (source)
Description : Specifies the URL (web address) of the image.
Example : src="image.jpg"
This attribute is mandatory, as it tells the browser where to find the image that needs to be
displayed.
This attribute is also used for accessibility, making images accessible to visually impaired users
and it is highly recommended to always include an alt attribute.
4. title
Description : Provides additional information about the image. The information is usually
displayed as a tooltip when the mouse moves over the image.
Example : title="Title of the Image"
5. loading
Description : This attribute allows a browser to defer loading the image until it reaches a
calculated distance from the viewport.
Values :
auto : Default, loads the image when it gets to the point in the page where it needs
to be loaded.
lazy : Delays loading of the image until it reaches a certain distance from the
viewport.
eager : Loads the image immediately, regardless of where it appears on the page.
Example : loading="lazy"
Examples
Basic Image Embed
<img src="logo.png" alt="Company Logo">
This is a simple use of the <img> tag to display an image called logo.png.
This example shows an image with specified dimensions and a tooltip, providing a better control over
how the image should fit into the layout.
This uses the loading="lazy" attribute to defer loading of a large image until it is about to scroll into
view, which can help with performance on pages with many large images.
Using the <img> tag effectively allows web developers to incorporate visual elements into web
pages, enhancing user engagement and providing key information in a visual format.
Basic Syntax
<a href="url">Link Text</a>
Key Attributes
1. href (Hypertext Reference)
Description : Specifies the URL of the page the link goes to. This can be an absolute URL
(full web address) or a relative URL (location relative to the current page).
Example : href=https://www.example.com
2. target
Description : Defines where to open the linked document.
Values :
_blank: Opens the linked document in a new window or tab.
_self: Opens the link in the same frame as it was clicked (this is the default).
_parent: Opens the link in the parent frame.
_top: Opens the link in the full body of the window.
Example : target="_blank" (commonly used for opening a link in a new tab).
3. title
Description : Provides additional information about the link. This is often shown as a
tooltip when the user hovers over the link.
Example : title="Go to Example"
4. rel (Relationship)
Description : Specifies the relationship between the current document and the linked
document.
Values :
nofollow: Tells search engines not to follow this hyperlink.
noopener: Prevents the new page from being able to access the window object of
the page that opened it.
noreferrer: Prevents the Referer header from being sent to the new page.
Example : rel="noopener noreferrer"
5. download
Description : Specifies that the target will be downloaded when a user clicks on the
hyperlink. This attribute only works for same-origin URLs or when a CORS setting is
configured to allow it.
Example : download="filename.ext" or just download to use the original filename.
This opens a link in a new tab and uses rel="noopener noreferrer" for security reasons,
particularly to prevent the new page from accessing the JavaScript window object of the
opening page.
4. Email Link
<a href="mailto:[email protected]">Send Email</a>
This creates a hyperlink that opens the user’s default mail program with the "To" field pre-
filled with the specified email address.
5. Telephone Link
<a href="tel:+1234567890">Call Us</a>
This creates a hyperlink that, when clicked on a device capable of making calls, will
attempt to dial the number.
Accessibility Considerations
When using the <a> tag, it's important to ensure the link text is descriptive enough to be
understood out of context, as screen readers might read links as a list. Avoid vague
descriptions like "click here" and aim for more descriptive links, e.g., "Read more about
HTML tags".
The <a> tag is essential for web navigation, providing a way to interconnect content across
the vast landscape of the internet and making the web a navigable and user-friendly
environment.
The <audio> tag is used to embed audio content in a document, such as music or other sound clips.
Here is how you can use this tag:
Basic Syntax
<audio controls>
The <video> tag is used to embed video content in a document. It supports a variety of video
formats, though the exact support can vary widely between web browsers.
Basic Syntax
</video>
Key Attributes
Here’s a simple example that shows how to embed both audio and video files into an HTML
document :
<!DOCTYPE html>
<html lang="en”>
<head>
<meta charset="UTF-8">
<title>Media Example</title>
</head>
<body>
<h1>Audio Example</h1>
<audio controls>
In this example :
The <audio> and <video> tags are used with the controls attribute to allow user interaction.
The <source> tags are used to specify multiple sources for the same video or audio to ensure
maximum compatibility across different browsers.
These tags are essential for making multimedia a seamless part of modern web applications,
providing users with rich audio and video experiences directly in their browsers without additional
software.
Basic Syntax
<iframe src="url" width="width" height="height"></iframe>
Key Attributes
1. src (source)
Description : Specifies the URL of the page that the <iframe> will display.
Example : src=https://www.example.com
3. frameborder
Description : Specifies whether or not to display a border around the <iframe>. While it's
still supported by most browsers, it's considered obsolete in HTML5. CSS should be used
instead for styling.
Example : frameborder="0" (to have no border)
4. name
Description : Assigns a name to the <iframe>, which can be targeted by links and forms.
Example : name="frame1"
5. sandbox
Description : Enables an extra set of restrictions for the content in the <iframe>. This
attribute is important for enhancing security by controlling what the embedded
document can do.
Values :
Without value: Applies all restrictions.
allow-forms: Allows the form submission.
allow-scripts: Allows script execution.
allow-same-origin: Allows the iframe content to be treated as being from the same
origin.
allow-popups: Allows popups.
Example : sandbox="allow-scripts"
6. allow
Description : Specifies a feature policy for the <iframe>. It can be used to control which
features and APIs can be used in the embedded document.
Example : allow="geolocation; microphone"
7. srcdoc
Description : Specifies the HTML content of the page to show in the iframe. This
attribute allows embedding content directly without an external page.
Example : srcdoc="<p>Hello, world!</p>"
<!DOCTYPE html>
<html lang="en”>
<head>
<meta charset="UTF-8">
<title>iframe Example</title>
</head>
<body>
<h1>Embedded Content</h1>
</iframe>
</body>
</html>
In this example, an external website is embedded within an <iframe>, with specified dimensions and
permissions. The frameborder="0" is used to ensure that no border is visible around the iframe,
making it seamlessly integrate into the layout of the hosting page.
<iframe> remains a powerful HTML element for embedding third-party content directly into web
pages, but it requires careful management to ensure security and maintain website performance.
Inline Element and Block level Element
In HTML, elements are broadly categorized into two types based on how they are displayed by
default in the browser: inline elements and block-level elements. Understanding the distinction
between these two types is crucial for effectively managing the layout and formatting of a webpage.
Block-Level Elements
Block-level elements are those that start on a new line and occupy the full width available, stretching
out to the left and right as far as possible. Essentially, these elements look like "blocks" of content on
a webpage.
Example :
<div>
<h1>This is a heading.</h1>
</div>
Inline Elements
Inline elements do not start on a new line and only occupy as much width as necessary. This makes
them ideal for use within other elements without breaking the flow of content, such as within a
paragraph or a heading.
Example :
<p>This is a paragraph with some <strong>bold text</strong> and a <a href="#">link</a>.</p>
Understanding and using these types of elements correctly is fundamental to web design, affecting
everything from document structure to style application.