0% found this document useful (0 votes)
0 views

HTML5 o level note

0779357818

Uploaded by

chiripotawanda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

HTML5 o level note

0779357818

Uploaded by

chiripotawanda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

HTML5 Tutorial

 Create Static web page that will simply show


 Saved with extension htm or html created by a text editor
 Home page always be default or index with extension htm or html and is not case
sensitive (in windows) but if use lower case you will not go wrong
 Duplicated (code which some people no longer use) code should not be used
What is HTML?
 HTML is the standard markup language for creating Web pages.
 HTML stands for Hyper Text Markup Language
 HTML describes the structure of a Web page
 HTML consists of a series of elements
 HTML elements tell the browser how to display the content
 HTML elements are represented by tags
 HTML tags label pieces of content such as "heading", "paragraph", "table", and so on
 Browsers do not display the HTML tags, but use them to render the content of the
page
 To understand "HTML" from front to back, let's look at each word that makes up the
abbreviation:
Hypertext: text (often with embeds such as images, too) that is organized in order to
connect related items
Markup: a style guide for typesetting anything to be printed in hardcopy or soft copy
format
Language: a language that a computer system understands and uses to interpret
commands.
HTML determines the structure of web pages. This structure alone is not enough to
make a web page look good and interactive. So you'll use assisted technologies such
as CSS and JavaScript to make your HTML beautiful and add interactivity,
respectively

Example
<!DOCTYPE html>
<html> ‘opens the web page
<head>
<title>Page Title</title>
</head>
<body> ‘opens what people will see on the web page

<h1>This is a Heading</h1> ‘opens heading style that is big


and bold
<h2 align=“right”>This is a Heading</h2> ‘aligns the heading 2
right
<p>This is a <strong>paragraph.</p> ‘apply the bold style to
the word para

</body>
</html>
Note apply style attributes
Centre
Bold <strong text
 The <!DOCTYPE html> declaration defines this document to be HTML5
 The <html> element is the root element of an HTML page
 The <head> element contains meta information about the document
 The <title> element specifies a title for the document
 The <body> element contains the visible page content
 The <h1> element defines a large heading
 The <p> element defines a paragraph
HTML Tags
Define
(i) a tag;
 is a special word or letter surrounded by angle brackets, < and >. You use tags to
create HTML elements , such as paragraphs or links. Many elements have an opening
tag and a closing tag — for example, a p (paragraph) element has a <p> tag, followed
by the paragraph text, followed by a closing </p> tag
 HTML tags are used to hold the HTML element. HTML element holds the
content. HTML attributes are used to describe the characteristic of an HTML element
in detail. HTML tag starts with < and ends with > Whatever written within a HTML
tag are HTML elements.
 Elements are identified by tags in the text source. A tag consists of the element name
(usually an abbreviation of a longer descriptive name) within angle brackets (< >).
The browser knows that any text within brackets is hidden and not displayed in the
browser window.
 The element name appears in the opening tag (also called a start tag) and again in
the closing (or end) tag preceded by a slash (/). The closing tag works something like
an “off” switch for the element. Be careful not to use the similar backslash character
in end tags (see the tip Introducing...HTML elements).
 tags begin with the less-than (<) character and end with greater-than (>).

HTML tags are element names surrounded by angle brackets:


<tagname>content goes here...</tagname>
The tags added around content are referred to as the markup.
 HTML tags normally come in pairs like <p> and </p>
 The first tag in a pair is the start tag, the second tag is the end tag
 The end tag is written like the start tag, but with a forward slash inserted before the
tag name
Tip: The start tag is also called the opening tag, and the end tag the closing tag.

(ii) an element.

 Elements: An HTML element is an individual component of an HTML file. In


an HTML file, everything written within tags are termed as HTML elements.
 HTML element holds the content HTML element is used to indicate the term
being defined within the context of a definition phrase or sentence.
 Elements: An HTML element is an individual component of an HTML file. In an
HTML file, everything written within tags are termed as HTML elements

Elements
It is important to note that an element consists of both the content and its markup (the start and end
tags). Not all elements have content, however. Some are empty by definition, such as the img element
used to add an image to the page.

Attributes
HTML tags can contain one or more attributes.
 Attributes are added to a tag to provide the browser with more information about how the
tag should appear or behave.
 Attributes consist of a name and a value separated by an equals (=) sign, with the value
surrounded by double quotes. Here's an example, style="color:black;".
 There are 3 kinds of attributes that you can add to your HTML tags: Element-specific,
global, and event handler content attributes.
 Attribute: An attribute in HTML provides extra information about the element, and it is
applied within the start tag. An HTML attribute contains two fields: name & value.
 Attribute names and attribute values are case-insensitive. However, the World Wide Web
Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4
recommendation

Syntax

 The syntax for an attribute is as follows:

 attributename="value"

 Attributes go after the element name, separated by a space. In non-empty elements, attributes
go in the opening tag only:

 <element attributename="value">

 <tag name attribute_name= " attr_value"> content </ tag name>


<element attributename="value">Content</element>

You can also put more than one attribute in an element in any order. Just keep them separated with
spaces.

<element attribute1="value" attribute2="value">

 Most attributes take values, which follow an equals sign (=). In HTML, some attribute values can
