HTML free notes
HTML free notes
What is HTML?
content
The <h1> element defines
HTML is the standard markup a large heading
language for creating Web The <p> element defines a
pages. paragraph
HTML stands for Hyper
Text Markup Language HTML Tags
HTML describes the TML tags are element names
structure of Web pages surrounded by angle brackets:
using markup <tagname>content goes
HTML elements are the here...</tagname>
building blocks of HTML HTML tags normally
pages come in pairs like <p>
HTML elements are and </p>
represented by tags The first tag in a pair is
HTML tags label pieces of the start tag, the second
content such as "heading", tag is the end tag
"paragraph", "table", and The end tag is written like
so on the start tag, but with
Browsers do not display a forward slash inserted
the HTML tags, but use before the tag name
them to render the content Tip: The start tag is also called
of the page the opening tag, and the end
Example Explained tag the closing tag.
The <!DOCTYPE
html> declaration defines
this document to be HTML5
Open Notepad
Open Start > Programs
The <html> element is the
> Accessories > Notepad
root element of an HTML
page
The <head> element
HTML Headings
HTML headings are defined with
contains meta information
the <h1> to <h6> tags.
about the document
<h1> defines the most
The <title> element
important heading. <h6>
specifies a title for the
defines the least important
document
heading:
Example displayed as a tooltip when you
mouse over the paragraph:
<h1>This is heading 1</h1>
<h2>This is heading 2</h2> Example
<h3>This is heading 3</h3> <p title="I'm a tooltip">
This is a paragraph.
HTML Paragraphs
</p>
HTML Links
s.com">This is a link</a>
HTML Images
provided as attributes:
HTML Horizontal
Rules
The <hr> tag defines a thematic
break in an HTML page, and is The HTML <pre>
Element
most often displayed as a
horizontal rule.
The <hr> element is used to The HTML <pre> element
separate content (or define a defines preformatted text.
change) in an HTML page: The text inside a <pre> element
Example is displayed in a fixed-width font
(usually Courier), and it
<h1>This is heading 1</h1> preserves both spaces and line
<p>This is some text.</p> breaks:
<hr>
<h2>This is heading 2</h2>
<p>This is some other
text.</p>
<hr>
HTML Styles
HTML Background
HTML Line Breaks
The HTML <br> element defines Color
a line break. The background-color property
Use <br> if you want a line defines the background color for
break (a new line) without an HTML element.
starting a new paragraph: This example sets the
background color for a page to
powderblue:
Result:-
Example
<h1 style="font-
size:300%;">This is a
heading</h1>
<p style="font-
HTML Text Color size:160%;">This is a
The color property defines the paragraph.</p>
text color for an HTML element:
HTML Text
Example
<h1 style="color:blue;">This Alignment
is a heading</h1> The text-align property defines
<p style="color:red;">This the horizontal text alignment for
is a paragraph.</p> an HTML element:
Example
Result:-
Example Example
<i>This text is italic</i> <p>My favorite color
The HTML <em> element is <del>blue</del> red.</p>
defines emphasized text, with
added semantic importance. HTML <ins>
Example Element
<em>This text is The HTML <ins> element
emphasized</em> defines inserted (added) text.
nts
<html>
<head>
<style>
You can add comments to your
HTML source by using the body {background-
following syntax: color: powderblue;}
<!-- Write your comments h1 {color: blue;}
here --> p {color: red;}
</style>
HTML Styles - </head>
<body>
CSS Fonts
powderblue;
}
<p>This is a paragraph.</p>
Example This is a paragraph.
<!DOCTYPE html>
<html>
<head>
CSS Padding
<p id="p01">I am different.</p>
The id Attribute
To define a specific style for one
special element, add an id
attribute to the element:
Example HTML Link Colors
#p01 { By default, a link will appear like
color: blue; this (in all browsers):
} An unvisited link is
underlined and blue
A visited link is underlined height:42px;border:0;">
and purple </a>
An active link is underlined
and red
You can change the default
HTML Tables
colors, by using styles:
Defining an HTML
Example
<style> Table
a:link {color:green; An HTML table is defined with
background- the <table> tag.
color:transparent; text- Each table row is defined with
the <tr> tag. A table header is
decoration:none} defined with the <th> tag. By
a:visited {color:pink; b default, table headings are bold
ackground- and centered. A table data/cell
color:transparent; text- is defined with the <td> tag.
decoration:none} Example
a:hover {color:red; ba <table style="width:100%">
ckground- <tr>
color:transparent; text- <th>Firstname</th>
decoration:underline} <th>Lastname</th>
a:active {color:yellow; <th>Age</th>
background- </tr>
<tr>
color:transparent; text- <td>Jill</td>
decoration:underline} <td>Smith</td>
</style> <td>50</td>
</tr>
<tr>
HTML Links - <td>Eve</td>
<td>Jackson</td>
Image as Link <td>94</td>
</tr>
<a href="#"> </table>
<img src="smiley.gif" alt=
"HTML Firstname Lastname Age
tutorial" style="width:42px; Jill Smith 50
Eve Jackson 94
John Doe 80 Firstname Lastname Age
Jill Smith 50
HTML Table -
Firstname Lastname Age
}
text-align: left; that Span Many
HTML Table - Cells Rows
To make a cell span more than
that Span Many one row, use
the rowspan attribute:
Columns Example
To make a cell span more than <table style="width:100%">
one column, use <tr>
the colspan attribute: <th>Name:</th>
Example <td>Bill Gates</td>
</tr>
<table style="width:100%"> <tr>
<tr> <th rowspan="2">Telephon
<th>Name</th> e:</th>
<th colspan="2">Telephon <td>55577854</td>
e</th> </tr>
</tr> <tr>
<tr> <td>55577855</td>
<td>Bill Gates</td> </tr>
<td>55577854</td> </table>
<td>55577855</td> Cell that spans two rows:
</tr>
</table> Name: Bill Gates
Cell that spans two columns:
55577854
Name Telephone Telephone:
55577855
HTML Lists
Bill Gates 55577854 55577
Unordered HTML
<li>Milk</li>
</ul>
List
Result:-
o Coffee
o Tea
An unordered list starts with
o Milk
the <ul> tag. Each list item
starts with the <li> tag. Example - Square
The list items will be marked
<ul style="list-style-
with bullets (small black circles)
type:square">
by default:
<li>Coffee</li>
Example <li>Tea</li>
<ul> <li>Milk</li>
<li>Coffee</li> </ul>
<li>Tea</li> Result:-
<li>Milk</li> Coffee
Tea
</ul>
Milk
Result
Coffee Example - None
Tea
<ul style="list-style-
Milk
type:none">
Example - Disc <li>Coffee</li>
<ul style="list-style- <li>Tea</li>
type:disc"> <li>Milk</li>
<li>Coffee</li> </ul>
<li>Tea</li> Coffee
<li>Milk</li> Tea
</ul> Milk
Result:-
Coffee
Ordered HTML List
Tea An ordered list starts with
Milk the <ol> tag. Each list item
starts with the <li> tag.
Example - Circle The list items will be marked
<ul style="list-style- with numbers by default:
type:circle">
<li>Coffee</li>
Example
<li>Tea</li> <ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol> Uppercase Roman
Result:-
1. Coffee
Numbers:
<ol type="I">
2. Tea
3. Milk <li>Coffee</li>
<li>Tea</li>
Numbers: <li>Milk</li>
<ol type="1"> </ol>
<li>Coffee</li> Result:-
<li>Tea</li> I. Coffee
<li>Milk</li> II. Tea
</ol> III. Milk
1. Coffee
2. Tea
Lowercase Roman
3. Milk Numbers:
Uppercase Letters: <ol type="i">
<ol type="A"> <li>Coffee</li>
<li>Coffee</li> <li>Tea</li>
<li>Tea</li> <li>Milk</li>
<li>Milk</li> </ol>
Result:-
</ol>
i. Coffee
Result:-
ii. Tea
A. Coffee
iii. Milk
B. Tea
C. Milk
HTML Description
Lowercase Letters:
<ol type="a"> Lists
<li>Coffee</li> HTML also supports description
<li>Tea</li> lists.
<li>Milk</li> A description list is a list of
</ol> terms, with a description of each
Result:- term.
a. Coffee The <dl> tag defines the
b. Tea description list, the <dt> tag
c. Milk defines the term (name), and
the <dd> tag describes each
term:
Example One popular way is to style a list
horizontally, to create a menu:
<dl>
<dt>Coffee</dt> Example
<dd>- black hot drink</dd> <!DOCTYPE html>
<dt>Milk</dt> <html>
<dd>- white cold <head>
drink</dd> <style>
</dl> ul {
Result:- list-style-type: none;
Coffee margin: 0;
- black hot drink padding: 0;
Milk overflow: hidden;
- white cold drink background-
<div class="cities">
Attribute <h2>Paris</h2>
<p>Paris is the capital and
Using The class most populous city of
France.</p>
Attribute
</div>
</body>
The HTML class attribute makes
</html>
it possible to define equal styles
for elements with the same class
name.
Using The class Iframe Syntax
Attribute on Inline
An HTML iframe is defined with
the <iframe> tag:
<iframe src="URL"></iframe>
Elements
<!DOCTYPE html> Iframe - Set
<html>
<head> Height and Width
<style>
span.note {
Example
font-size: 120%; <iframe src="demo_iframe.htm
color: red; " height="200" width="300"><
} /iframe>
</style> Result:-
</head>
<body>
Entities Example
<p>I will display €</p>
HTML entities were described in
<p>I will display
the previous chapter.
€</p>
Many mathematical, technical,
<p>I will display
and currency symbols, are not
€</p>
present on a normal keyboard.
To add such symbols to an HTML Will display as:
page, you can use an HTML I will display €
entity name. I will display €
If no entity name exists, you
I will display €
can use an entity number, a
What Is XHTML?
<input type="text"
name="lastname"
XHTML stands for value="Mouse">
EXtensible HyperText Mar <br><br>
kup Language <input type="submit"
XHTML is almost identical value="Submit">
to HTML </form>
XHTML is stricter than Result:-
HTML
XHTML is HTML defined as
an XML application
XHTML is supported by all
major browsers
Why XHTML?
Many pages on the internet
contain "bad" HTML. Text Input
This HTML code works fine in <input type="text"> defines
most browsers (even if it does a one-line input field for text
not follow the HTML rules): input:
Input
<input type="submit" value
="Submit">
<input type="radio"> defines </form>
a radio button.
Radio buttons let a user select
ONE of a limited number of
choices:
Example
<form> Grouping Form
<input type="radio" name="
gender" value="male" checked Data with
> Male<br>
<input type="radio" name=" <fieldset>
gender" value="female"> Fema The <fieldset> element is used
le<br> to group related data in a form.
<input type="radio" name=" The <legend> element defines a
gender" value="other"> Other caption for the <fieldset>
</form> element.
Result:- Example
<form action="action_page.ph
p">
<fieldset>
<textarea>
The <select> Element
Element The <textarea> element defines
a multi-line input field (a text
The <select> element defines
area):
a drop-down list:
Example Example
<textarea name="message" row
<select name="cars">
s="10" cols="30">
<option value="volvo">Volv
The cat was playing in the
o</option>
garden.
<option value="saab">Saab<
</textarea>
/option>
value="audi">Audi</option>
<option value="fiat">Fiat<
</select>
/option>
<br><br>
<option value="audi">Audi<
<input type="submit">
/option>
</form>
</select>
Result:-
Result:-
selected attribute.
<form
action="action_page.php">
<select name="cars">
<option
value="volvo">Volvo</option>
<option
value="saab">Saab</option>
<option value="fiat"
selected>Fiat</option>
The <button> HTML Input
Element
The <button> element defines a Types
Input Type Text
clickable button:
Example <input type="text"> defines
<button type="button" onclic a one-line text input field:
k="alert('Hello
World!')">Click Me!</button> Example
<form>
First name:<br>
HTML5 <datalist> <input type="text" name="f
irstname"><br>
Element Last name:<br>
<input type="text" name="l
The <datalist> element astname">
specifies a list of pre-defined </form>
options for an <input> element. Result:
Users will see a drop-down list
of the pre-defined options as
they input data.
Example
<form action="action_page.ph
p">
<input list="browsers">
<datalist id="browsers">
Input Type
<option value="Internet
Explorer">
Password
<option value="Firefox"> <input
type="password"> defines
<option value="Chrome">
a password field:
<option value="Opera">
<option value="Safari"> Example
</datalist> <form>
</form> User name:<br>
Result:- <input type="text" name="u
sername"><br>
User password:<br>
Input Type Radio
<input type="password" nam
e="psw">
</form> <input type="radio"> defines
Result:- a radio button.
Radio buttons let a user select
ONLY ONE of a limited number
of choices:
Example
Input Type Reset <form>
<input type="reset"> defines <input type="radio" name="
a reset button that will reset all gender" value="male" checked
form values to their default > Male<br>
values: <input type="radio" name="
Example
gender" value="female"> Fema
le<br>
<form action="action_page.ph <input type="radio" name="
p"> gender" value="other"> Other
First name:<br> </form>
<input type="text" name="f Result:-
irstname" value="Mickey"><br
>
Last name:<br>
<input type="text" name="l
astname" value="Mouse"><br><
br>
<input type="submit" value
="Submit">
Input Type
<input type="reset">
</form>
Checkbox
<input
Result:-
type="checkbox"> defines
a checkbox.
Checkboxes let a user select
ZERO or MORE options of a
limited number of choices.
Example
<form>
<input type="checkbox" nam
e="vehicle1" value="Bike"> I
have a bike<br> tep="10" value="30">
<input type="checkbox" nam </form>
e="vehicle2" value="Car"> I Result:-
have a car
</form>
Input Restrictions
a color picker can show up in
the input field.
Here is a list of some common
input restrictions (some are new
Example
in HTML5): <form>
Select your favorite
Example color:
<form> <input type="color" name="
Quantity: favcolor">
<input type="number" name= </form>
"points" min="0" max="100" s Result:-
Input Type
Input Type Range
The <input type="range"> is Week
used for input fields that should The <input
contain a value within a range. type="week"> allows the
Depending on browser support,
the input field can be displayed
user to select a week and
as a slider control. year.
Depending on browser
Example support, a date picker can
<form> show up in the input field.
<input type="range" name="
points" min="0" max="10"> Example
</form> <form>
Result:-
Select a week:
<input type="week" nam
e="week_year">
Input Type Month </form>
The <input Result:-
type="month"> allows the user
to select a month and year.
Depending on browser support,
a date picker can show up in the
Input Type Time
input field. The <input
type="time"> allows the
Example user to select a time (no
<form>
Birthday (month and year): time zone).
<input type="month" name=" Depending on browser
bdaymonth"> support, a time picker can
</form> show up in the input field.
Result:-
Example
<form>
Select a time:
<input type="time" nam
e="usr_time">
</form>
Example
Result:- <form>
E-mail:
<input type="email" na
Input Type me="email">
</form>
Datetime-local Result:-
The <input
type="datetime- Input Type
local"> specifies a date
and time input field, with no
time zone.
Search
The <input
Depending on browser
type="search"> is used
support, a date picker can
for search fields (a search
show up in the input field.
field behaves like a regular
Example text field).
<form> Example
Birthday (date and
<form>
time):
Search Google:
<input type="datetime-
<input type="search" n
local" name="bdaytime">
ame="googlesearch">
</form>
</form>
Result:-
Result:-
<form>
Add your homepage:
<input type="url" name
="homepage">
</form> The readonly
Attribute
Result:-
HTML Input
The readonly attribute
specifies that the input field
is read only (cannot be
Attributes changed):
Example
<form action="">
First name:<br>
<input type="text" name=
"firstname" value="John"
readonly>
</form>
Example
Result:- <form action="">
First name:<br>
<input type="text" name=
"firstname" value="John"
size="40">
The disabled </form>
Result:-
Attribute
The disabled attribute
The maxlength
specifies that the input field
is disabled
Example Attribute
<form action="">
The maxlength attribute
First name:<br>
specifies the maximum
<input type="text" name=
allowed length for the input
"firstname" value="John"
field:
disabled>
</form> Example
Result:- <form action="">
First name:<br>
<input type="text" name=
"firstname" maxlength="1
0">
The size </form>
Result:-
Attribute
The size attribute specifies
the size (in characters) for
the input field:
The list
one value in the <input>
element.
The multiple attribute works
Attribute with the following input
The list attribute refers to a types: email, and file.
<datalist> element that Example
contains pre-defined options A file upload field that
for an <input> element. accepts multiple values:
Example Select
An <input> element with images: <input type="fil
pre-defined values in a e" name="img" multiple>
<datalist>: Result:-
<input list="browsers">
The multiple
Result:-
Attribute
The multiple attribute
specifies that the user is
The step Attribute
allowed to enter more than
Example: if step="3",
legal numbers could be -
3, 0, 3, 6, etc. Example
An input field with a
specified legal number
intervals:
<input type="number" nam
e="points" step="3">
Result:-