UECS2094 2194 - Topic 2 - HTML - Jan 2025
UECS2094 2194 - Topic 2 - HTML - Jan 2025
TOPIC 2: HTML
UECS 2094/ UECS 2194 Web Application Development
Jan 2024
2
CONTENT
• Introduction
• Part 3 - Tables
3
INTRODUCTION TO HTML
• HTML5 - 5th version of the "HyperText Markup Language".
• The 'HTML' part contains all the content, organized into a logical
structure. This is the part that an author might be most concerned with: the
words, chapter headings, figures, diagrams, etc.
6
INTRODUCTION TO HTML
• While there have been numerous versions of HTML since its inception, our
focus in this course is the most recent version, HTML5.
• HTML5 was developed to provide more powerful and flexible ways for
developers to create dynamic Web pages.
7
• There are many ways to markup a document, but HTML borrows a technique
from an ancestor language, SGML (Standard Generalized Markup
Language), which uses angle brackets ("<" and ">") to separate the
annotations from the regular text. In HTML these annotations are called
"tags".
9
EDITORS
• You can build and edit your HTML pages by either using online editors or
editors that you can install on your machine like Visual Studio Code.
• Online editor
• https://jsbin.com/
• https://codepen.io/pen/
• Editor
• https://code.visualstudio.com/
• https://notepad-plus-plus.org/
11
ELEMENTS
• 'Elements' are the pieces themselves, i.e. a paragraph is an element, or a
header is an element, even the body is an element.
• Most elements can contain other elements, as the body element would
contain header elements and paragraph elements
12
TAGS
• 'Tags' are what we use to organize a text file (which is just a long string of characters)
such that it represents a tree of elements that make up the HTML document.
• Tags are not the elements themselves, rather they're the bits of text you use to tell
the computer where an element begins and ends.
• By using '<' and '>' as a kind of parentheses, HTML can indicate the beginning and
end of a tag, i.e. the presence of '<' tells the browser 'this next bit is markup, pay
attention’.
• The browser needs to be able to distinguish between the end of the current tag or
the beginning of a new tag (representing a nested element). This is done by adding
a '/' right after the '<' to indicate that it's a 'close tag'.
13
TAGS
14
TAGS
• Most tags have open and close versions, but there are a few strange ones.
We'll learn more about these later, but we generally refer to the strange ones
as "self closing" tags.
COMMENTS
• Computers are great at reading computer languages, but it's not always
easy for humans.
• Comments are a way of adding some text that is primarily targeted towards
human readers.
COMMENTS
17
ATTRIBUTES
• A given element on your Web page can be distinguished by any number of
unique or common attributes. You can identify it uniquely with an id
attribute, or group it with a class of other elements by setting the class
attribute. (More info in part 2)
• Best practice is to name these things to increase clarity, consistency and
brevity.
18
• For example, you could streamline HTML so that whenever you see a <p>
tag, you start a new paragraph, no close tag needed. That might work most
of the time, but that would prevent you from nesting one element inside
another, as the browser could not know if you meant the new element to be
nested or a successor.
19
• A browser, on the other hand, has difficulty with a task like that, so it is helpful
to use a close tag that matches the open tag to make things absolutely
clear.
20
• That's why the first thing you need in any HTML file is a tag to tell you what
type of HTML file it is:
22
• Nearly every HTML document has two parts. The body is the main content of
the page, containing text, images, tables and so on. The head comes before
the body (on top). It is where you put information about the document that
does not really go in the body, AKA 'meta-' information.
23
MORE ON TAGS
• Until here we have learned about:
• <!doctype> - It is there to declare exactly what type of HTML the
computer will find in this file. It is used as that: <!DOCTYPE html>
• <html> - This tag wrap around nearly everything in your html file (except
the doctype tag). This essentially contains all of the HTML code in the file,
which is generally everything (one big html element).
• <head> - The head element is where you put information that does not
really appear in the body of the work. For example, the <title> of the
page, which typically appears on the window containing the page, is
defined in the head section.
25
MORE ON TAGS
• <body> - The body section contains all of the content of your page,
essentially what the user sees. This could be text, pictures, links, videos, tables
and so on. There can be only one <body> element in a document.
• <p> - P is for 'paragraph', which is the tag you may use to arrange much of
your text information. Depending on the style you are using, text wrapped in
a <p> tag may be indented or have extra vertical white space before
starting. When rendered on the Web page, a p element creates a new line.
26
• An <h1> tag might be used as the title of the document (as it appears on
the page, not the same as the <title> element), or to indicate the outer
most level in a group of nested sections.
27
EXAMPLE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome</title>
</head>
<body>
<h1>A TALE OF TWO CITIES</h1>
<h2>A STORY OF THE FRENCH REVOLUTION</h2>
<h2>Book the First—Recalled to Life</h2>
<h3>I. The Period</h3>
</body>
</html>
28
• <hr> tag is an empty tag and does not require an end tag.
33
EXERCISE 1
EXERCISE 2
ATTRIBUTES
• We learned a little bit about what attributes are in the previous part. Let’s
look into it in more depth
• Here is an ordered list:
ATTRIBUTES
• What if we want the list to start from 5?
Here, using the start attribute, we made our list start with 5 instead of 1.
40
ATTRIBUTES
• Like start, we have many useful attributes that can affect your element.
<ol start="5"></ol>
<ol id="cinema" class="attribute-list" start="5"></ol>
<ol start="5" class="attribute-list"></ol>
41
THE id ATTRIBUTE
• Imagine you have two paragraph below, how are you going to identify
them?
• We need to give them each a name first so we can refer back to the
paragraphs separately. This unique name we give each element is called
an id.
<p id="para1">I am paragraph 1 and I want to be in red</p>
<p id="para2">I am paragraph 2 and I want to be in blue</p>
42
NAMING RULE OF id
• Must be of at least one character
• This means 'QuestioN' and 'question' are NOT the same. That does not mean you
can define two different IDs that only differ by case, e.g. "myid" and "MyId".
• They are different and so legal but it would be extremely confusing to do this.
43
• We can assign the same class to multiple tags, so that we can refer to the
whole group at once rather than refer to each of them one by one
44
• For example, start is an attribute for the <ol> tag and it cannot be applied on
the <p> or <h1> tags, as it is specific to only ordered lists <ol>. Another attribute
specific to the <ol> tag is reversed
SEMANTIC ELEMENTS
• Semantic HTML is HTML that concentrates on the meaning of information in
Web pages instead of its presentation or look.
• From a semantic HTML perspective, using the right tags is important. For
example, you should use <blockquote> to wrap a quote and not use a
paragraph tag and then style it to look like a quote. When you see a heading
like <h1> or <h2>, you know this is likely the start of a new sub-section or
topic.
• Semantic elements are beneficial to both the developer and browser. They
convey much more information about your HTML document's content and
structure. Communication is always welcome in any programming language.
47
SEMANTIC ELEMENTS
• This additional communication is useful for a developer who can understand
the markup structure better (when you come back to your code after a year
or pass it on to a colleague, this is going to help you and them a lot!).
• For the browser, it can better differentiate different types of data which
results in better display of content in different devices.
• Assistive technology, such as a screen reader, will read content and convey
information about the content depending on the semantic meaning, for
example, identifying headers and reading them in a different tone.
48
• <h1> to <h6> are headings. <h1> is for the most important heading
and <h6> is for the least important.
• The header can and frequently does contain headings <h1> to <h6>. In
the case of headings, they do not have be to be used within a header.
56
• Span and Div are so similar yet so different that there is an entire wikipedia
page dedicated to it. https://en.wikipedia.org/wiki/Div_and_span
• <div> and <span> serve the same purpose but should be applied at
different levels. <div> is a block level element (for a block of space)
while <span> is an inline element (for within a line or phrase).
58
<div> :EXAMPLE
<section>
<h2>Module 1</h2>
<p>This week, you will be learning about...
module 1 stuff</p>
<div class="code">
<ol>
<li>Line of code</li>
<li>Line of code</li>
</ol>
</div>
</section>
<section>
<h2>Module 2</h2>
<p>This week, you will be learning about...
module 2 stuff</p>
<div class="code">
<ol>
<li>Line of code</li>
<li>Line of code</li>
</ol>
</div>
</section>
59
<span>: EXAMPLE
THE <img>TAG
• In this age of visual culture, pictures and images make everything more
interesting and engaging.
• Here is the most basic <img> tag:
• The image tag has several attributes out of which only src and alt are
required. The rest are useful but optional attributes, but it is recommended to
set the image size by specifying its width and height.
61
EXAMPLE
65
HYPERLINKS
• A hyperlink is any text or image that takes you to another place. This can be:
• href points to the URL that the link should jump to.
• Though it is an optional attribute, without it, the <a> tag will not be a
hyperlink because it obviously has no idea where to jump to.
69
• a link to a file or page within the same Web site also known as relative URL.
<a href="contacts.html"></a>
• a link to an element on the same page. The element, is referenced using its ID.
E.g. If you want to link to a div with id='details', the corresponding anchor tag
will be:
<a href="#details"></a>
70
EXAMPLE: HYPERLINK
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
</head>
<body>
<!-- Text in a hyperlink-->
<a href="https://www.wikipedia.com/">If you click on me, I will take you to Wikipedia</a>
<!-- Paragraph in a hyperlink-->
<a href="https://www.wikipedia.com/"><p>If you click on me, I will take you to Wikipedia</p></a>
<!-- Image in a hyperlink-->
<a href="https://www.wikipedia.com/">
<img src="https://www.wikipedia.org/portal/wikipedia.org/assets/img/[email protected]"
alt="Image navigating to Wikipedia"></a>
</body>
</html>
71
EXAMPLE: HYPERLINK
72
HYPERLINK: EMAIL
• You can even use the anchor element to add your email address under the
contacts section of your Web page.
• You can also add a subject to the email.
In the same view where the link resides. _self <a href="https://wikipedia.com/" LINK will open in
target="_self"></a> same window
If no target is specified, this is the
default behavior.
In a new window or tab. This is very _blank <a href="https://wikipedia.com/" LINK will open in new
target="_blank"></a> window
convenient if you want to link the user
to a Web page without having the
current page disappear. By clicking on
the previous window or tab, they can
redirect to the page where the link is.
74
EXERCISE
Continue from Part 1 Exercise 1, improve
the HTML code the get the result as
shown on the left.
75
PART 3 - TABLES
76
TABLES
• Tables are used to arrange data in tabular format - rows and columns of
cells.
• You can put a variety of data like text, images, forms, links and even other
tables in your table.
77
TABLES
• Here is a list of all the table elements we will be learning in this section:
Type Element
Define table <table>
<table>
<caption>
<p>Table 1.0</p>
<p>Student's final exam results 2023</p>
</caption>
</table>
79
<body>
EXAMPLE
<table border=1>
<tr>
<th colspan="2">Name</th>
<th colspan="2">Age</th>
</tr>
<tr>
<td>Alexa</td>
<td>23</td>
<td>Son</td>
<td>Jim</td>
</tr>
<tr>
<td>James</td>
<td>35</td>
<td>Daughter</td>
<td>Aria</td>
</tr>
</table>
</body>
81
• Example
82
• The footer is the last table part to be specified. Rows within <tfoot> are
defined to be footer rows for the table
83
EXAMPLE
84
<audio> ELEMENT
• You can use the <audio> element to embed audio in your page. Any text
between the <audio> element will be displayed if the browser does not
support the audio element.
<audio src="sounds/flute.mp3">
Your browser does not support the audio file.
</audio>
85
<video> ELEMENT
• You can use the <video> element to embed video in your page. You can
specify the location of your video file using the src attribute
or source element (for multiple source files).
• Any text between the <video> element will be displayed if the browser does
not support the video element.
<video src="multimedia/running.mp4">
Your browser does not support the HTML5 video
element.
</video>
86
END OF TOPIC 2