HTML
HTML
10-Feb-25
What is the World Wide Web?
◼ The World Wide Web (WWW) is most often called the
Web
◼ The Web is a network of computers all over the world
◼ All the computers in the Web can communicate with
each other.
◼ All the computers use a communication standard called
HTTP (Hypertext Transfer Protocol)
2
How does the WWW work?
◼ Web information is stored in documents called Web pages
◼ Web pages are text files stored on computers called Web
servers
◼ Computers reading the Web pages are called Web clients
◼ Web clients view the pages with a program called a Web
browser
◼ Popular browsers are: Internet Explorer, Firefox, Safari,
Chrome, and Opera
◼ Other browsers are: Netscape Navigator, Omniweb, iCab,
etc.
3
How does the browser fetch pages?
4
How does the browser display pages?
5
What is an HTML File?
◼ A simple, universal mark-up language
◼ HTML stands for Hypertext Markup Language is the language
used to create a Web pages
◼ An HTML file is a text file containing small markup tags
◼ Just a series of tags that are integrated into a text document
◼ The markup tags tell the Web browser how to display the page
◼ An HTML file must have an .htm or .html file extension
◼ .html is preferred
◼ .htm extensions are used by servers on very old operating systems that can
only handle “8+3” names (eight characters, dot, three characters)
◼ Can be created in a simple text editor
◼ Using HTML, you can create a Web page with text, graphics,
sound, and video
6
HTML Tags
7
Structure of an HTML document
◼ An HTML document is • Hence, a fairly minimal
contained within <html> tags HTML document looks like
◼ It consists of a <head> and a this:
<body>, in that order <html>
◼ The <head> typically contains <head>
a <title>, which is used as the
title of the browser window <title>My Title</title>
◼ Almost all other content goes in </head>
the <body> <body>
Hello, World!
</body>
</html>
8
HTML documents are trees
html
head body
title
This will be the world’s best
web page, so please check
My Web Page back soon!
(Under construction)
9
Whitespace
◼ Whitespace is any non-printing characters (space, tab, newline,
and a few others)
◼ HTML treats all whitespace as word separators, and
automatically flows text from one line to the next, depending on
the width of the page
◼ To group text into paragraphs, with a blank line between
paragraphs, enclose each paragraph in <p> and </p> tags
◼ To force HTML to use whitespace exactly as you wrote it,
enclose your text in <pre> and </pre> tags (“pre” stands for
“preformatted”)
◼ <pre> also uses a monospace font
◼ <pre> is handy for displaying programs
10
Creating your Web pages
11
12
Text in HTML
◼ Anything in the body of an HTML document, unless marked
otherwise, is text
◼ You can emphasize a word or statement by surrounding it with
<em> and </em> tags
◼ Browsers usually display emphasis with italics
◼ You can strongly emphasize a word or statement by surrounding
it with <strong> and </strong> tags
◼ Browsers usually display strong emphasis with boldface
◼ You can put headers in your document with <h1>, <h2>, <h3>,
<h4>, <h5>, or <h6> tags (and the corresponding end tag, </h1>
through </h6>)
◼ <h1> is quite large; <h6> is very small
◼ Each header goes on a line by itself
13
Text in HTML
◼ HTML Paragraphs
◼ HTML paragraphs are defined with the <p> tag:
◼ <p style="color:red;">This is a red paragraph.</p>
◼ The title Attribute
◼ The title attribute defines some extra information about
an element.
◼ The value of the title attribute will be displayed as a
tooltip when you mouse over the element:
◼ <p title="I'm a tooltip">This is a paragraph.</p>
14
HTML Links
◼ HTML links are defined with the <a> tag:
◼ <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.
16
Lists
◼ Two of the kinds of lists in ◼ Example:
HTML are ordered, <ol> to The four main food
</ol>, and unordered, <ul> groups are:
to </ul> <ul>
◼ Ordered lists typically use <li>Sugar</li>
numbers: 1, 2, 3, ... <li>Chips</li>
◼ Unordered lists typically use <li>Caffeine</li>
bullets (•) <li>Chocolate</li>
◼ The elements of a list (either </ul>
kind) are surrounded by <li>
and </li>
17
Attributes
◼ Some markup tags may contain attributes of the form
name="value" to provide additional information
◼ Example: To have an ordered list with letters A, B, C, ...
instead of numbers, use <ol type="A"> to </ol>
◼ For lowercase letters, use type="a"
◼ For Roman numerals, use type="I"
◼ For lowercase Roman numerals, use type="i"
◼ In this example, type is an attribute
18
Images
◼ Images (pictures) are not part of an HTML page; the HTML
just tells where to find the image
◼ To add an image to a page, use:
<img src="URL" alt="text description" width="150" height="100">
◼ The src attribute is required; the others are optional
◼ The required alt attribute for the <img> tag specifies an alternate text
for an image, if the image for some reason cannot be displayed. This
can be due to slow connection, or an attribute, or if the user uses a
screen reader. error in the src
◼ The height and width attributes, if included, will improve the
display as the page is being downloaded
◼ If height or width is incorrect, the image will be distorted
◼ There is no </img> end tag, because <img> is not a container
19
Links
20
Tables
◼ Tables are used to organize information in two dimensions (rows
and columns)
◼ A <table> contains one or more table rows, <tr>
◼ Each table row contains one or more table data cells, <td>, or
table header cells, <th>
◼ The difference between <td> and <th> cells is just formatting--text in
<th> cells is boldface and centered
◼ Each table row should contain the same number of table cells
◼ To put borders around every cell, add the attribute border="1" to
the <table> start tag
21
Example table
<table border="1">
<tr>
<th>Name</th> <th>Phone</th>
</tr>
<tr>
<td>Dick</td> <td>555-1234</td>
</tr>
<tr>
<td>Jane</td> <td>555-2345</td>
</tr>
<tr>
<td>Sally</td> <td>555-3456</td>
</tr>
</table>
22
More about tables
◼ Tables, with or without borders, are excellent for arranging things
in rows and columns
◼ Wider borders can be set with border="n"
◼ Text in cells is less crowded if you add the attribute cellpadding="n" to
the <table> start tag
◼ Tables can be nested within tables, to any (reasonable) depth
◼ This is very convenient but gets confusing
◼ Tables, rows, or individual cells may be set to any background
color (with bgcolor="color")
◼ Columns have to be colored one cell at a time
◼ You can also add bgcolor="color" to the <body> start tag
23
Entities
◼ Certain characters, such as <, have special meaning in HTML
◼ To put these characters into HTML without any special meaning,
we have to use entities
◼ Here are some of the most common entities:
◼ < represents <
◼ > represents >
◼ & represents &
◼ ' represents '
◼ " represents "
◼ represents a “nonbreaking space”--one that HTML does not treat
as whitespace
24
Frames
◼ Frames are a way of breaking a browser window up into
“panes,” and putting a separate HTML page into each
pane
◼ The Java API is an example of a good use of frames
25
Framesets
◼ Frames are enclosed within a frameset
◼ Replace <body>...</body> with
<frameset>...</frameset>
◼ Within the <frameset> start tag, use the attributes:
◼ rows=row_height_value_list
◼ cols=col_width_value_list
◼ The value lists are comma-separated lists of values, where a
value is any of:
◼ value% – that percent of the height or width
◼ value – that height or width in pixels (usually a bad idea)
◼ * – everything left over (use only once)
◼ Example: <frameset cols="20%,80%">
26
Adding frames to a frameset
◼ Put as many <frame> tags within a <frameset> as
there are rows or columns
◼ <frame> is not a container, so there is no </frame> end tag
◼ Each <frame> should have this attribute:
◼ src=URL – tells what page to load
◼ Some optional tags include:
◼ scrolling="yes|no|auto" (default is "auto")
◼ noresize
◼ Within a <frameset> you can also put <noframes>Text
to display if no frames</noframes>
27
Example: The Java API
<HTML>
<HEAD>
<TITLE>Java 2 Platform SE v1.4.0</TITLE>
</HEAD>
<FRAMESET cols="20%,80%">
<FRAMESET rows="30%,70%">
<FRAME src="overview-frame.html" name="packageListFrame">
<FRAME src="allclasses-frame.html" name="packageFrame">
</FRAMESET>
<FRAME src="overview-summary.html" name="classFrame">
</FRAMESET>
<NOFRAMES>
<H2>If you see this, you have frames turned off!</H2>
</NOFRAMES>
</HTML>
28
The rest of HTML
◼ HTML is a large markup language, with a lot of options
◼ None of it is really complicated
◼ I’ve covered only enough to get you started
◼ You should study one or more of the tutorials
◼ The w3schools tutorial is among the best
◼ Your browser’s View -> Source command is a great way to
see how things are done in HTML
29
DHTML
◼ HTML sometimes has other things mixed in
◼ There is no such “thing” as DHTML (Dynamic HTML)-
-it’s a marketing term
◼ DHTML is simply HTML with several other technologies
mixed in, mostly forms, CSS, and JavaScript, all of which we
will cover
◼ DHTML has gotten a bad reputation because browsers were
so incompatible, but that’s mostly fixed now
◼ If something on an HTML page doesn’t look like HTML, it
probably isn’t--so don’t worry about it for now
30
Vocabulary
◼ WWW: World Wide Web
◼ W3C: World Wide Web Consortium
◼ HTML: Hypertext Markup Language
◼ URL: Uniform Resource Locator
31
The End
32
Who makes the Web standards?
◼ The Web standards are not made up by Microsoft, or
even Netscape
◼ The rule-making body of the Web is the W3C
◼ W3C stands for the World Wide Web Consortium
◼ W3C puts together specifications for Web standards
◼ The most essential Web standards are HTML, CSS and
XML
◼ The latest HTML standard is XHTML 1.1
33
HTML Styles - CSS
What is CSS?
Cascading Style Sheets (CSS) is used to format the layout of a webpage.
With CSS, you can control the color, font, the size of text, the spacing between
elements, how elements are positioned and laid out, what background images or
background colors are to be used, different displays for different devices and screen
sizes, and much more!
34
CSS
CSS Solved a Big Problem
HTML was NEVER intended to contain tags for formatting a web page!
HTML was created to describe the content of a web page, like:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
When tags like <font>, and color attributes were added to the HTML 3.2
specification, it started a nightmare for web developers. Development of
large websites, where fonts and color information were added to every
single page, became a long and expensive process.
To solve this problem, the World Wide Web Consortium (W3C) created
CSS.
CSS removed the style formatting from the HTML page!
35
CSS
36
CSS Syntax
Using CSS
38
Inline CSS
Inline CSS
An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the <h1> element to blue, and
the text color of the <p> element to red:
Example
39
Internal CSS
Internal CSS
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML page, within
a <style> element.
The following example sets the text color of ALL the <h1> elements (on
that page) to blue, and the text color of ALL the <p> elements to red. In
addition, the page will be displayed with a "powderblue" background
color:
40
Internal CSS
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
41
External CSS
External CSS
An external style sheet is used to define the style for many HTML pages.
To use an external style sheet, add a link to it in the <head> section of each
HTML page:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
42
External CSS
The external style sheet can be written in any text editor. The file must not
contain any HTML code, and must be saved with a .css extension.
Here is what the "styles.css" file looks like:
"styles.css"
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p {
color: red;
}
With an external style sheet, you can change the look of an entire
web site, by changing one file!
43
CSS Colors, Fonts and Sizes
<!DOCTYPE html>
<html>
CSS Colors, Fonts and Sizes <head>
<style>
h1 {
color: blue;
The CSS color property defines the text font-family: verdana;
font-size: 300%;
color to be used. }
p {
The CSS font-family property defines the color: red;
font-family: courier;
font to be used. font-size: 160%;
The CSS font-size property defines the }
</style>
text size to be used. </head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
44
CSS Border, Padding, Margin
<!DOCTYPE html>
CSS Border
<html>
The CSS border property defines a border
<head>
<style>
around an HTML element.
p{
You can define a border for nearly all border: 2px solid powderblue;
HTML elements. padding: 30px;
margin: 50px;
}
CSS Padding </style>
The CSS padding property defines a </head>
padding (space) between the text and <body>
the border.
<h1>This is a heading</h1>
</body>
</html> 45
Link to External CSS
Link to External CSS
External style sheets can be referenced with a full URL
or with a path relative to the current web page.
This example links to a style sheet located in the html folder on the current web site:
This example links to a style sheet located in the same folder as the current page:
46
Chapter Summary
Chapter Summary
•Use the HTML style attribute for inline styling
•Use the HTML <style> element to define internal CSS
•Use the HTML <link> element to refer to an external CSS file
•Use the HTML <head> element to store <style> and <link> elements
•Use the CSS color property for text colors
•Use the CSS font-family property for text fonts
•Use the CSS font-size property for text sizes
•Use the CSS border property for borders
•Use the CSS margin property for space outside the border
•Use the CSS padding property for space inside the border
47