Basic HTML - Jacksonville University

Download Report

Transcript Basic HTML - Jacksonville University

1
Basic HTML
CS380
Hypertext Markup Language (HTML)
2




Describes the content and structure of information
on a web page
Not the same as the presentation (appearance on
screen)
Surrounds text content with opening and closing
tags
Each tag's name is called an element
 syntax:
<element> content </element>
 example: <p>This is a paragraph</p>
CS380
Structure of HTML page
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
information about the page
</head>
<body>
page contents
</body>
</html>




HTML is saved with extension .html
Basic structure: tags that enclose content, i.e., elements
Header describes the page
Body contains the page’s contents
HTML
Page Title <title>
4
…
<head>
<title> HARRY POTTER AND THE DEATHLY HALLOWS
- PART 2 </title>
</head>
…
HTML


Placed within the head of the page
Displayed in web browser’s title mark and when
bookmarking the page
CS380
Paragraph <p>
5
…
<body>
<p> Harry Potter and the Deathly Hallows,
the last book in the series, begins directly after the
events of the sixth book.
Voldemort
has completed his ascension to power and
gains
control of the Ministry of Magic</p>
</body>
…
HTML
Harry Potter and the Deathly Hallows, the last book in the series, begins
directly after the events of the sixth book. Voldemort has completed his
ascension to power and gains control of the Ministry of Magic
output

Placed within the body of the page
CS380
Headings <h1>, <h2>, … <h6>
6
<h1> Harry Potter </h1>
<h2> Books </h2>
<h3> Harry Potter and the Philosopher’s Stone </h3>
HTML
Harry Potter
Books
Harry Potter and the Philosopher’s Stone
output
CS380
Horizontal rule <hr />
7
<p> First paragraph </p>
<hr />
<p> Second Paragraph </p>
HTML
First Paragraph
Second Paragraph
output

Should be immediately closed with />
CS380
Block and Inline Statements
8

Block elements contain an entire large region of
content
 examples:
paragraphs, lists, table cells
 the browser places a margin of whitespace between
block elements for separation
CS380
Block and Inline Statements (cont.)
9

Inline elements affect a small amount of content
 examples:
bold text, code fragments, images
 the browser allows many inline elements to appear on
the same line
 must be nested inside a block element
CS380
More HTML tags
10

Some tags can contain additional information called
attributes
 syntax:
<element attribute="value" attribute="value">
content </element>
 example: <a href="page2.html">Next page</a>
CS380
More HTML tags
11

Some tags don't contain content; can be opened
and closed in one tag
 syntax:
<element attribute="value" attribute="value" />
 example: <hr />
 example:
<img src=“Harry.jpg" alt="pic of Harry Potter" />
CS380
Links <a>
12
<p>
Search
<a href="http://www.google.com/">Google</a>
now!
</p>
HTML
Search Google now!
output


The href attribute specifies the destination URL
Links or anchors are inline elements, so they must be
placed inside a block element such as a p or h1
CS380
More about anchors
13
<p><a href=“deathlyHallows-book.html">Harry Potter and the
Deathly Hallows Book</a></p>
<p><a href="http://en.wikipedia.org”
title="Search">Wikipedia</a></p>
HTML
Harry Potter and the Deathly Hallows
Wikipedia

Types of URLs that can appear in anchors:
 Absolute:
to another web site
 Relative: to another page on this web site
CS380
output
Nesting tags
14
Bad
<p>
<a href=" deathlyHallows-book.html"> Harry Potter and the
Deathly Hallows Book </p>
<p>
This text also links to Harry Potter Book</a>
</p>
HTML


Tags must be correctly nested: a closing tag must
match the most recently opened tag
The browser may render it correctly anyway, but it
is invalid XHTML
CS380
Images <img>
15
<img src="images/tobby.jpg" alt=“Tobby from Harry Potter" />
HTML


The src attribute specifies source of the image URL
XHTML also requires an alt attribute describing the
image
CS380
More about images
16
<a href="http://harrypotter.net/">
<img src="images/dumbledore.jpg" alt=“Dumbledore from Harry
Potter"
title="Alas! Ear wax!"/>
</a>
HTML


If placed inside an a anchor, the image will become
a link
The title attribute specifies an optional tooltip
Line Break <br>
17
<p>One Ring to rule them all, One Ring to find them, <br
/> One Ring to bring them all and in the darkness bind
them.</p>
<p> In the Land of Mordor where the Shadows lie. </p>
HTML
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them
In the Land of Mordor where the Shadows lie.
output


br should be immediately closed with />
br should not be used to separate paragraphs or
used multiple times in a row to create spacing
CS380
Comments <!-- … -- >
18
<!-- My web page, by Bob Student
CSE 380, Fall 2048 -->
<p>CS courses are <!-- NOT --> a lot of fun!</p>
HTML
CS courses are a lot of fun!
output