be reduced to single descriptive words—for example, the checked attribute, which makes a
checkbox checked when a form loads. In XHTML, however, all attributes must have explicit
values (checked="checked"). You may hear this type of attribute called a Boolean
attribute because it describes a feature that is either on or off.
 A value might be a number, a word, a string of text, a URL, or a measurement, depending on the
purpose of the attribute. You’ll see examples of all of these throughout this book.
 Some values don’t have to be in quotation marks in HTML, but XHTML requires them. Many
developers like the consistency and tidiness of quotation marks even when authoring HTML.
Either single or double quotation marks are acceptable as long as they are used consistently;
however, double quotation marks are the convention. Note that quotation marks in HTML files
need to be straight (”) not curly (”).
 Some attributes are required, such as the src and alt attributes in the img element.
 The attribute names available for each element are defined in the HTML specifications; in other
words, you can’t make up an attribute for an element

The attributes that you can add to this tag are listed below.
Element-Specific Attributes
The following table shows the attributes that are specific to this tag/element.
Attribute Description

None

Global Attributes
The following attributes are standard across all HTML 5 tags.

 accesskey  hidden  lang


 class  id  spellcheck
 contenteditable  itemid  style
 contextmenu  itemprop  tabindex
 dir  itemref  title
 draggable  itemscope  translate
 dropzone  itemtype

For a full explanation of these attributes, see HTML 5 global attributes.


Event Handler Content Attributes
Event handler content attributes enable you to invoke a script from within your HTML. The
script is invoked when a certain "event" occurs. Each event handler content attribute deals
with a different event.
Here are the standard HTML 5 event handler content attributes.
 onabort  onended  onmousewheel
 oncancel  onerror  onpause
 onblur  onfocus  onplay
 oncanplay  onformchange  onplaying
 oncanplaythrough  onforminput  onprogress
 onchange  oninput  onratechange
 onclick  oninvalid  onreadystatechange
 oncontextmenu  onkeydown  onscroll
 ondblclick  onkeypress  onseeked
 ondrag  onkeyup  onseeking
 ondragend  onload  onselect
 ondragenter  onloadeddata  onshow
 ondragexit  onloadedmetadata  onstalled
 ondragleave  onloadstart  onsubmit
 ondragover  onmousedown  onsuspend
 ondragstart  onmousemove  ontimeupdate
 ondrop  onmouseout  onvolumechange
 ondurationchange  onmouseover  onwaiting
 onemptied  onmouseup
Web Browsers
The purpose of a web browser (Chrome, Edge, Firefox, Safari) is to read HTML documents
and display them.
The browser does not display the HTML tags, but uses them to determine how to display the
document:

HTML Page Structure


Below is a visualization of an HTML page structure:
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
</html>
Note: Only the content inside the <body> section (the white area above) is displayed in a
browser.
The <!DOCTYPE> Declaration
The <!DOCTYPE> declaration represents the document type, and helps browsers to display
web pages correctly.
It must only appear once, at the top of the page (before any HTML tags).
The <!DOCTYPE> declaration is not case sensitive.
The <!DOCTYPE> declaration for HTML5 is:
<!DOCTYPE html>

HTML Versions
Since the early days of the web, there have been many versions of HTML:
Version Year

HTML 1991

HTML 2.0 1995

HTML 3.2 1997

HTML 4.01 1999

XHTML 2000

HTML5 2014

HTML Editors
Write HTML Using Notepad or TextEdit
Web pages can be created and modified by using professional HTML editors.
However, for learning HTML we recommend a simple text editor like Notepad (PC) or
TextEdit (Mac).
We believe using a simple text editor is a good way to learn HTML.
Follow the steps below to create your first web page with Notepad or TextEdit.

Step 1: Open Notepad (PC)


Windows 8 or later:
Open the Start Screen (the window symbol at the bottom left on your screen).
Type Notepad.
Windows 7 or earlier:
Open Start > Programs > Accessories > Notepad

Step 1: Open TextEdit (Mac)


Open Finder > Applications > TextEdit
Also change some preferences to get the application to save files correctly. In Preferences >
Format > choose "Plain Text"
Then under "Open and Save", check the box that says "Display HTML files as HTML code
instead of formatted text".
Then open a new document to place the code.

Step 2: Write Some HTML


Write or copy some HTML into Notepad.
<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>

Step 3: Save the HTML Page


Save the file on your computer. Select File > Save as in the Notepad menu.
Name the file "index.htm" and set the encoding to UTF-8 (which is the preferred encoding
for HTML files).

You can use either .htm or .html as file extension. There is no difference, it is up to you.

Step 4: View the HTML Page in Your Browser


Open the saved HTML file in your favorite browser (double click on the file, or right-click -
and choose "Open with").
The result will look much like this:
W3Schools Online Editor
With our free online editor, you can edit the HTML code and view the result in your browser.
It is the perfect tool when you want to test code fast. It also has color coding and the ability
to save and share code with others:
Example
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>

</body>
</html>
HTML Basic Examples
Don't worry if these examples use tags you have not learned.
You will learn about them in the next chapters.

HTML Documents
All HTML documents must start with a document type declaration: <!DOCTYPE html>.
The HTML document itself begins with <html> and ends with </html>.
The visible part of the HTML document is between <body> and </body>.
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html>
HTML Headings
HTML headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important heading:
Example
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
HTML Paragraphs
HTML paragraphs are defined with the <p> tag:
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML Links
HTML links are defined with the <a> tag:
Example
<a href="https://www.w3schools.com">This is a link</a>
The link's destination is specified in the href attribute.
Attributes are used to provide additional information about HTML elements.
You will learn more about attributes in a later chapter.
examples

