HTML Lectures
HTML Lectures
<p>HTML links are defined with the a tag. The link address is
Example specified in the href attribute:</p>
<p>This is a <br> paragraph with a line break.</p>
<a href="https://www.w3schools.com">This is a link</a>
Empty elements can be "closed" in the opening tag like this: <br />.
HTML5 does not require empty elements to be closed. But if you want
stricter validation, or if you need to make your document readable by
XML parsers, you must close all HTML elements properly.
Example
<img src="img_girl.jpg" width="500" height="600"> //same as above
The style Attribute
The width and height are specified in pixels by default; so width="500"
means 500 pixels wide. The style attribute is used to specify the styling of an element, like
color, font, size etc.
The alt Attribute
The alt attribute specifies an alternative text to be used, if an image Example
cannot be displayed. The value of the alt attribute can be read by screen <h2>The style Attribute</h2>
6
NABIIKHAN OFFICIAL HTML NOTES
<p>The style attribute is used to specify the styling of an element, like Example
color:</p>
<p title="I'm a tooltip">
<p style="color:red">This is a red paragraph.</p> This is a paragraph.
</p>
The first two letters specify the language (en). If there is a dialect, add
Good
two more letters (US). <a href="https://www.w3schools.com">
HTML Headings
Headings are defined with the <h1> to <h6> tags. <h1> defines the most
important heading. <h6> defines the least important heading.
Using quotes are the most common. Omitting quotes can produce Example
errors. At W3Schools we always use quotes around attribute values. <h1>Heading 1</h1>
<h2>Heading 2</h2>
Single or Double Quotes? <h3>Heading 3</h3>
<h4>Heading 4</h4>
Double quotes around attribute values are the most common in HTML, <h5>Heading 5</h5>
but single quotes can also be used. In some situations, when the <h6>Heading 6</h6>
attribute value itself contains double quotes, it is necessary to use single
Note: Browsers automatically add some white space (a margin) before
quotes:
and after a heading.
<p title='John "ShotGun" Nelson'>
Or vice versa:
8
NABIIKHAN OFFICIAL HTML NOTES
HTML Paragraphs
ignores it.
</p>
The HTML <p> element defines a paragraph: Don't Forget the End Tag
Most browsers will display HTML correctly even if you forget the end
Example tag:
<p>This is a paragraph.</p>
<p>This is another paragraph.</p> Example
Note: Browsers automatically add some white space (a margin) before <p>This is a paragraph.
and after a paragraph. <p>This is a paragraph.
<p>This is a paragraph.
HTML Display <p>Don't forget to close your HTML tags!</p>
The example above will work in most browsers, but do not rely on it.
You cannot be sure how HTML will be displayed. Large or small
screens, and resized windows will create different results. With HTML, Note: Dropping the end tag can produce unexpected results or errors.
you cannot change the output by adding extra spaces or extra lines in
your HTML code. The browser will remove any extra spaces and extra HTML Line Breaks
lines when the page is displayed:
The HTML <br> element defines a line break. Use <br> if you want a
Example line break (a new line) without starting a new paragraph:
<p> Example
This paragraph
contains a lot of lines <p>This is<br>a paragraph<br>with line breaks.</p> The <br> tag is
in the source code, an empty tag, which means that it has no end tag
but the browser
10
NABIIKHAN OFFICIAL HTML NOTES
<p>
HTML Styles
My Bonnie lies over the ocean.
Background Color
The CSS background-color property defines the background color for an
HTML element. This example sets the background color for a page to
The HTML <pre> Element powderblue:
The HTML <pre> element defines preformatted text. The text inside Example
a <pre> element is displayed in a fixed-width font (usually Courier), and
it preserves both spaces and line breaks: <body style="background-color:powderblue;">
<h1>This is a heading</h1>
Example <p>This is a paragraph.</p>
Text Color
The CSS color property defines the text color for an HTML element:
Example
<h1 style="color:blue;">This is a heading</h1> Text Size
<p style="color:red;">This is a paragraph.</p> The CSS font-size property defines the text size for an HTML element:
Example
<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>
Fonts
The CSS font-family property defines the font to be used for an HTML
element:
12
NABIIKHAN OFFICIAL HTML NOTES
Text Alignment
The CSS text-align property defines the horizontal text alignment for an
HTML Text Formatting
HTML element: HTML Formatting Elements
In the previous chapter, you learned about the HTML style attribute.
Example HTML also defines special elements for defining text with a
special meaning.
<h1 style="text-align:center;">Centered Heading</h1> HTML uses elements like <b> and <i> for formatting output,
<p style="text-align:center;">Centered paragraph.</p> like bold or italic text.
Formatting elements were designed to display special types of text:
<b> - Bold text
<strong> - Important text
<i> - Italic text
<em> - Emphasized text
<mark> - Marked text
<small> - Small text
<del> - Deleted text
<ins> - Inserted text
<sub> - Subscript text
Chapter Summary <sup> - Superscript text
Use the style attribute for styling HTML elements HTML <b> and <strong> Elements
Use background-color for background color The HTML <b> element defines bold text, without any extra
Use color for text colors importance.
Use font-family for text fonts Example
Use font-size for text sizes <p>This text is normal.</p>
Use text-align for text alignment
<b>This text is bold</b>
The HTML <strong> element defines strong text, with added semantic
"strong" importance.
13
NABIIKHAN OFFICIAL HTML NOTES
Example
<p>This text is normal.</p>
Example
HTML <sub> Element <p>Browsers usually insert quotation marks around the q element.</p>
The HTML <sub> element defines subscripted text.
Example <p>WWF's goal is to: <q>Build a future where people live in harmony
with nature.</q></p>
<p>This is <sub>subscripted</sub> text.</p>
Example
<p>The HTML address element defines contact information
(author/owner) of a document or article.</p>
<address>
HTML <abbr> for Abbreviations Written by John Doe.<br>
The HTML <abbr> element defines an abbreviation or an acronym. Visit us at:<br>
Marking abbreviations can give useful information to browsers, Example.com<br>
translation systems and search-engines. Box 564, Disneyland<br>
USA</address>
Example
<p>The <abbr title="WorldHealth Organization">WHO</abbr> was
founded in 1948.</p>
Example
<p>The HTML cite element defines the title of a work.</p>
<p>Browsers usually display cite elements in italic.</p>
16
NABIIKHAN OFFICIAL HTML NOTES
<img src="img_the_scream.jpg" width="100" height="100"
alt="The Scream">
<p><cite>The Scream</cite> by Edvard Munch. Painted in
1893.</p>
HTML Comments
Comment tags are used to insert comments in the HTML source
code.
HTML Comment Tags
You can add comments to your HTML source by using the following
syntax:
<!-- Write your comments here -->
HTML <bdo> for Bi-Directional Override
Notice that there is an exclamation point (!) in the opening tag, but not
The HTML <bdo> element defines bi-directional override. in the closing tag.
The <bdo> element is used to override the current text direction:
Note: Comments are not displayed by the browser, but they can help
Example document your HTML source code.
<p>If your browser supports bi-directional override (bdo), the next line With comments you can place notifications and reminders in your
will be written from right to left (rtl):</p> HTML:
Example
<bdo dir="rtl">This text will be written from right to left</bdo> <!-- This is a comment -->
<p>This is a paragraph.</p>
Example
<!-- Do not display this image at the moment
<img border="0" src="pic_trulli.jpg" alt="Trulli">
-->
HTML Colours
HTML colors are specified using predefined color names, or RGB, HEX,
HSL, RGBA, HSLA values.
Color Names
In HTML, a color can be specified by using a color name. HTML
supports 140 standard color names.
Background Color
You can set the background color for HTML elements:
Example
<h1 style="background-color:Tomato;">Tomato</h1> <h1 style="background-color:DodgerBlue;">Hello World</h1>
<h1 style="background- Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
color:MediumSeaGreen;">MediumSeaGreen</h1> suscipit lobortis nisl ut aliquip ex ea commodo consequat. </p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam Hello World
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation Hello World
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
Hello World
Text Color You can set the color of text:
Example
Color Values
In HTML, colors can also be specified using RGB values, HEX values,
<h3 style="color:Tomato;">Hello World</h3>
HSL values, RGBA values, and HSLA values.
<p style="color:DodgerBlue;">Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed diam nonummy nibh euismod Example
tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> <p>Same as color name "Tomato":</p>
<p style="color:MediumSeaGreen;">Ut wisi enim ad minim
<h1 style="background-color:rgb(255, 99, 71);">rgb(255, 99,
veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl
71)</h1>
ut aliquip ex ea commodo consequat.</p>
<h1 style="background-color:#ff6347;">#ff6347</h1>
<img src="url">
The alt Attribute
The alt attribute provides an alternate text for an image, if the user for
some reason cannot view it (because of slow connection, an error in the
src attribute, or if the user uses a screen reader). The value of
the alt attribute should describe the image:
Example
<img src="img_chania.jpg" alt="Flowers in Chania">
HTML Images Note: The alt attribute is required. A web page will not validate
correctly without it.
Images can improve the design and the appearance of a web page.
20
NABIIKHAN OFFICIAL HTML NOTES
The width and height attributes always defines the width and height of
the image in pixels.
Note: Always specify the width and height of an image. If width and
height are not specified, the page might flicker while the image loads.
Example
Images in Another Folder
If not specified, the browser expects to find the image in the same
<!DOCTYPE html> <html> <head> folder as the web page. However, it is common to store images in a
<style> sub-folder. You must then include the folder name in the src attribute:
/* This stylesheet sets the width of all images to 50%: */
21
NABIIKHAN OFFICIAL HTML NOTES
Example
<h2>Images in Another Folder</h2>
<p>It is common to store images in a sub-folder. You must then
include the folder name in the src attribute:</p>
<img src="/images/html5.gif" alt="HTML5
Icon" style="width:128px;height:128px;">
Image Floating
HTML Screen Readers
Use the CSS float property to let the image float to the right or to the A screen reader is a software program that reads the HTML code,
left of a text: converts the text, and allows the user to "listen" to the content. Screen
readers are useful for people who are visually impaired or learning
Example disabled.
<h2>Floating Images</h2>
<p><strong>Float the image to the right:</strong></p> Chapter Summary
<p>
<img src="smiley.gif" alt="Smiley face" Use the HTML <img> element to define an image
style="float:right;width:42px;height:42px;"> Use the HTML src attribute to define the URL of the image
23
NABIIKHAN OFFICIAL HTML NOTES
Use the HTML alt attribute to define an alternate text for an <area shape="rect" coords="34,44,270,350" alt="Computer" href="co
image, if it cannot be displayed mputer.htm">
Use the HTML width and height attributes to define the size of <area shape="rect" coords="290,172,333,250" alt="Phone" href="pho
the image ne.htm">
Use the CSS width and height properties to define the size of
<area shape="circle" coords="337,300,44" alt="Coffee" href="coffee.
the image (alternatively)
Use the CSS float property to let the image float htm"></map>
Image Maps
The <map> tag
defines an image-
map. An image-map
is an image with
clickable areas. Click How Does it Work?
on the computer, the The idea behind an image map is that you should be able to perform
phone, or the cup of different actions depending on where in the image you click.
coffee in the image To create an image map you need an image, and a map containing
below: some rules that describe the clickable areas.
Example
<h2>Image
The Image The image is inserted using the <img> tag. The only
difference from other images is that you must add a usemap attribute:
Maps</h2>
<p>Click on the computer, the phone, or the cup of coffee to go to a <img src="workplace.jpg" alt="Workplace" usemap=
new page and read more about the topic:</p> "#workmap">
<img src="workplace.jpg" alt="Workplace" usemap="#workmap">
<map name="workmap">
24
NABIIKHAN OFFICIAL HTML NOTES
The usemap value starts with a hash tag # followed by the name of the 1. The coordinates 34, 44 is located 34 pixels from the left margin
image map, and is used to create a relationship between the image and and 44 pixels from the top:
the image map.
Note: You can use any image as an image map. 2. The coordinates 270, 350 is located 270 pixels from the left margin
and 350 pixels from the top:
The Map Then add a <map> element. The <map> element is
used to create an image map, and is linked to the image by using
the name attribute:
<map name="workmap">
The name attribute must have the same value as the usemap attribute.
Note: You may insert the <map> element anywhere you like, it does not
have to be inserted right after the image.
The Areas Then add the clickable areas. Now you have enough data to create a clickable rectangular area:
A clickable area is defined using an <area> element. <area shape="rect" coords=
"34, 44, 270, 350" href="computer
Shape You must define the shape of the area, and you can choose .htm">
one of these values: This is the area that becomes clickable
rect - defines a rectangular region and will send the user to the page computer.htm:
circle - defines a circular region
poly - defines a polygonal region
default - defines the entire region
Circle
1. To add a circle area, first locate the coordinates of the center of
Coordinates You must define some coordinates to be able to the circle: 337, 300
place the clickable area onto the image. The coordinates come in pairs,
one for the x-axis and one for the y-axis. 2. Then specify the radius of the circle: 44 pixels
25
NABIIKHAN OFFICIAL HTML NOTES
separated by a comma. Each pair of numbers defines the (x,
y) coordinates of a point on the image. These points are all
vertices of the polygon
Chapter Summary
Use the HTML <map> element to define an image-map
Use the HTML <area> element to define the clickable areas in
the image-map
Use the HTML <img>'s element usemap attribute to point to
an image-map
You can also specify the background image in the <style> element:
Example Specify the background image in the style element:
<style>
div {
background-image: url('img_girl.jpg'); }
</style>
Background Image on a Page
If you want the entire page to have a background image, then you must
<h2>Background Image</h2>
specify the background image on the <body> element:
<div>
You can specify background images<br>
27
NABIIKHAN OFFICIAL HTML NOTES
Example Add a background image on a HTML page: background-image: url('example_img_girl.jpg'); }
<style> </style>
body { <body>
background-image: url('img_girl.jpg'); } </style> <h2>Background Repeat</h2>
<h2>Background Image</h2> <p>By default the background image will repeat itself if it is smaller
<p>By default the background image will repeat itself if it is smaller than the element where it is specified, in this case the BODY
than the element where it is specified, in this case the BODY element.</p>
element.</p>
Background Repeat
If the background image is smaller than the element, the image will
repeat itself, horizontally and vertically, until it has reach the end of the
To avoid the background image from repeating itself, use
element. To explain, see what happens when we use a small image as a
the background-repeat property.
background inside a large div element: The background-image property
will try to fill the div element with images until it has reach the end. Example
Example <style>
<style> body {
body { background-image: url('example_img_girl.jpg');
background-repeat: no-repeat; } </style>
28
NABIIKHAN OFFICIAL HTML NOTES
Background Cover
If you want the background image cover the entire element, you can
set the background-size property to cover. Also, to make sure the entire
Background Stretch
element is always covered, set the background-attachment property to If you want the background image stretch to fit the entire image in the
fixed: As you can see, the image will cover the entire element, with no element, you can set the background-size property to 100% 100%:
stretching, the image will keep its original proportions. Try resizing the browser window, and you will see that the image will
Example stretch, but always cover the entire element.
<style> Example
body { <style>
background-image: url('img_girl.jpg'); body {
background-repeat: no-repeat; background-image: url('img_girl.jpg');
background-attachment: fixed; background-repeat: no-repeat;
background-size: cover; } </style> background-attachment: fixed;
<body> background-size: 100% 100%; } </style>
</style> <body>
<h2>Background Cover</h2> <h2>Background Stretch</h2>
<p>Set the background-size property to "cover" and the background <p>Set the background-size property to "100% 100%r" and the
image will cover the entire element, in this case the BODY background image will be stretched to cover the entire element, in this
element.</p> </body> </html> case the BODY element.</p> </body> </html>
29
NABIIKHAN OFFICIAL HTML NOTES
and/or device. Each <source> element have attributes describing when
their image is the most suitable.
Syntax
Show different images on different screen sizes:
<picture>
<source media="(min-width: 650px)" srcset="img_food.jpg">
<source media="(min-width: 465px)" srcset="img_car.jpg">
<img src="img_girl.jpg">
</picture>
Example
<head>
<meta name="viewport" content="width=device-width, initial-
scale=1.0"> </head> <body>
<h2>The picture Element</h2>
<picture>
Numbers:
<ol type="1">
Ordered HTML List <li>Coffee</li>
<li>Tea</li>
An ordered list starts with the <ol> tag. Each list item starts with
<li>Milk</li>
the <li> tag. The list items will be marked with numbers by default:
</ol>
Example
<ol>
<li>Coffee</li>
<li>Tea</li> Uppercase Letters:
<li>Milk</li> <ol type="A">
</ol> <li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Ordered HTML List - The Type Attribute
The type attribute of the <ol> tag, defines the type of the list item
marker:
Type Description
Lowercase Letters:
<ol type="a">
type="1" The list items will be numbered with numbers (default) <li>Coffee</li>
<li>Tea</li>
type="A" The list items will be numbered with uppercase letters <li>Milk</li>
</ol>
type="a" The list items will be numbered with lowercase letters
37
NABIIKHAN OFFICIAL HTML NOTES
Last name: <input Defines a submit button (for submitting the form)
Doe type="submit">
Submit
Text Fields
<input type="text"> defines a single-line input field for text
The <form> Element input.
The HTML <form> element defines a form that is used to collect user Example
input: A form with two text input fields:
<!DOCTYPE html>
<form> <html> <body>
form elements <h2>Text input fields</h2>
</form> <form>
<label for="fname">First name:</label><br>
An HTML form contains form elements. <input type="text" id="fname" name="fname" value="John"><br>
Form elements are different types of input elements, like: text fields, <label for="lname">Last name:</label><br>
checkboxes, radio buttons, submit buttons, and more. <input type="text" id="lname" name="lname" value="Doe">
</form>
The <input> Element <p>Note that the form itself is not visible.</p>
The <input> element is the most important form element. <p>Also note that the default width of text input fields is 20
The <input> element is displayed in several ways, depending on characters.</p>
the type attribute. Here are some examples: </body>
You will learn a lot more about input types later in this tutorial. </html>
40
NABIIKHAN OFFICIAL HTML NOTES
Radio Buttons
<input type="radio"> defines a radio button.
Radio buttons let a user select ONE of a limited number of choices.
Example
A form with radio buttons:
<form>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<input type="radio" id="other" name="gender" value="other">
This is how it will look like in a browser: <label for="other">Other</label>
</form>
Note: The form itself is not visible. Also note that the default width of
an input field is 20 characters. This is how the HTML code above will be displayed in a browser:
Male
The <label> Element Female
Notice the use of the <label> element in the example above.
The <label> tag defines a label for many form elements. Other
The <label> element is useful for screen-reader users, because the
screen-reader will read out load the label when the user is focused on The Submit Button
the input element. <input type="submit"> defines a button for submitting the
The <label> element also help users who have difficulty clicking on
form data to a form-handler.
very small regions (such as radio buttons or checkboxes) - because
The form-handler is typically a page on the server with a script for
when the user clicks the text within the <label> element, it toggles the processing input data.
radio button/checkbox. The form-handler is specified in the form's action attribute.
The for attribute of the <label> tag should be equal to the id attribute of
the <input> element to bind them together. Example
A form with a submit button:
41
NABIIKHAN OFFICIAL HTML NOTES
<form action="/action_page.php">
<label for="fname">First name:</label><br>
The Target Attribute
<input type="text" id="fname" name="fname" value="John"><br> The target attribute specifies if the submitted result will open in a new
<label for="lname">Last name:</label><br> browser tab, a frame, or in the current window.
The default value is "_self" which means the form will be submitted in
<input type="text" id="lname" name="lname" value="Doe"><br><br
the current window.
> To make the form result open in a new browser tab, use the value
<input type="submit" value="Submit"> "_blank".
</form>
Example Here, the submitted result will open in a new browser
This is how the HTML code above will be displayed in a browser: tab:
First name:
<form action="/action_page.php" target="_blank">
John
Last name:
Doe
Submit
<form action="/action_page.php">
If the action attribute is omitted, the action is set to the current page.
42
NABIIKHAN OFFICIAL HTML NOTES
Other legal values are "_parent", "_top", or a name representing the OR:
name of an iframe.
Example
The Method Attribute Use the POST method when submitting the form:
The method attribute specifies the HTTP method (GET or POST) to <form action="/action_page.php" method="post">
be used when submitting the form data.
Example
Use the GET method when submitting the form:
If the type attribute is omitted, the input field gets the default type:
"text".
All the different input types are covered in the next chapter: HTML
Input Types.
45
NABIIKHAN OFFICIAL HTML NOTES
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
Visible Values: <option value="audi">Audi</option>
Use the size attribute to specify the number of visible values: </select>
Example
<select name="cars" size="3">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
The rows attribute specifies the visible number of lines in a text area.
The <fieldset> and <legend> Elements
The cols attribute specifies the visible width of a text area. The <fieldset> element is used to group related data in a form.
This is how the HTML code above will be displayed in a browser The <legend> element defines a caption for the <fieldset> element.
Example
Example <form action="/action_page.php">
<textarea name="message" style="width:200px; height:600px;"> <fieldset>
The cat was playing in the garden. <legend>Personalia:</legend>
</textarea> <label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
The <button> Element <input type="text" id="lname" name="lname" value="Doe"><br><br>
The <button> element defines a clickable button: <input type="submit" value="Submit">
Example </fieldset></form>
<button type="button" onclick="alert('Hello World!')">Click
Me!</button>
47
NABIIKHAN OFFICIAL HTML NOTES
<option value="Safari">
</datalist> </form>
If you omit the submit button's value attribute, the button will get a
Input Type Submit default text:
Example
<form>
<label for="datemax">Enter a date before 1980-01-01:</label>
<input type="date" id="datemax" name="datemax" max="1979-12-
31"><br><br>
<label for="datemin">Enter a date after 2000-01-01:</label>
<input type="date" id="datemin" name="datemin" min="2000-01-
02">
</form>
53
NABIIKHAN OFFICIAL HTML NOTES