Comments are useful for disabling sections of a
page
Comments cannot be nested and cannot contain a --
CS380
Phrase elements <em>, <strong>
19
<p>
HTML is <em>really</em>,
<strong>REALLY</strong> fun!
</p>
HTML
HTML is really REALLY fun!
output



em: emphasized text (usually in italic)
strong: strongly emphasized text (usually in bold)
The tags must be properly nested for a valid page
CS380
Unordered list: <ul>, <li>
20
<ul>
<li>No shoes</li>
<li>No shirt</li>
<li>No problem!</li>
</ul>
• No shoes
• No shirt
• No problem!


ul represents a bulleted list of items (block)
li represents a single item within the list (block)
CS380
HTML
output
More about unordered lists
21
<ul>
<li>Harry Potter characters:
<ul>
<li>Harry Potter</li>
<li>Hermione</li>
<li>Ron</li>
</ul>
</li>
<li>LOTR characters:
<ul>
<li>Frodo</li>
<li>Bilbo</li>
<li>Sam</li>
</ul>
</li>
</ul>
CS380
HTML
More about unordered lists (cont.)
22
• Harry Potter characters:
• Harry Potter
• Hermione
• Ron
• LOTR characters:
• Frodo
• Bilbo
• Sam
output
CS380
Ordered list <ol>
23
<p>Apple business model:</p>
<ol>
<li>Beat Microsoft</li>
<li>Beat Google</li>
<li>Conquer the world!</li>
</ol>
Apple business model:
1. Beat Microsoft
2. Beat Google
3. Conquer the world


HTML
output
ol represents a numbered list of items
we can make lists with letters or Roman numerals
using CSS (later)
CS380
Common error: Not closing a list
24
<ul>
<li>No shoes</li>
<li>No shirt</li>
<li>No problem!</li>
<p>Paragraph after list...</p>
HTML
• No shoes
• No shirt
• No problem!
Paragraph after list...

output
If you leave a list open, subsequent contents will be
indented
CS380
Common Error: Improper nested list
placement
25
<ul>
<li>Harry Potter characters:</li>
<ul>
<li>Harry Potter</li>
<li>Hermione</li>
<li>Ron</li>
</ul>
</li>
<li>LOTR characters:
<ul>
<li>Frodo</li>
<li>Bilbo</li>
<li>Sam</li>
</ul>
</ul>

HTML
closing the outer li too early (or not at all) will render
correctly in most browsers, but it is incorrect XHTML
Definition list <dl>, <dt>, <dd>
26
<dl>
<dt>newbie</dt> <dd>one who does not have mad skills</dd>
<dt>jaded</dt> <dd>tired, bored, or lacking enthusiasm
</dd>
<dt>frag</dt> <dd>a kill in a shooting game</dd>
</dl>
HTML
newbie
one who does not have mad skills
jaded
Tired, bored, or lacking enthusiasm
frag
a kill in a shooting game


dl represents a list of definitions of terms
dt represents each term, and dd its definition
CS380
output
Tables <table>, <tr>, <td>
27
<table>
<tr><td>1,1</td><td>1,2 okay</td></tr>
<tr><td>2,1 real wide</td><td>2,2</td></tr>
</table>
1,1
1,2 okay
2,1 real wide
2,2
HTML
output



table defines the overall table, tr each row, and
td each cell's data
Useful for displaying large row/column data sets
NOTE: tables are sometimes used by novices for
web page layout, but this is not proper semantic
HTML and should be avoided
Table headers, captions: <th>,
<caption>
28
<table>
<caption>My important data</caption>
<tr><th>Column 1</th><th>Column 2</th></tr>
<tr><td>1,1</td><td>1,2 okay</td></tr>
<tr><td>2,1 real wide</td><td>2,2</td></tr>
</table>
HTML
My important data
Column 1
Column 2
1,1
1,2 okay
2,1 real wide
2,2


th cells in a row are considered headers
a caption at the start of the table labels its
meaning
output
Quotations <blockquote>
29
<p>As Lincoln said in his famous Gettysburg Address:</p>
<blockquote>
<p>Fourscore and seven years ago, our fathers
brought forth
on this continent a new nation, conceived in
liberty, and
dedicated to the proposition that all men are
created equal.</p>
</blockquote>
HTML
As Lincoln said in his famous Gettysburg Address:
Fourscore and seven years ago, our fathers brought forth on this
continent a new nation, conceived in liberty, and dedicated to the proposition
that all men are created equal.
output

a lengthy quotation
CS380
Inline quotations <q>
30
<p>Quoth the Raven, <q>Nevermore.</q></p>
HTML
Quoth the Raven, “Nevermore.”
output