HTML Images
HTML images are defined with the <img> tag.
The source file (src), alternative text (alt), width, and height are provided as attributes:
Example
<img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">

HTML Buttons
HTML buttons are defined with the <button> tag:
Example
<button>Click me</button>
HTML Lists
HTML lists are defined with the <ul> (unordered/bullet list) or the <ol> (ordered/numbered
list) tag, followed by <li> tags (list items):
Example
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
HTML Elements

HTML Elements
An HTML element usually consists of a start tag and an end tag, with the content inserted in
between:
<tagname>Content goes here...</tagname>
The HTML element is everything from the start tag to the end tag:
<p>My first paragraph.</p>
Start tag Element content End tag

<h1> My First Heading </h1>

<p> My first paragraph. </p>

<br>
HTML elements with no content are called empty elements. Empty elements do not have an
end tag, such as the <br> element (which indicates a line break).
Nested HTML Elements
HTML elements can be nested (elements can contain elements).
All HTML documents consist of nested HTML elements.
This example contains four HTML elements:
Example
<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>


<p>My first paragraph.</p>

</body>
</html>
Example Explained
The <html> element defines the whole document.
It has a start tag <html> and an end tag </html>.
Inside the <html> element is the <body> element.
<html>
<body>

<h1>My First Heading</h1>


<p>My first paragraph.</p>

</body>
</html>
The <body> element defines the document body.
It has a start tag <body> and an end tag </body>.
Inside the <body> element is two other HTML elements: <h1> and <p>.
<body>

<h1>My First Heading</h1>


<p>My first paragraph.</p>

</body>
The <h1> element defines a heading.
It has a start tag <h1> and an end tag </h1>.
The element content is: My First Heading.
<h1>My First Heading</h1>
The <p> element defines a paragraph.
It has a start tag <p> and an end tag </p>.
The element content is: My first paragraph.
<p>My first paragraph.</p>
Do Not Forget the End Tag
Some HTML elements will display correctly, even if you forget the end tag:
Example
<html>
<body>

<p>This is a paragraph
<p>This is a paragraph

</body>
</html>
The example above works in all browsers, because the closing tag is considered optional.
Never rely on this. It might produce unexpected results and/or errors if you forget the
end tag.

Empty HTML Elements


HTML elements with no content are called empty elements.
<br> is an empty element without a closing tag (the <br> tag defines a line break):
Example
<p>This is a <br> paragraph with a line break.</p>
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.

HTML Is Not Case Sensitive


HTML tags are not case sensitive: <P> means the same as <p>.
The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in
HTML, and demands lowercase for stricter document types like XHTML.
At W3Schools we always use lowercase tags.
More on HTML Attributes
Attributes provide additional information about HTML elements.

HTML Attributes
 All HTML elements can have attributes
 Attributes provide additional information about an element
 Attributes are always specified in the start tag
 Attributes usually come in name/value pairs like: name="value"

The href Attribute


HTML links are defined with the <a> tag. The link address is specified in the href attribute:
Example
<a href="https://www.w3schools.com">This is a link</a>
You will learn more about links and the <a> tag later in this tutorial.

The src Attribute


HTML images are defined with the <img> tag.
The filename of the image source is specified in the src attribute:
Example
<img src="img_girl.jpg">

The width and height Attributes


HTML images also have width and height attributes, which specifies the width and height of the
image:
Example
<img src="img_girl.jpg" width="500" height="600">
The width and height are specified in pixels by default; so width="500" means 500 pixels wide.
You will learn more about images in our HTML Images chapter.

The alt Attribute


The alt attribute specifies an alternative text to be used, if an image cannot be displayed.
The value of the alt attribute can be read by screen readers. This way, someone "listening" to the
webpage, e.g. a vision impaired person, can "hear" the element.
Example
<img src="img_girl.jpg" alt="Girl with a jacket">
Try it Yourself »
The alt attribute is also useful if the image cannot be displayed (e.g. if it does not exist):
Example
See what happens if we try to display an image that does not exist:
<img src="img_typo.jpg" alt="Girl with a jacket">
The style Attribute
The style attribute is used to specify the styling of an element, like color, font, size etc.
Example
<p style="color:red">This is a paragraph.</p>

The lang Attribute


The language of the document can be declared in the <html> tag.
The language is declared with the lang attribute.
Declaring a language is important for accessibility applications (screen readers) and search engines:
<!DOCTYPE html>
<html lang="en-US">
<body>

...

</body>
</html>
The first two letters specify the language (en). If there is a dialect, add two more letters (US).
The title Attribute
Here, a title attribute is added to the <p> element. The value of the title attribute will be displayed as a
tooltip when you mouse over the paragraph:
Example
<p title="I'm a tooltip">
This is a paragraph.
</p>

We Suggest: Use Lowercase Attributes


The HTML5 standard does not require lowercase attribute names.
The title attribute can be written with uppercase or lowercase like title or TITLE.
W3C recommends lowercase in HTML, and demands lowercase for stricter document types like
XHTML.
At W3Schools we always use lowercase attribute names.

We Suggest: Quote Attribute Values


