Professional Documents
Culture Documents
Week 2 Lecture
Week 2 Lecture
• Structure of HTML
Attempt Exercises
Need Support?
Attempt Exercises
Complete Exercises
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
<p>
Hello World!
</p>
</body>
</html>
https://codepen.io/usmannaeem/pen/MZEqBz
• HTML attribute is a name=value pair that provides more information about the HTML
element.
• In XHTML, attribute values had to be enclosed in quotes; in HTML5, the quotes are
optional.
• Browsers ignore comments, unrecognisable tags, line breaks, multiple spaces, and tabs
<a href="http://www.bbc.co.uk">BBC</a>
Element Name Attribute Content
Can be text or other HTML elements
<br/>
Element Name
School of Electronic Engineering and Computer Science 10
What can you do with
Elements?
• Insert images using the <img> tag
• Any elements contained within the child are said to be descendents of the
parent element; likewise, any given child element, may have a variety of
ancestors.
Ancestor
<body>
Child Parent
<p>
<em>
HTML is <em>Fun!</em>
</p>
<h1>
<h1>This is a heading</h1>
Sibling
<div>
Descendants
<p>
This is <strong>
<strong>important</strong>
</p>
</div>
</body>
School of Electronic Engineering and Computer Science 13
Hierarchy of Elements
Descendants
<body>
Children
<em> <p>
Ancestors
<strong>
• Information about how the content should look when it is displayed in the
browser is best left to CSS (Cascading Style Sheets).
• Structure is vital
• We will examine tags that describe the basic structural information
• e.g. Articles, headings, lists, paragraphs, links, navigation, footers
• Faster
1 <!DOCTYPE html>
2 <html>
3 <head>
<meta charset="utf-8"> 5
<title>Basic HTML Page Structure</title> 6
</html>
<!DOCTYPE html>
<html>
{
<head> 3
{
Contents that is <body> 4
rendered in the
viewport of the <h1>Main heading goes here</h1>
browser </body>
</html>
School of Electronic Engineering and Computer Science 20
Inside the Head?
<meta> element: This example declares that the character encoding for the
document is UTF-8.
<meta charset="utf-8"> 5
<script src="main.js"></script> 7
https://codepen.io/usmannaeem/pen/zyEQpq
<div> confusion?
https://codepen.io/usmannaeem/pen/ebGaxZ
School of Electronic Engineering and Computer Science 24
Headings and Lines
• HTML provides six levels of heading
(<h1>, <h2>, <h3>, …), with the higher
heading number indicating a heading of
less importance.
• Be semantically accurate!
• Do not choose a heading level
because of its default presentation
https://codepen.io/usmannaeem/pen/BvweEb
• The image's URL (address) can be de ned using the src attribute.
• Default units for height and width are “picture elements” (pixels)
• Can specify percentage of client area of the browser using string such as “50%”
Text in alt attribute provides a brief Speci es the width and height
description of image’s content for of image in pixels
users are unable to see it.
School of Electronic Engineering and Computer Science 26
fi
fi
fi
Images <img>
https://codepen.io/usmannaeem/pen/QzOavM
• Links are created using the <a> element (the “a” stands for anchor).
• A link has two main parts: the destination and the label.
Label
Destination
<a href="index.html">Home</a>
https://codepen.io/usmannaeem/pen/BvwgPN
https://codepen.io/usmannaeem/pen/WLZqYG
School of Electronic Engineering and Computer Science 32
Lists <li>
• Ordered lists <ol> Collections of items that have a set order; these are by default
rendered by the browser as a numbered list.
https://codepen.io/usmannaeem/pen/YdroJM
School of Electronic Engineering and Computer Science 33
De nition Lists <dl>
• Terms being de ned are the content of the
<dt> tag
https://codepen.io/usmannaeem/pen/oJGrmm
3
<nav> 3
4 4
<article> 5 5
<section>
6
<figure> 6
7 <figcaption> 7
<aside> 8 8
9
<footer>
9
41
<header> <footer>
Most web site pages have a recognisable header and footer section.
• Typically the header contains
• site logo
• title
• horizontal navigation links, and
• perhaps one or two horizontal banners.
• <section> or <div>?
• The WHATWG speci cation warns readers that the <section> element is not a
generic container element. HTML already has the <div> element for such uses.
• Another way to help you decide whether or not to use the <section> element is
to ask yourself if it is appropriate for the element's contents to be listed explicitly in
the document's outline.
• The <figure> element can be used not just for images but for any type of essential content that
could be moved to a different location in the document.
• However:
• For instance, it makes no sense to wrap the site logo or non-essential images such as banner
ads and graphical embellishments within <figure> elements.
• Instead, only use the <figure> element for circumstances where the image (or other content)
has a caption and where the gure is essential to the content but its position on the page is
relatively unimportant.
Aside
• The <aside> element could thus be used for sidebars, pull quotes, groups of
advertising images, or any other grouping of non-essential elements.
• JavaScript - Interaction
• onClick = “turnOffTelevsion()”