a short quotation
Why not just write the following?
<p>Quoth the Raven, "Nevermore."</p>
We don't use " marks for two reasons:
 XHTML
shouldn't contain literal quotation mark
characters; they should be written as &quot;
 using <q> allows us to apply CSS styles to quotations
HTML Character Entities
31
character(s)
<>
éèñ
™©
πδΔ
И
"&
CS380
entity
&lt; &gt;
&eacute; &egrave; &ntilde;
&trade; &copy;
&pi; &delta; &Delta;
&#1048;
&quot; &amp;
Inline quotations <q>
32
&lt;p&gt;
&lt;a
href=&quot;http://google.com/search?q=xenia&amp;ie=utf8&amp;aq=t&quot;&gt;
Search Google for Xenia
&lt;/a&gt;
&lt;/p&gt;
HTML
<p> <a href="http://google.com/search?q=xenia&ie=utf-8&aq=t"> Search
Google for Xenia </a> </p>
output
CS380
Computer code <code>
33
<p>
The <code>ul</code> and <code>ol</code>
tags make lists.
</p>
HTML
The ul and ol tags make lists.
output

code: a short section of computer code
CS380
Preformatted text <pre>
34
<pre>
Bill Gates speaks
You will be assimilated
Microsoft fans delirious
</pre>
HTML
Bill Gates speaks
You will be assimilated
Microsoft fans delirious
output


Displayed with exactly the whitespace / line breaks
given in the text
Shown in a fixed-width font by default
CS380
Preformatted text <pre>
35
<pre><code>
public static void main(String[] args) {
System.out.println("Hello, world!");
}
</code></pre>
HTML
public static void main(String[] args) {
System.out.println("Hello, world!");
}
output

When showing a large section of computer code,
enclose it in a pre to preserve whitespace and a
code to describe the semantics of the content
CS380
Web Standards
36

Why use HTML and web standards?
 more
rigid and structured language
 more interoperable across different web browsers
 more likely that our pages will display correctly in the
future
 can be interchanged with other XML data: SVG
(graphics), MathML, MusicML, etc.
CS380
W3C HTML Validator
37
<p>
<a href="http://validator.w3.org/check/referer">
<img src="http://www.w3.org/Icons/valid-xhtml11"
alt="Validate" />
</a>
</p>
HTML

checks your HTML code to make sure it meets the
official strict XHTML specifications
CS380
Web page metadata <meta>
38
<meta name="description"
content=“Harry Potter Official Website." />
<meta name="keywords" content="harry potter, harry potter
and the deathly hallows, deathly hallows, ministry of
magic, resurrection stone, clock of invisibility" />
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
HTML



information about your page (for a browser, search
engine, etc.)
placed in the head of your XHTML page
meta tags often have both the name and content
attributes

CS380
some meta tags use the http-equiv attribute instead of name
meta element to aid browser / web
server
39
<meta http-equiv="Content-Type"
content="type of document (character encoding)" />
<meta http-equiv="refresh"
content="how often to refresh the page (seconds)" />
</head>
HTML
using the Content-Type gets rid of the W3C "tentatively valid"
warning
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
 the meta refresh tag can also redirect from one page to
another:
<meta http-equiv="refresh" content="5;url=http://www.bjp.com"
/>
 why would we want to do this? (example)

meta element to describe the page
40
<head>
<meta name="author"
content="web page's author" />
<meta name="revised"
content="web page version and/or last modification date"
/>
<meta name="generator"
content="the software used to create the page" />
</head>
HTML

many WYSIWYG HTML editors (FrontPage,
PageMaker, etc.) place their names in the meta
generator tag (why?)
CS380
meta element to aid search engines
41
<head>
<meta name="description"
content="how you want search engines to display your page"
/>
<meta name="keywords"
content="words to associate with your page (comma
separated)" />
</head>
HTML


these are suggestions to search engines about how to
index your page
the search engine may choose to ignore them (why?)
CS380
How to protect your html code?
42
CS380
What is HTML5?
43






a new W3C standard version of the HTML markup language
w3c
successor to HTML 4.01 and XHTML 1.1
balance between too-loose-ness of HTML 4 and too-strict-ness
of XHTML
reduces the browser's need for plugins to display content, e.g.
multimedia
make web content more rich, semantically meaningful,
descriptive, accessible
more easily enable the web as an application platform (Web
2.0)
CS380
What’s new in HTML5?
44


semantic tags: nav, aside, header, footer, section, aside, article
date/timeForms 2.0: sliders, search bars,
color/number/email/url/date/time, placeholders, ...

slider search number

audio and video tags for embedding multimedia

video

canvas tag for drawing 2D shapes in HTML/JS (like DrawingPanel) (ref 1,
2, 3)
CS380
What’s new (continued)
45