The HTML5 standard does not require quotes around attribute values.
The href attribute, demonstrated above, can be written without quotes:
Bad
<a href=https://www.w3schools.com>
Good
<a href="https://www.w3schools.com">
W3C recommends quotes in HTML, and demands quotes for stricter document types like XHTML.
Sometimes it is necessary to use quotes. This example will not display the title attribute correctly,
because it contains a space:
Example
<p title=About W3Schools>
Using quotes are the most common. Omitting quotes can produce errors.
At W3Schools we always use quotes around attribute values.

Single or Double Quotes?


Double quotes around attribute values are the most common in HTML, but single quotes can also be
used.
In some situations, when the attribute value itself contains double quotes, it is necessary to use single
quotes:
<p title='John "ShotGun" Nelson'>
Or vice versa:
<p title="John 'ShotGun' Nelson">
Chapter Summary
 All HTML elements can have attributes
 The title attribute provides additional "tool-tip" information
 The href attribute provides address information for links
 The width and height attributes provide size information for images
 The alt attribute provides text for screen readers
 At W3Schools we always use lowercase attribute names
 At W3Schools we always quote attribute values

HTML Exercises
Exercise:
Add a "tooltip" to the paragraph below with the text "About W3Schools".
Below is an alphabetical list of some attributes often used in HTML, which
you will learn more about in this tutorial:
Attribut Description
e

alt Specifies an alternative text for an image, when the image cannot be displayed

disabled Specifies that an input element should be disabled

href Specifies the URL (web address) for a link

id Specifies a unique id for an element

src Specifies the URL (web address) for an image

style Specifies an inline CSS style for an element

title Specifies extra information about an element (displayed as a tool tip)


A complete list of all attributes for each HTML element, is listed in
our: HTML Attribute Reference.
HTML Headings
Headings
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
HTML Headings
Headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least
important heading.
Example
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
Note: Browsers automatically add some white space (a margin) before
and after a heading.
Headings Are Important
Search engines use the headings to index the structure and content of
your web pages.
Users often skim a page by its headings. It is important to use headings to
show the document structure.
<h1> headings should be used for main headings, followed
by <h2> headings, then the less important <h3>, and so on.
Note: Use HTML headings for headings only. Don't use headings to make
text BIG or bold.
Bigger Headings
Each HTML heading has a default size. However, you can specify the size
for any heading with the style attribute, using the CSS font-
size property:
Example
<h1 style="font-size:60px;">Heading 1</h1>
HTML Horizontal Rules
The <hr> tag defines a thematic break in an HTML page, and is most often
displayed as a horizontal rule.
The <hr> element is used to separate content (or define a change) in an
HTML page:
Example
<h1>This is heading 1</h1>
<p>This is some text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
<hr>
The HTML <head> Element
The HTML <head> element is a container for metadata. HTML metadata is
data about the HTML document. Metadata is not displayed.
The <head> element is placed between the <html> tag and
the <body> tag:
Example
<!DOCTYPE html>
<html>

<head>
<title>My First HTML</title>
<meta charset="UTF-8">
</head>

<body>
.
.

Note: Metadata typically define the document title, character set, styles,
scripts, and other meta information.

How to View HTML Source?


Have you ever seen a Web page and wondered "Hey! How did they do
that?"
View HTML Source Code:
Right-click in an HTML page and select "View Page Source" (in Chrome) or
"View Source" (in Edge), or similar in other browsers. This will open a
window containing the HTML source code of the page.
Inspect an HTML Element:
Right-click on an element (or a blank area), and choose "Inspect" or
"Inspect Element" to see what elements are made up of (you will see both
the HTML and the CSS). You can also edit the HTML or CSS on-the-fly in
the Elements or Styles panel that opens.
HTML Exercises
Exercise:
Use the correct HTML tag to add a heading with the text "London".

<p>London is the capital city of England. It is the most


populous city in the United Kingdom, with a metropolitan area
of over 13 million inhabitants.</p>

HTML Tag Reference


W3Schools' tag reference contains additional information about these tags
and their attributes.
You will learn more about HTML tags and attributes in the next chapters of
this tutorial.
Tag Description

<html> Defines the root of an HTML document

<body> Defines the document's body

<head> A container for all the head elements (title, scripts, styles,
meta information, and more)
The head element contains descriptive information about the document
itself, such as its title, the style sheet(s) it uses, scripts, and other types of
“meta” information.

<h1> to Defines HTML headings


<h6>

<hr> Defines a thematic change in the content


For a complete list of all available HTML tags, visit our HTML Tag
Reference.
HTML Paragraphs
The HTML <p> element defines a paragraph:
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
Note: Browsers automatically add some white space (a margin) before
and after a paragraph.
HTML Display
You cannot be sure how HTML will be displayed.
Large or small screens, and resized windows will create different results.
With HTML, 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 lines when the page
is displayed:
Example
<p>
This paragraph
contains a lot of lines
in the source code,
but the browser
ignores it.
</p>

<p>
This paragraph
contains a lot of spaces
in the source code,
but the browser
ignores it.
</p>
Don't Forget the End Tag
Most browsers will display HTML correctly even if you forget the end tag:
Example
<p>This is a paragraph.
<p>This is another paragraph.
The example above will work in most browsers, but do not rely on it.
Note: Dropping the end tag can produce unexpected results or errors.

