Chapter 2.part1
Chapter 2.part1
Introduction to HTML5
Structure and Formatting
Introduction
HTML5 (HyperText Markup Language 5) specifies the
structure and content of documents that are displayed in
web browsers.
Web development incorporates a lot of languages and
technologies, but HTML is the foundation. Here we show you
HTML5, the latest incarnation of HTML, and describe how it’s
used to form the basic skeleton of your pages.
Weintroduce some basics, then cover more sophisticated
HTML5 techniques such as:
tables which are particularly useful for structuring
information from databases
forms for collecting information from web-page visitors
internal linking for easier page navigation
meta elements for specifying information about a
document
HTML Structure
In order to learn how to write web pages, it is very
important to understand how to structure documents.
There are three main concepts of HTML:
Tags
Elements
Attributes
HTML Page Structure
HTML Tags
InHTML, tags act like containers. They tell you something
about the information that lies between their opening and
closing tags.
HTML tags are element names surrounded by angle brackets:
Examples:
The lang Attribute: The language of the document can
be declared in the <html> tag.
Create your first web page
Using Notepad++
Text Editor: Editing HTML5
We’ll create HTML5 documents by typing HTML5
markup text in a text editor, like Notepad++, and saving
it with the .html or .htm filename extension.
Start up Notepad or Notepad++
Save as .html or .htm
Open with browser
If it doesn't look like web page, find the file you just
created on your computer and make sure that it has the
file extension .html (if it is .txt then you need to go back
to Notepad and save the file again)
It’s important that your filename has no spaces and ends
with the .html extension.
https://notepad-plus-plus.org
Web Browser: Viewing HTML
Docs
The purpose of a web browser (Chrome, IE, Firefox,
Safari) is to read HTML documents and display them.
Thebrowser does not display the HTML tags, but uses
them to determine how to display the document.
Looking at site code
You can look at your or other websites code, by inspect
element or view source code.
HTML documents
AllHTML documents must start with a document type
declaration: <!DOCTYPE html>
DOCTYPE declaration tells a browser which version of
HTML the page is using, and helps the browser to render
the page correctly
Itmust only appear once, at the top of the page (before
any HTML tags).
The HTML document itself begins with <html> and ends
with </html>
The visible part of the HTML document is between
<body> and </body>.
Head & Body Sections
Head Section
Contains information that describes the Web page document
<head>
…head section info goes here
</head>
Body Section
Contains text and elements that display in the Web page
document/ The visible part of the document
<body>
…body section info goes here
</body>
14
The HTML <head> Element
The <head> element is a container for metadata.
HTML metadata is data about the HTML document.
Metadata is not displayed.
<meta> tag is a single tag.
The <head> element also contains the document title. The
contents of the <title> element is shown in the top of the
browser.
The Heading Element
16
The <p> tag
Paragraphelement
<p> …paragraph goes here… </p>
17
The <br > tag
Line Break element
◦ Stand-alone tag
18
The <hr > tag
Horizontal Rule element
◦ Stand-alone tag
19
Logical Style
Elements
Indicate the logical style of the text display
<strong>This is important</strong>
◦ <em>…</em>
To cause text to be emphasized in relation to other text on the
page. Usually italics.
<em>Please note</em>
20
Physical Style Elements
Provide browser font configuration info
◦ Useful for browsers – but not always applicable for other devices or user
agents such as screen readers
◦ <i>…</i>
To display text in italics
<i>Please note</i>
◦ <u>…</u>
To display as underlined text
<u>This text will be underlined</u>
21
<sup> and <sub> Elements
◦ <sup>…</sup>
The <sup> element is used to contain characters that
should be superscript such as raising a number to a
power such as x2.
x <sup>2</sup>
◦ <sub>…</sub>
The <sub> element is used to contain characters that
should be subscript. It is commonly used with foot
notes or chemical formulas such as H20.
H <sub>2</sub> O
22
Special Characters
Display special characters such as quotes, copyright symbol,
etc.
Character Code
© ©
< <
> >
& &
“ "
space
23
Comments and <div> tags
To insert a comment into your code, use the comment tag
<!-- YOUR COMMENT HERE -->,
Example:
<div>
<h1>This is a heading in a div element</h1>
<p>This is some text in a div element.</p>
</div> 24
Summary
HTML pages are text documents.
HTML uses tags (characters that sit inside angled
brackets) to give the information they surround special
meaning.
Tags are often referred to as elements.
Tags usually come in pairs. The opening tag denotes the
start of a piece of content; the closing tag denotes the
end.
Opening tags can carry attributes, which tell us more
about the content of that element.
Attributes require a name and a value.
To learn HTML you need to know what tags are
available for you to use, what they do, and where they
can go.
HTML Lists
Types of lists:
Unordered lists generally contain bullet points. They’re used
when the order of elements in the list isn’t important.
Ordered lists usually have some kind of numeric counter
preceding each list item.
HTML Unordered Lists
An unordered list starts with the <ul> tag.
Each list item is placed between an <li> and </li> tag, Li stands for list item.
The list items will be marked with bullets (disc) by default.
Browsers indent lists by default.
HTML Unordered Lists
The type html attribute in the <ul> open tag is used to define
the style of the list item marker (the type of bullet point).
Can also be defined using CSS list-style-type property with
the same following values:
HTML Unordered Lists
HTML Ordered Lists
An ordered list starts with the <ol> tag.
Each list item starts with the <li> tag.
The list items will be marked with numbers by default.
HTML Ordered Lists
Sometimes you may see a type attribute used with the element to specify the
type of numbering (numbers, letters, roman numerals and so on).
It is better to use the CSS
The type attribute of the <ol> tag, defines the type of the list item marker:
HTML Ordered Lists
Numbers
HTML Ordered Lists
Uppercase Letters
HTML Ordered Lists
Lowercase Letters
i
HTML Ordered Lists
The start attribute of the <ol> tag, defines where the counting should start.
The value of the start attribute is always a number, for example we don’t say
start=“B” for an uppercase letters list.
Browsers display
nested lists indented
further than the
parent list.
In nested unordered
lists, the browser will
usually change the
style of the bullet
point too.
Notice that the </li> closing tag that contains the nested list, comes after the closing tag of the nested
list itself (</ul>), as the whole list is considered as a content of this item.
Exercise
Write the HTML code that creates the
following list:
Summary
Ordered lists use numbers or letters.
Unordered lists use bullets.
Lists can be nested inside one another.
HTML Navigation
Hyperlinks
HTML - HyperText
Links are the defining feature of the web because they allow
you to move from one web page to another — enabling the
very idea of browsing or surfing
A hyperlink references or links to other resources, such as
HTML5 documents and images.
Web browsers typically underline hyperlinks text and color
them blue by default.
In HTML, links are defined with the anchor <a> tag.
Anchors can link to an e-mail address using a mailto: email address as the
value of the href attribute
When a user clicks this type of anchored link, most browsers launch the
default e-mail program (e.g., Microsoft Outlook or Apple Mail) to enable
the user to write an e-mail message to the linked address.
HTML Email Links-example
HTML Internal Link/Bookmark
Link to specific part of the same page
At the top of a long web page, you might want to add a list of contents that
links to the corresponding sections lower down. Or you might want to add a
link from part way down the page back to the top of it to save users from
having to scroll back to the top.
Before you can link to a specific part of a page, you need to identify the
points in the page that the link will go to (create the bookmark). You do this
using the id attribute. Then add a link to it.
add a link to the bookmark ("Useful Tips Section"), from within the same
page:
HTML External-Relative Links
When you are linking to other pages within the same site, you do not need to
specify the domain name in the URL. You can use a shorthand known as a
relative URL.
Relative URLs help when building a site on your computer because you can
create links between pages without having to set up your domain name or
hosting
This
is how the user actually navigate inside a website containing many
pages.
If
you link to the same page from two different pages you
might, therefore, need to write two different relative URLs.
Depends on from which web page the link is being added.
Directory structure
Some Relative link types
Note:in order to notice the effect, the vertical scroll bar of “aboutus.html”
page should be enabled (i.e., has large content)
Open links in a new window
By default, the page in href attribute is being loaded over the same page
(use the same browser tab), to change that use a target attribute.
Ifyou want a link to open in a new window, you can use the target attribute
on the opening <a> tag. The value of this attribute should be _blank.
Generally, you should avoid opening links in a new window, but if you do, it
is considered good practice to inform users that the link will open a new
window before they click on it.
HTML Link Colors – change default style
Bydefault, a link will appear like this (in all browsers):
An unvisited link is underlined and blue
A visited link is underlined and purple
An active link is underlined and red
59
Example
60
Summary
Links are created using the <a> element.
The <a> element uses the href attribute to indicate the
page you are linking to.
If you are linking to a page within your own site, it is
best to use relative links rather than qualified URLs.
You can create links to open email programs with an
email address in the "to" field.
You can use the id attribute to target elements within a
page that can be linked to
Exercise
Write the HTML code that creates the following content:
Link to a
wiki page
Link to send
you an email