HTML Notes + Examples
HTML Notes + Examples
Gradi Mukwasa
PAGE 1
Document Structure
Image
Tables
PAGE 2
Introduction:
What is HTML?
As the name HyperText Markup Language indicates, HTML is a markup language, not a
programming language.
HTML allows a web author to organizeand define how content should be displayed,
which means it can do things like addtext formatting; make headings, lists, and tables;
and include images and links.You can think of an HTML file as an ordinary written
document that has been carefully annotated by the author.
The “HyperText” part of the HTML acronym refers to the way links on the Web allow
you to move from one document to another in a non-linear fashion.
It is a code that describes how a webpage is formatted in html. Although HTML tags are
not visible to the end-user (i.e., the person viewing your website), they give the web
browser suggestions about how to format the content and how it should be displayed on
the page.
Document tags:
The <head></head> it’s a tag which contains information about the HTML page.
The <title></title> it’s a tag which specifies a title for the HTML page (which is shown in
the browser's title bar or in the page's tab). It is always found in between the head tags.
In the paragraph, one word, i.e. ‘Gradi' is enclosed within the <b>tag. The text enclosed
within the <b> tag is bold now. Similarly, there is another tag that behaves in the same. It
is called the <strong> tag.
You may not find any difference between <b> and <strong>, but the strong text has an extra
meaning while the bold don't.
In the paragraph above, The sentence ‘Football & Basketball' is enclosed within the <i> tag,
which makes the sentence Football & Basketball to be italic.
Similarly, there is another tag, <em>, which also define italic text, but with extra
importance. So, if we were to replace the <i> tag in the example above with <em> it would
look like:
All the HTML tags are built for a specific purpose. For example, the <p> is used to for
paragraphs and <img/> is used for images. Most of the HTML tags have additional properties
or characteristicsthat are defined by attributes. A tag may or may not havemandatory
attributes. The <img/> tag, for example, must contain srcand alt attributes. Further, you can
place height and width attributes, but they are not mandatory. Have a look at the below
HTML code:
A <img> tag is defined with two attributes - src and alt. Value for an attribute is written inside
the double-quotes. As of now, these two attributes do not have any values.
Html attributes PAGE 17
Document structure Links/Images Tables
An attributes is used to add properties to a tag. It always goes inside the opening tag.
*The attribute given to a tag is always in “ ”quotetation marks and it always have an =
equal sign to go alone with it.
* Notes sometimes bgcolor can be given it terms of the RGB codes. For example, the
RGB code for Light blue is #00ffff . However the process remains the same; <body
bgcolor=“#00ffff "> The result will be same. The RGB stands for Red, Green & Blue.
Color are originally made from Red, Green and Blue that’s why in coding it is refer to as
the RGB code.
<font size="+8"> </font> For the font size (to increase the size)
<!-- --> Comment tags allow you to place notes to yourself so that you can keep
track of elements embedded in your web pages. The web browser does not display
comments.
Html attributes PAGE 21
Document structure Links/Images Table
HTML Lists
There are two types of of HTML list:
• Unordered list (Bullet list)
• Ordered list e.g. a,b,c,d etc or i,ii,iii
Unordered (Bulleted list)
In order to create a bullet list you need to use <ul> tag. <ul> </ul>This tag is used to
specifie where the list will start. <ul> tag stands for Unordered List.
In figurre 2 above I used the <ul> tag to specific where I want my list to start. Note that
in figure 2, there’s also the <li> tag.
<li> </li> tag is used to List item; you can specify at which number the list must start.
There Figure 2, will look like this on the webpage:
• Basketball
• Soceer
• Cricket
ii)
The <a> is used to create hyperlinks in HTML. In this chapter, we will discuss how to use
the <a> tag to move from one HTML document or web page to another. Its closing tag is
</a>.
<a> tag
The <a> tag has few attributes. One of these attributes - href, is a mandatory attribute that
holds the link of the document or web page that will open when clicked. Observe the syntax
of the <a> tag.
Links PAGE 28
Document structure Text formatting Tables
The URL should be written within the quotes. The text will appear on the screen and when
clicked on it, the URL specified for the href attribute will open. Observe the following
HTML code.
In the paragraph, the word - 'here' is a hyperlink. The href is 'https://google.com'. This means
the homepage of Google will open when clicked on the hyperlink.
Links PAGE 29
Document structure Text formatting Tables
You can also move locally from one HTML document to another. In the href attribute, you
have to provide the proper path for the document you want to navigate.
In the above <a> tag, the name of a document is specified that happens to be in the same
folder. Clicking on the hyperlink will open the demo.html document.
Links PAGE 30
Document structure Text formatting Tables
Target attribute (Not examinable by ieb)
The target attribute is an optional attribute of the <a> tag. It specifies where to open the
document or web page. It can have the following four values:
• _self : To open the document or web page in the same tab/window. The target is set to
_self by default.
• _blank : To open the document or web page in a new tab/window.
• _top : To open the document or web page in the full body of the window.
• _parent : To open the document or web page in the parent frame.
Links PAGE 31
Document structure Text formatting Tables
Images
Images are the most common part of a website after the text. Today, almost every
website you visit has images. Images improve the appearance of a website and attract
more audiences.
To simply add an image, use the <img> tag. Nonetheless, it is not always just about
adding an image. The image should have proper alignment, position, and size.
<img> tag
The <img> tag has the following syntax:
The <img> tag does not have a corresponding closing. (It does have a closing tag)
Image PAGE 32
Document structure Text formatting Links/Tables
The src attribute is mandatory because it holds the URL of the image. The image can be
present locally or it can be another server. Let's discuss how to add local images in an
HTML document.
Image PAGE 33
Document structure Text Formatting Links/Tables
Normally, in an exam situation are given an image that is found inside a sub folder
within the html document. In that case you will have to “mention” the name of that sub
folder in your html document. Let’s consider the following example:
Insert the image in the 5101-2pac-art.webp found in the Image sub folder.
Answer:
It is important to include the image file extension in your html document, otherwise it
won’t display in the web browser.
Image PAGE 34
Document structure Text Formatting Links/Tables
Image size
Have a look at the following image.
Image PAGE 35
Document Structure Text Formatting Links/Tables
This is not how it should appear, right? So what do you think is wrong here? By
default, the size of the image appearing on the screen is the same as its actual size. This
image is huge in size and that is why only a portion of it is appearing on the screen. The
whole image can be seen by scrolling up and down.
To encounter such situations, the <img> tag has two attributes to set the width and height of
an image. They are simply called width and height.
Image PAGE 36
Document structure Text formatting Links/Table
The height and width are set to 30% and 50%, respectively.
Now, it looks much better.
Image PAGE 37
First Skill Text Formatting Links/Tables
alt attribute
The alt attribute is optional but it is recommended to use alt in every <img> tag.
Suppose, an image fails to load for some reason. Then what? Let's see
Image PAGE 38
First Skill Text Formatting Third Skill
Now, the user will know if there is a problem with image loading.
Image PAGE 39
First Skill Text Formatting Third Skill
Tables
Data on a web page should be represented in a proper manner. There are various ways of
representing data. We already discussed some of these ways, such as the <p> and <h1>
tags. But sometimes, we may need a better way to display data more accurately and clearly.
Tables are considered one of the best ways to represent data.
Tables arrange data in rows and columns. In HTML, the <table> tag is used to create a
table. There are few other tags and attributes that are necessary to create a proper table in
HTML. So, in this chapter we will discuss how to create a simple table in HTML.
Tables PAGE 40
Document structure Text formatting Links/Images
The <table> tag
The <table> tag alone does not display anything.
HTML has the <tr> tag and <td> tag to create a row and column, respectively.
Tables PAGE 41
Document structure Text formatting Links/Images
The <tr> and <td> tags
As mentioned, the <tr> tag creates a row. It is placed inside the <table> tag.
The above table has one row. Let's add two columns in this row using the <td> tag.
Tables PAGE 42
Document structure Text formatting Links/Images
So, this is how rows and columns are created in HTML. Let's add some content in each
column and see how the tables appear in the browser.
This does not look like a table, right? By default, a table in HTML does not have any border.
To add a border in the table we need to use the border attributes in the <table> tag:
< table border= “1” >, you chance the size to whatever number you want.
Tables PAGE 43
Document structure Text formatting Links/Images
Now it looks like a table. A second row is also added.
The colspan attribute increases the span of a cell according to the value specified.
Tables PAGE 44
Document structure Text formatting Links/Images
The first cell of the first row has colspan of 2.
Tables PAGE 45
Document structure Text formatting Links/Images
You can see that the cell now covers the area of two columns. The colspan attribute
can have any value but it should be used carefully or the result can be an unpleasant
table. Similarly, the rowspan is used to increase the span of a row.
Tables PAGE 46
Document structure Text formatting Links/Images
The <th> tag
The <th> tag is used to create a header . It behaves like the <td> tag but the content
is bold.
Tables PAGE 47
Document structure Text formatting Links/Images
The <thead> and <tbody>
The <thead> and <tbody> tags are used to group the head part and the body of the
table.
The table created has three rows - first one has headers while the other two have
columns. So the first one can be written inside the <thead> tag and others can be
written inside the <tbody> tag.
Tables PAGE 48
Document structure Text formatting Links/Images
THE END
Tables PAGE 49
Document structure Text formatting Links/Images