HTML Line Breaks


The HTML <br> element defines a line break.
Use <br> if you want a line break (a new line) without starting a new
paragraph:
Example
<p>This is<br>a paragraph<br>with line breaks.</p>
The <br> tag is an empty tag, which means that it has no end tag.
The Poem Problem
This poem will display on a single line:
Example
<p>
My Bonnie lies over the ocean.

My Bonnie lies over the sea.

My Bonnie lies over the ocean.

Oh, bring back my Bonnie to me.


</p>
The HTML <pre> Element
The HTML <pre> element defines preformatted text.
The text inside a <pre> element is displayed in a fixed-width font (usually
Courier), and it preserves both spaces and line breaks:
Example
<pre>
My Bonnie lies over the ocean.
My Bonnie lies over the sea.

My Bonnie lies over the ocean.

Oh, bring back my Bonnie to me.


</pre>
HTML Exercises
Exercise:
Use the correct HTML tag to add a paragraph with the text "Hello World!".
<html>
<body>

</body>
</html>

Submit Answer »
Start the Exercise

HTML Tag Reference


W3Schools' tag reference contains additional information about HTML
elements and their attributes.
Tag Description

<p> Defines a paragraph

<br> Inserts a single line break

<pre> Defines pre-formatted text


For a complete list of all available HTML tags, visit our HTML Tag
Reference.
HTML Paragraphs
The HTML <p> element defines a paragraph:
Example
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
Note: Browsers automatically add some white space (a margin) before
and after a paragraph.
HTML Display
You cannot be sure how HTML will be displayed.
Large or small screens, and resized windows will create different results.
With HTML, 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 lines when the page
is displayed:
Example
<p>
This paragraph
contains a lot of lines
in the source code,
but the browser
ignores it.
</p>

<p>
This paragraph
contains a lot of spaces
in the source code,
but the browser
ignores it.
</p>
Don't Forget the End Tag
Most browsers will display HTML correctly even if you forget the end tag:
Example
<p>This is a paragraph.
<p>This is another paragraph.
The example above will work in most browsers, but do not rely on it.
Note: Dropping the end tag can produce unexpected results or errors.

HTML Line Breaks


The HTML <br> element defines a line break.
Use <br> if you want a line break (a new line) without starting a new
paragraph:
Example
<p>This is<br>a paragraph<br>with line breaks.</p>
The <br> tag is an empty tag, which means that it has no end tag.
The Poem Problem
This poem will display on a single line:
Example
<p>
My Bonnie lies over the ocean.

My Bonnie lies over the sea.

My Bonnie lies over the ocean.

Oh, bring back my Bonnie to me.


</p>
The HTML <pre> Element
The HTML <pre> element defines preformatted text.
The text inside a <pre> element is displayed in a fixed-width font (usually
Courier), and it preserves both spaces and line breaks:
Example
<pre>
My Bonnie lies over the ocean.

My Bonnie lies over the sea.


My Bonnie lies over the ocean.

Oh, bring back my Bonnie to me.


</pre>
HTML Exercises
Exercise:

HTML Tag Reference


W3Schools' tag reference contains additional information about HTML
elements and their attributes.
Tag Description

<p> Defines a paragraph

<br> Inserts a single line break

<pre> Defines pre-formatted text


.
HTML Text Formatting
Text Formatting
This text is bold
This text is italic
This is subscript and superscript
HTML Formatting Elements
In the previous chapter, you learned about the HTML style attribute.
HTML also defines special elements for defining text with a
special meaning.
HTML uses elements like <b> and <i> for formatting output,
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
 <sup> - Superscript text
HTML <b> and <strong> Elements
The HTML <b> element defines bold text, without any extra importance.
Example
<b>This text is bold</b>
The HTML <strong> element defines strong text, with added semantic
"strong" importance.
Example
<strong>This text is strong</strong>
HTML <i> and <em> Elements
The HTML <i> element defines italic text, without any extra importance.
Example
<i>This text is italic</i>
The HTML <em> element defines emphasized text, with added semantic
importance.
Example
<em>This text is emphasized</em>
Note: Browsers display <strong> as <b>, and <em> as <i>. However,
there is a difference in the meaning of these tags: <b> and <i> defines
bold and italic text, but <strong> and <em> means that the text is
"important".
HTML <small> Element
The HTML <small> element defines smaller text:
Example
<h2>HTML <small>Small</small> Formatting</h2>
HTML <mark> Element
The HTML <mark> element defines marked/highlighted text:
Example
<h2>HTML <mark>Marked</mark> Formatting</h2>
HTML <del> Element
The HTML <del> element defines deleted/removed text.
Example
<p>My favorite color is <del>blue</del> red.</p>
HTML <ins> Element
The HTML <ins> element defines inserted/added text.
Example
<p>My favorite <ins>color</ins> is red.</p>
HTML <sub> Element
The HTML <sub> element defines subscripted text.
Example
<p>This is <sub>subscripted</sub> text.</p>
HTML <sup> Element
The HTML <sup> element defines superscripted text.
Example
<p>This is <sup>superscripted</sup> text.</p>
HTML Exercises

HTML Text Formatting Elements


Tag Description

<b> Defines bold text

<em> Defines emphasized text

<i> Defines italic text

<small> Defines smaller text

<strong> Defines important text


<sub> Defines subscripted text