semantic web / microdata attributes: rel="...",
itemscope, itemtype, itemprop
SVGaccessibility features ("ARIA")
embedding of rich XML-like formats such as SVG
vector graphics
other stuff: offline apps, geolocation, crossdocument messaging, MIME type registration,
history management, ...
CS380
File Formats
46


some differ in features (animation, 5.1 stereo,
transparency)
many multimedia formats use compression to reduce
file size
 compression
algorithms are also called codecs (list
 some compression algorithms are "lossless", others are
"lossy"

some formats are patented (unusable in free
software)
CS380
File Formats
47

some formats are encrypted to protect information
inside
 Digital
Rights Management (DRM) restricts what user
can do with file
 can be broken: DVD (DeCSS), HD DVD
(09f911029d74e35bd84156c5635688c0)


some formats are streaming (can play while
downloading)
comparisons of formats: audio/video containers
CS380
Image File formats
48


JPEG : uses "lossy compression"; small file size; good for
photos
GIF : 256 colors; LZW run-length encoding lossless compression





allows transparency (can see behind parts of image)
possible to create animated GIFs
PNG : free format created to avoid patent and color issues in
GIF format; lossless compression, transparency
others: TIFF, BMP
image format comparisons: text, photo, PNG
CS380
Raster and vector graphics
49

the image formats on the previous slide
are raster or bitmap formats
 they
describe the pixels that should be drawn on the
screen

vector graphics formats such as SVG describe
shapes/lines rather than pixels
 advantage:
infinite precision; good for zooming,
printing
 disadvantage: not supported on all platforms;
computationally expensive
CS380
Audio File Formats
50








MP3 : uses lossy compression that eliminates inaudible sounds
AAC : Apple's iTunes audio file format
WMA / ASF: Microsoft Windows Media Audio format
OGG : Linux hippie audio/video format
RA / RM / RAM : Real Audio format
other formats: WAV (MS), AU (Sun), AIFF / SND (Apple), FLAC
Sequenced Music: MID, MOD
comparison of formats
CS380
Video File Formats
51

MPEG : Motion Picture standard video format








DVDs are encoded using MPEG-2
HD DVDs are often compressed with MPEG-4 (H.264) codec
MOV : Apple's QuickTime movie format
WMV / ASF : Microsoft's Windows Media Video format
AVI : classic Microsoft video format that can be encoded in
many ways
SWF / FLC : Macromedia Flash multimedia format
RV : Real Video format
comparisons of formats: 1, 2
CS380
Flash
52


format for graphics, video, audio developed by
Macromedia/Adobe
widely used for many reasons:
 supported
in most major platforms/browsers
 lightweight
 can produce impressive interactive animated content


downside: proprietary; editing software costs
money (viewer is free)
examples: Duck Hunt, Homestar Runner
CS380
Linking to multimedia files
53
<a href="video.avi">My video</a>





browser has a list of default applications to associate with
each file type
if it has an associated app, it will run it
some file types are displayed within the browser using plugins
if it doesn't know what to do, it will just download the file
try it yourself: MPG, MOV, WMV, RM, SWF, WAV, MID
CS380
File types and Browser plugins
54

plugin: helper app launched within the browser to
view certain file types
 examples:
Flash player, QuickTime, Windows Media
Player, Acrobat Reader, Java


about:plugins URL will show you list of plugins in
Firefox
enter preferences, then choose Content, File Types,
Manage...
 can
change which app/plugin will be used to open
particular file types
CS380
HTML5 embedding video
55
<video src="video.ogv" width="425"
height="350"></video>


it'll also be easy to manipulate
(play/pause/stop/etc.) the video via the JS DOM
one drawback: drama over codecs such as MPEG 4
/ H.264, Ogg Theora / VP3, WebM, AVI
CS380
Embedded objects <object>
56
<object data="video.avi"
type="video/avi"></object>
 this is how you used to embed a video prior to HTML5
 attributes: archive, classid, codebase, codetype, data,
declare, height, name, standby, type, usemap, width
 type attribute specifies file's MIME type
 IE6 requires non-standard classid attribute to specify
which plugin to use (list)
CS380
Parameters <param>
57
<object id="slider1" width="100" height="50">
<param name="BorderStyle" value="thick" />
<param name="MousePointer" value="hourglass" />
<param name="Enabled" value="true" />
<param name="Min" value="0" />
<param name="Max" value="10" />
</object>


indicates a parameter to be passed to the embedded object
required name and value attributes tell the object what parameter this is
and what value it should have
CS380
Embedding a YouTube video
58
<object width="width" height="height"
type="application/x-shockwave-flash"
data="videoURL">
<param name="wmode" value="transparent" />
parameters
</object>
<object width="425" height="350"
type="application/x-shockwave-flash"
data="http://www.youtube.com/v/eKgPY1adc0A">
<param name="wmode" value="transparent" />
</object>
CS380