CSC 551: Web Programming Spring 2004: Basic HTML
CSC 551: Web Programming Spring 2004: Basic HTML
Spring 2004
Basic HTML
hypertext
tags & elements
text formatting
lists, hyperlinks, images
tables, frames
1
Web development tools
many high-level tools exist for creating Web pages
e.g., Microsoft FrontPage, Netscape Composer, Adobe PageMill,
Macromedia DreamWeaver, HotDog, …
also, many applications have "save to HTML" options (e.g., Word)
for most users who want to develop basic, static Web pages, these are fine
so, why are we learning low-level HTML using a basic text editor?
may want low-level control
may care about size/readability of pages
may want to "steal" page components and integrate into existing pages
may want dynamic features such as scripts or applets
2
Structural elements
an HTML document has two main structural elements
HEAD contains setup information for the browser & the Web page
e.g., the title for the browser window, style definitions, JavaScript code, …
BODY contains the actual content to be displayed in the Web page
<html>
<!-- Dave Reed page01.html 1/16/04 --> HTML documents begin and end with <html>
<!-- Demo web page --> and </html> tags
<head>
<title>Title for Page</title>
Comments appear between <!-- and -->
</head>
HEAD section enclosed between <head>
<body> and </head>
Text that appears in the page
</body>
BODY section enclosed between <body>
</html> and </body>
Text layout
<html>
<!-- Dave Reed page02.html 1/16/04 --> for the most part, layout of the text
<!-- Demo web page --> must be left to the browser
<head> every sequence of whitespace is
<title>Text Layout</title> interpreted as a single space
</head>
browser automatically wraps the text to
<body> fit the window size
<p>
This is a paragraph of text<br/>
made up of two lines.
</p> can override some text layout
<p>
This is another paragraph with a can cause a line break using the
GAP between <br/> tag (no closing tag)
some of the words.
</p>
can specify a new paragraph (starts on
a new line, preceded by a blank line)
<p> using <p>…</p>
This paragraph is<br/> can force a space character using the
indented on the first line<br/>
but not on subsequent lines.
symbol for a non-breaking space:
</p>
</body>
3
Separating blocks of text
<html>
<!-- Dave Reed page03.html 1/16/04 --> can specify headings for
<!-- Demo web page --> paragraphs or blocks of text
<head>
<title>Blocks of Text</title>
<h1>…</h1> tags produce a large,
</head> bold heading
<h2>…</h2> tags produce a slightly
<body> smaller heading
<h1>Major heading 1</h1>
<p> ...
Here is some text. <h6>…</h6> tags produce a tiny
</p> heading
<h2>Subheading</h2>
<p>
Here is some subtext. can insert a horizontal rule to divide
</p> sections
<hr/>
<hr/> draws line across window
<h1>Major heading 2</h1> <hr width="50%" /> sets width
<p> <hr size=10 /> sets thickness
Here is some more text.
</p>
</body>
Aligning text
<html>
<!-- Dave Reed page04.html
<!-- Demo web page
1/16/04 -->
-->
can specify how
elements should be
<head>
<title>Text Alignment</title> aligned (default is
</head>
left-justified)
<body> utilize STYLE
<h1 style="text-align:center">Centered Heading</h1> attribute of tag
<p>
Here is some left-justified text
(which is the default in HTML).
</p>
to justify more than
<p style="text-align:center">
Here is some centered text. one element as a
</p> group, use DIV tags
<div style="text-align:right"> ell elements enclosed
<h2>Right-justified Heading</h2> in DIV are formatted
<p>Here is some right-justified text.</p> similarly
</div>
</body>
</html>
4
Example Web page
Text styles
<html> can specify styles for fonts
<!-- Dave Reed page05.html 1/16/04 -->
<!-- Demo web page --> <b>… </b> specify bold
<i>… </i> specify italics
<head> <tt>… </tt> specify typewriter-like
<title>Text Styles</title> (fixed-width) font
</head>
<body>
<big>… </big> increase the size of
<p> the font
Text can be emphasized using <small>… </small> decrease the
<b>bold</b>, <i>italics</i>, or even size of the font
<big>resizing</big>. <br/>
The typewriter font is good for <sub>… </sub> specify a subscript
displaying code:
<sup>… </sup> a superscript
<tt>sum = sum + i;</tt> <br />
And remember: <span style="color:red">
<small>2<sup>10</sup></small> = <p style="color:red">…</p>
1024</span> for paragraphs
</p> <span style="color:blue">
</body> …</span> for inline text
</html>
Note: if elements are nested, the order of
view page in browser opening/closing is important! (LIFO)
10
5
More text grouping
<html>
<!-- Dave Reed page06.html 1/16/04 --> <pre>…</pre> specify text that is to
be displayed as is (line breaks and
<head> spacing are preserved)
<title>More Text Grouping</title>
</head> useful for code or whenever you want text
to fit a specific layout
<body>
<p>
<tt><pre>
for (i = 0; i < 10; i++) {
sum = sum + i;
<blockquote>…</blockquote>
} specify text that is to be indented on
</pre></tt> both margins
</p>
useful for quotations or for indenting text
<p> in subsections
Eagleson's Law states that:
<blockquote>
Any code of your own that you haven't
looked at for six or more months
might as well have been written by
someone else.
</blockquote>
</p>
</body> view page in browser
</html> 11
Lists
<html>
<!-- Dave Reed page07.html 1/16/04 --> there are 3 different types of list
<head> elements
<title>Simple Lists</title>
</head>
<ol>…</ol> specifies an ordered list
<body> (using numbers or letters to label each
<p> list item)
<ol> <li> identifies each list item
<li>First thing.
<li>Second thing.
can set type of ordering, start index
<li>Third thing.
</ol>
</p>
<ul>…</ul> specifies unordered list
<p> (using a bullet for each)
<dl> <li> identifies each list item
<dt>HTML
<dd>HyperText Markup Language
<dt>HTTP <dl>…</dl> specifies a definition list
<dd>HyperText Transfer Protocol <dt> identifies each term
</dl> <dd> identifies its definition
</p>
</body>
view page in browser
</html>
12
6
Hyperlinks
<html> perhaps the most important HTML
<!-- Dave Reed page08.html 1/16/04 --> element is the hyperlink, or
<head> ANCHOR
<title>Hyperlinks</title>
</head> <a href="URL">…</a>
<body> where URL is the Web address of the
<p> page to be displayed when the user
<a href="http://www.creighton.edu"> clicks on the link
Creighton University</a>
<br> if the page is accessed over the Web,
<a href="page07.html" target="_blank"> must start with http://
Open page07 in a new window</a>
</p>
if not there, the browser will assume it is
</body>
the name of a local file
13
Hyperlinks (cont.)
<html>
<!-- Dave Reed page09.html 1/16/04 -->
for long documents, you can even
have links to other locations in that
<head>
<title>Internal Links in a Page</title> document
</head>
<a name="ident">…</a>
<body>
<p align="center"> where ident is a variable for identifying
[ <a href="#HTML">HTML</a> | this location
<a href="#HTTP">HTTP</a> |
<a href="#IP">IP</a> |
<a href="#TCP">TCP</a> ]
</p>
<a href="#ident">…</a>
<p> will then jump to that location within the
Computer acronyms: file
<dl>
<a name="HTML"></a><dt>HTML
<dd>HyperText Markup Language <a href="URL#ident">…</a>
<a name="HTTP"></a><dt>HTTP
<dd>HyperText Transfer Protocol can jump into the middle of another file
<a name="IP"></a><dt>IP just as easily
<dd>Internet Protocol
<a name="TCP"></a><dt>TCP
<dd>Transfer Control Protocol
</p>
</body>
</html> view page in browser 14
7
Images
can include images using IMG
by default, browsers can display GIF and JPEG files
other image formats may require plug-in applications for display
<img src="filename" alt="alternate text" />
again, if file is to be accessed over the Web, must start with http:// (if not, will assume local file)
<html>
<!-- Dave Reed page10.html 1/16/04 -->
<head>
<title>Images</title>
</head>
<body>
<div style="text-align:center">
<img src="http://www.creighton.edu/~davereed/Images/reed.gif"
alt="Dave Reed" />
<p>Dave Reed</p>
</div>
</body> view page in
</html> browser 15
bold, italics, and font size changes are used throughout to embellish text
16
8
Tables
tables are common tools for arranging complex layout on a Web page
a table divides contents into rows and columns
by default, column entries are left-justified, so provide for alignment
<html>
<!-- Dave Reed page11.html 1/16/04 -->
<head>
<title>Tables</title> <table>…</table> specify a table
</head>
element
<body>
<table> <tr>…</tr> specify a row in the table
<tr>
<td>foo</td> <td>bar</td>
</tr> <td>…</td> specify table data (i.e., each
<tr> column entry in the table)
<td>bizbaz</td> <td>booboo</td>
</tr>
</table>
</body>
</html>
view page in browser 17
Layout in a table
<html>
can have a border on tables using
<!-- Dave Reed page12.html 1/16/04 --> the BORDER attribute
<head> <table border=1>
<title>Table Layout</title>
</head> increasing the number makes the border thicker
<body>
<table border=1> can control the horizontal & vertical
<tr align="center">
<td>foo<br>foo</td>
layout within cells
<td valign="top">bar</td>
</tr> <td align="center">
<tr> <td align="right">
<td>bizbaz</td>
<td>booboo</td>
</tr> <td valign="top">
</table> <td valign="bottom">
</body>
</html>
can apply layout to an entire row
view page in browser
<tr align="center">
<tr valign="top">
18
9
Table width
<html>
<!-- Dave Reed page13.html 1/16/04 --> by default, the table is sized to fit
<head>
the data
<title>Table Width</title>
</head>
can override & specify the width of
<body>
<table width="100%">
a table relative to the page
<tr> <table width="60%">
<td>left-most
<td align="right">right-most</td>
</tr>
</table>
</body>
useful for page footer –
</html> set table width to 100%
1st column: left-justified
2nd column: right-justified
view page in browser
19
10
Example Web page revisited
office hours are aligned, with "Office hours:" to the left (2-column table)
21
Frames
frames provide the ability to split the screen into independent pages
must define a FRAMESET that specifies the layout of the pages
actual pages to be displayed must be in separate files
11
Frame controversy
frames are probably the most controversial HTML feature
some people love them, some people hate them
23
Menu frame
<html>
to create a menu, need to be able to <!-- Dave Reed menu16.html 1/16/04 -->
direct links to the main frame <head>
name the frames in the FRAMESET <title>Menu of Demos</title>
specify the frame name as TARGET </head>
in the link <body>
specify _top as target to return to Links to demo pages
top level of browser
<p>
<a href="page01.html"
<html> target="main">Demo 1</a><br/>
<!-- Dave Reed page16.html 1/16/04 --> <a href="page02.html"
target ="main">Demo 2</a><br/>
<head> <a href="page03.html"
<title>Demo Browser</title> target ="main"> Demo 3</a><br/>
</head> <a href="page04.html"
target ="main"> Demo 4</a><br/>
<frameset cols="30%,*"> <a href="page05.html"
<frame src="menu16.html" name="menu"> target ="main"> Demo 5</a><br/>
<frame src="page01.html" name="main"> <a href="page06.html"
</frameset> target ="main"> Demo 6</a><br/>
<a href="http://www.creighton.edu"
</html> target="_top" >Creighton</a>
</p>
view page in browser </body>
</html> 24
12
Content vs. presentation
most HTML tags define content type, independent of presentation
exceptions?
HTML style sheets are known as Cascading Style Sheets, since can be defined at
three different levels
1. inline style sheets apply to the content of a single HTML element
2. document style sheets apply to the whole BODY of a document
3. external style sheets can be linked and applied to numerous documents
25
13
Inline style sheets (cont.)
<html>
<!-- Dave Reed page18.html 1/16/04 --> more style properties & values
<head>
<title>Inline Style Sheets</title> margin-left:0.1in margin-right:5%
</head>
margin:3em
<body> padding-top:0.1in padding-bottom:5%
<p>Here is an image padding:3em
<img src="reed.gif" alt="Dave Reed"
style="margin-left:0.3in;
border-width:thin border-width:thick
margin-right:0.3in;
vertical-align:middle; border-width:5
border-style:double; border-color:red
border-color:yellow"> border-style:dashed border-style:dotted
embedded in text. border-style:double border-style:none
</p>
whitespace:pre
<ol style="list-style-type:upper-alpha">
<li> one thing
<li> or another list-style-type:square
<ul style="list-style-type:square; list-style-type:decimal
whitespace:pre"> list-style-type:lower-alpha
<li> with this list-style-type:upper-roman
<li> or that
</ul>
</ol>
</body>
view page in browser 27
</html>
<body>
<table style="font-family:Arial,sans-serif">
<caption style="color:red;
font-style:italic;
text-decoration:underline">
Student data. </caption>
<tr style="background-color:red">
<th> name </th> <th> age </th>
</tr>
<tr>
<td> Chris Smith </td> <td> 19 </td>
</tr>
<tr>
<td> Pat Jones </td> <td> 20 </td>
</tr>
<tr>
<td> Doogie Howser </td> <td> 9 </td>
</tr>
</table>
</body>
</html> view page in browser
28
14
Document style sheets
inline style sheets apply to individual elements in the page
can lead to inconsistencies as similar elements are formatted differently
e.g., might like for all H1 elements to be centered
29
</body>
</html> view page in browser 30
15
Document style sheets (cont.)
<html>
<!-- Dave Reed page21.html 1/16/04 -->
document style sheets are
<head>
<title> Inline Style Sheets </title> especially useful in
<style type="text/css">
table {font-family:Arial,sans-serif}
formatting tables
caption {color:red;
font-style:italic;
text-decoration:underline}
th {background-color:red}
effectively separates
</style> content from presentation
</head>
<body>
<table>
<caption> Student data. </caption>
what if you wanted to right-
<tr><th> name </th> <th> age</th></tr> justify the column of
<tr><td> Chris Smith </td> <td> 19 </td></tr>
<tr><td> Pat Jones </td> <td> 20 </td></tr> numbers?
<tr><td> Doogie Howser </td> <td> 9 </td></tr>
</table>
</body> what if you changed your
</html>
mind?
view page in browser
31
Pseudo-elements
<html>
<!-- Dave Reed page22.html 1/16/04 --> pseudo-elements are used to
<head>
address sub-parts of elements
<title>Title for Page</title>
<style type="text/css"> can specify appearance of link in
a {color : red; various states
:visited :active :hover
text-decoration : none;
font-size : larger} can specify format of first line in page
a:visited {color : black} or paragraph
a:active {color : orange} :first-line
a:hover {color : blue}
p:first-letter {font-size : large; can specify format of first letter in
color : white; page or paragraph
background-color : darkblue} :first-letter
</style>
</head>
16
External style sheets
modularity is key to the development and reuse of software
design/implement/test useful routines and classes
package and make available for reuse
33
</body>
</html>
view page in browser 34
17
Web rules of thumb
HTML provides for lots of neat features,
but just because you can add a feature doesn't mean you should!
don't add features that distract from the content of the page
¾ use color & fonts sparingly and be careful how elements fit together
e.g, no purple text on a pink background, no weird fonts
¾ don’t be annoying
e.g., no pop-up windows, excessive advertising, silly music
¾ break large document into smaller or provide a menu (either internal or frame)
¾ stick to standard features and test using both IE and Netscape
¾ utilize style sheets to make changes easy & ensure consistency
35
18