<sup> Defines superscripted text

<ins> Defines inserted text

<del> Defines deleted text

<mark> Defines marked/highlighted text


.
HTML Quotation and Citation Elements
Quotation
Here is a quote from WWF's website:
For 50 years, WWF has been protecting the future of nature. The world's
leading conservation organization, WWF works in 100 countries and is
supported by 1.2 million members in the United States and close to 5
million globally.
HTML <q> for Short Quotations
The HTML <q> element defines a short quotation.
Browsers usually insert quotation marks around the <q> element.
Example
<p>WWF's goal is to: <q>Build a future where people live in
harmony with nature.</q></p>
HTML <blockquote> for Quotations
The HTML <blockquote> element defines a section that is quoted from
another source.
Browsers usually indent <blockquote> elements.
Example
<p>Here is a quote from WWF's website:</p>
<blockquote cite="http://www.worldwildlife.org/who/index.html"
>
For 50 years, WWF has been protecting the future of nature.
The world's leading conservation organization,
WWF works in 100 countries and is supported by
1.2 million members in the United States and
close to 5 million globally.
</blockquote>
HTML <abbr> for Abbreviations
The HTML <abbr> element defines an abbreviation or an acronym.
Marking abbreviations can give useful information to browsers, translation
systems and search-engines.
Example
<p>The <abbr title="World Health Organization">WHO</abbr> was
founded in 1948.</p>
HTML <address> for Contact Information
The HTML <address> element defines contact information (author/owner)
of a document or an article.
The <address> element is usually displayed in italic. Most browsers will
add a line break before and after the element.
Example
<address>
Written by John Doe.<br>
Visit us at:<br>
Example.com<br>
Box 564, Disneyland<br>
USA
</address>
HTML <cite> for Work Title
The HTML <cite> element defines the title of a work.
Browsers usually display <cite> elements in italic.
Example
<p><cite>The Scream</cite> by Edvard Munch. Painted in
1893.</p>
HTML <bdo> for Bi-Directional Override
The HTML <bdo> element defines bi-directional override.
The <bdo> element is used to override the current text direction:
Example
<bdo dir="rtl">This text will be written from right to
left</bdo>
HTML Quotation and Citation Elements
Tag Description

<abbr> Defines an abbreviation or acronym

<address> Defines contact information for the author/owner


of a document

<bdo> Defines the text direction

<blockquote> Defines a section that is quoted from another


source

<cite> Defines the title of a work

<q> Defines a short inline quotation


For a complete list of all available HTML tags, visit our HTML Tag
Reference.
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 -->
Notice that there is an exclamation point (!) in the opening tag, but not in
the closing tag.
Note: Comments are not displayed by the browser, but they can help
document your HTML source code.
With comments you can place notifications and reminders in your HTML:
Example
<!-- This is a comment -->

<p>This is a paragraph.</p>

<!-- Remember to add more information here -->


Comments are also great for debugging HTML, because you can comment
out HTML lines of code, one at a time, to search for errors:
Example
<!-- Do not display this image at the moment
<img border="0" src="pic_trulli.jpg" alt="Trulli">
-->

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:
Tomato
Orange
DodgerBlue
MediumSeaGreen
Gray
SlateBlue
Violet
LightGray
HTML supports 140 standard color names.

Background Color
You can set the background color for HTML elements:
Hello World

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Example
<h1 style="background-color:DodgerBlue;">Hello World</h1>
<p style="background-color:Tomato;">Lorem ipsum...</p>

Text Color
You can set the color of text:
Hello World
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat
volutpat.
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper
suscipit lobortis nisl ut aliquip ex ea commodo consequat.
Example
<h1 style="color:Tomato;">Hello World</h1>
<p style="color:DodgerBlue;">Lorem ipsum...</p>
<p style="color:MediumSeaGreen;">Ut wisi enim...</p>

Border Color
You can set the color of borders:
Hello World
Hello World
Hello World
Example
<h1 style="border:2px solid Tomato;">Hello World</h1>
<h1 style="border:2px solid DodgerBlue;">Hello World</h1>
<h1 style="border:2px solid Violet;">Hello World</h1>

Color Values
In HTML, colors can also be specified using RGB values, HEX values, HSL
values, RGBA values, and HSLA values:
Same as color name "Tomato":
rgb(255, 99, 71)
#ff6347
hsl(9, 100%, 64%)
Same as color name "Tomato", but 50% transparent:
rgba(255, 99, 71, 0.5)
hsla(9, 100%, 64%, 0.5)
Example
<h1 style="background-color:rgb(255, 99, 71);">...</h1>
<h1 style="background-color:#ff6347;">...</h1>
<h1 style="background-color:hsl(9, 100%, 64%);">...</h1>

<h1 style="background-color:rgba(255, 99, 71, 0.5);">...</h1>


<h1 style="background-color:hsla(9, 100%, 64%, 0.5);">...</h1>

HEX Value
In HTML, a color can be specified using a hexadecimal value in the form:
#rrggbb
Where rr (red), gg (green) and bb (blue) are hexadecimal values between
00 and ff (same as decimal 0-255).
For example, #ff0000 is displayed as red, because red is set to its highest
value (ff) and the others are set to the lowest value (00).
Example
#ff0000
#0000ff
#3cb371
#ee82ee
#ffa500
#6a5acd

Shades of gray are often defined using equal values for all the 3 light
sources:
Example
#000000
#3c3c3c
#787878
#b4b4b4
#f0f0f0
#ffffff

HSL Value
In HTML, a color can be specified using hue, saturation, and lightness
(HSL) in the form:
hsl(hue, saturation, lightness)
Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green,
and 240 is blue.
Saturation is a percentage value, 0% means a shade of gray, and 100% is
the full color.
Lightness is also a percentage, 0% is black, 50% is neither light or dark,
100% is white
Example
hsl(0, 100%, 50%)
hsl(240, 100%, 50%)
hsl(147, 50%, 47%)
hsl(300, 76%, 72%)
hsl(39, 100%, 50%)
hsl(248, 53%, 58%)

Saturation
Saturation can be described as the intensity of a color.
100% is pure color, no shades of gray
50% is 50% gray, but you can still see the color.
0% is completely gray, you can no longer see the color.
Example
hsl(0, 100%, 50%)
hsl(0, 80%, 50%)
hsl(0, 60%, 50%)
hsl(0, 40%, 50%)
hsl(0, 20%, 50%)

Lightness
The lightness of a color can be described as how much light you want to
give the color, where 0% means no light (black), 50% means 50% light
(neither dark nor light) 100% means full lightness (white).
Example
hsl(0, 100%, 0%)
hsl(0, 100%, 25%)
hsl(0, 100%, 50%)
hsl(0, 100%, 75%)
hsl(0, 100%, 90%)
hsl(0, 100%, 100%)

Shades of gray are often defined by setting the hue and saturation to 0,
and adjust the lightness from 0% to 100% to get darker/lighter shades:
Example
hsl(0, 0%, 0%)
hsl(0, 0%, 24%)
hsl(0, 0%, 47%)
hsl(0, 0%, 71%)
hsl(0, 0%, 94%)
hsl(0, 0%, 100%)

RGBA Value
RGBA color values are an extension of RGB color values with an alpha
channel - which specifies the opacity for a color.
An RGBA color value is specified with:
rgba(red, green, blue, alpha)
The alpha parameter is a number between 0.0 (fully transparent) and 1.0
(not transparent at all):
Example
rgba(255, 99, 71, 0)
rgba(255, 99, 71, 0.2)
rgba(255, 99, 71, 0.4)
rgba(255, 99, 71, 0.6)
rgba(255, 99, 71, 0.8)
rgba(255, 99, 71, 1)

HSLA Value
HSLA color values are an extension of HSL color values with an alpha
channel - which specifies the opacity for a color.
An HSLA color value is specified with:
hsla(hue, saturation, lightness, alpha)
The alpha parameter is a number between 0.0 (fully transparent) and 1.0
(not transparent at all):
Example
hsla(9, 100%, 64%, 0)
hsla(9, 100%, 64%, 0.2)
hsla(9, 100%, 64%, 0.4)
hsla(9, 100%, 64%, 0.6)
hsla(9, 100%, 64%, 0.8)
hsla(9, 100%, 64%, 1)
Yourself »
Section A

1. Online documentation often has technical words highlighted in a different colour. Clicking the
words leads to a further explanation. This is called.. 2021 p1 q
A. context-sensitive help B. highlights C. hypertext D. tool tips
2. Which of the following HTML tag will insert a line break? 2021 p1 q
A. <p/> B. <lb/> C. <br/> D. <break/>
3. Which of these instructions embedded in a web page, would cause the text following it to be
displayed in the largest letters? 2020 p1 q22
A <H1> B <H6> C <HEAD> D. <TITLE>
4. A small program designed to run in a web page is called 2020 p1 q26
A a hyperlink B an anchor C an applet D a frame
5. A ‘URL’ is formatted text string used by the browsers, email client and other software
users to identify a network resource on the internet 2019 p1 q13
A Universal Resource locator B Unlimited Resource locator
C Universal Reference link D Universal Resource link
6. A clickable link that takes you from one document to another, or to any resource, even
within the same document ,with text that is highlighted in some fashion is a 2019 p1 q35
A . URL B. locator C. protocol D. hyperlink
7. Which of the following is not a valid image file type 2019 p1 q36
A. prg B. rst C. jpg D. bmp
8. Web page contain instructions about how the test is to be displayed .The instructions are
embedded in the page as 2018 p1 q
A. anchors B. hyperlinks C. tags D. frames
9. A website makes use of multimedia. This means that it contains 2018 p1 q33
A. videos, pictures, text and sound B. text and images
C. applet and scripts D. hyperlinks and scripts
10. Which of the following tags is used to mark the beginning of a paragraph? 2018sp p1 q17
A < TD > B < br > C<P> D < TR >

Section B

11. A web page is made up of a number of essential parts which contribute to the large
whole. Name any three essential parts of a web page. 2018sp p2 q11 [3]

__________________________________________________________________________________________________________________________

__________________________________________________________________________________________________________________________

__________________________________________________________________________________________________________________________

__________________________________________________________________________________________________________________________

__________________________________________________________________________________________________________________________

12. (a) Write a statement to display a title when designing a web. 2020 p2 q8 [3]
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(b) Define
(i) a tag; [1]
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
(ii) an element. [1]
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________

13. (a) Define the terms below. 2021 p2 q12a


(i) html [1]
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
(ii) cookie [1]
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
(b) State three features found on a good website [3]
1. __________________________________________________________________
2. ___________________________________________________________________
3. __________________________________________________________________
Section A

1. Online documentation often has technical words highlighted in a different colour. Clicking
the words leads to a further explanation. This is called.. 2021 p1 q
A. context-sensitive help B. highlights C. hypertext D. tool tips
2. Which of the following HTML tag will insert a line break? 2021 p1 q
A. <p/> B. <lb/> C. <br/> D. <break/>
3. Which of these instructions embedded in a web page, would cause the text following it to be
displayed in the largest letters? 2020 p1 q22
A <H1> B <H6> C <HEAD> D. <TITLE>
4. A small program designed to run in a web page is called 2020 p1 q26
A a hyperlink B an anchor C an applet D a frame
5. A ‘URL’ is formatted text string used by the browsers, email client and other software
users to identify a network resource on the internet 2019 p1 q13
A Universal Resource locator B Unlimited Resource locator
C Universal Reference link D Universal Resource link
6. A clickable link that takes you from one document to another, or to any resource, even
within the same document ,with text that is highlighted in some fashion is a 2019 p1 q35
A . URL B. locator C. protocol D. hyperlink
7. Which of the following is not a valid image file type 2019 p1 q36
A. prg B. rst C. jpg D. bmp
8. Web page contain instructions about how the test is to be displayed .The instructions are
embedded in the page as 2018 p1 q
A. anchors B. hyperlinks C. tags D. frames
9. A website makes use of multimedia. This means that it contains 2018 p1 q33
A. videos, pictures, text and sound B. text and images
C. applet and scripts D. hyperlinks and scripts
10. Which of the following tags is used to mark the beginning of a paragraph? 2018sp p1 q17
A < TD > B < br > C<P> D < TR >

Section B

11. A web page is made up of a number of essential parts which contribute to the large
whole. Name any three essential parts of a web page. 2018sp p2 q11 [3]

 Header or Banner: Located at the top of a webpage (Website logo and Menu bar may
present in the header)
 Navigation Bar: These are usually placed below the Header/Banner bar.
 Sidebar: or a horizontal bar typically on the right side of screens that contain more links
or information. A sidebar is meant to act as another navigation facet of your site,
enabling visitors to find information that is important, but less critical than the
information in your header. Provides additional content, navigation or display ads.
 Main Body (Headings, Highlighted Content, Posts, Internal links may present in this
section)
 Content: The main part of a website will be dedicated to content, as this is the main value
of the site.
 Footer: footer is the bottom most part of any site. It usually contains a sitemap with links
to the pages available on your site. Footers also contain basic contact information, enabling
users to reach out to you or find your physical storefront. This type of information is
crucial for business success. Footers also might include a social bar that contains small but
recognizable icons that lead users to your social media pages. (Forms and Social links may
present in this section

2 (a)
Write a statement to display a title when designing a web. 2020 p2 q8 [3]
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
_______________________________________________________
(b) Define
(i) a tag; [1]
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
_______________________________________________________
(ii) an element. [1]
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
_______________________________________________________

 (a) Define the terms below. 2021 p2 q12a


(i) html [1]

 is the standard markup language for documents designed to be displayed in a web


browser.
 Hypertext Markup Language, a standardized system for tagging text files to achieve
font, colour, graphic, and hyperlink effects on World Wide Web pages.
 HTML (hypertext markup language), a formatting system for displaying material
retrieved over the Internet.
 Hypertext: text (often with embeds such as images, too) that is organized in
order to connect related items
 Markup: a style guide for typesetting anything to be printed in hardcopy or soft
copy format
 Language: a language that a computer system understands and uses to interpret
commands.
 HTML determines the structure of web pages. This structure alone is not enough to
make a web page look good and interactive. So you'll use assisted technologies such
as CSS and JavaScript to make your HTML beautiful and add interactivity,
respectively

(ii) cookie [1]

 Cookies are text files with small pieces of data — like a username and password —
that are used to identify your computer as you use a computer network.
 A small text file (up to 4KB) created by a website that is stored in the
user's computer either temporarily for that session only or permanently in storage ...
 cookie is information that a website puts on a user's computer
 HTTP cookies (also called web cookies, Internet cookies, browser cookies, or
simply cookies) are small blocks of data created by a web server while
a user is browsing a website and placed on the user's computer or other device by the
user’s web browser. Cookies are placed on the device used to access a website,

(b) State three features found on a good website [3]

 Responsive website pages. ...


 Page quality. ...
 A picture is worth a thousand words. ...
 A strong and visible call to action. ...
 Ensuring easy navigation
 Well Designed and Functional. ...
 Easy to Use. ...
 Optimized for Mobile. ...
 Fresh, Quality Content. ...
 Readily accessible contact and location. ...
 Clear calls to action. ...
 Optimized for Search and the Social Web.
 Helpful navigation. ...
 Strong brand identity. ...
 High-quality content. ...
 A blog. ...
 Clear calls-to-action. ...
 Contact information. ...
 Social media buttons. ...
 Security features. This is something that's most important to websites where
visitors may enter credit card or other sensitive information
 Landing Page. ...
 Responsive Across Devices. ...
 Ease of Use and Navigation. ...
 Contact Information. ...
 Ability to Give Feedback. ...
 Social Media Links. ...

You might also like