HTML Crash Course: by Daniel D'Agostino 2 June 2007 Revised 19 June 2007
HTML Crash Course: by Daniel D'Agostino 2 June 2007 Revised 19 June 2007
HTML Crash Course: by Daniel D'Agostino 2 June 2007 Revised 19 June 2007
* Now open the file with a web browser. * What happened to the text enclosed in tags?
3
* HTML tags normally have a start tag (<b>) and a closing tag (</b>) * You can have multiple tags around the same text but they must be closed in reverse order
<b><i>Hello!</i></b>
White space * newlines * multiple spaces Spacing tags * <br> * <p> * <br> is called an empty tag * Block and inline elements
5
* The <font> tag is deprecated * Use it until you learn better things * HTML tags can have attributes * <font> attributes: * face * color * size * Order of attributes not important * Values in quotes
6
The <blockquote> tag * needs inner tags (e.g. <p>) * block element The <q> tag * inline element * browser incompatibilities
10
HTML Comments
<!-- comment --> Useless in HTML * demonstrate using <blockquote> * HTML tags are clear and legible * HTML comments increase the size of the page, unlike with programming
11
Tags used to format source code in a page * <code> (inline, monospace) * <var> (inline, not monospace) * <pre> (block, monospace, kills whitespace)
12
HTML Entities
* You cannot use < or > characters because they are used for HTML tags * Entities are used where special characters are needed * Examples: < > © & " * Entity formats: name and number * Reference:
http://www.w3schools.com/html/html_entitiesref.asp
14
HTML Links
* Link is the most important thing * Format: <a href=target.htm>link</a> * Links are relative unless they start with a protocol (e.g. http:// or file://) * <a href=www.google.com>google</a> - wrong! (relative) * For internal links, relative links are better * shorter * transparent when relocating website
15
* / - root * .. - parent directory * . - current directory * dir/ - child directory named 'dir' * ../dir1/ - 'dir1' directory in parent directory Append slash to domains/folders to prevent multiple requests
16
* Used to link to a specific point in a page * <a href=#label>local link</a> * <a name=label>local anchor</a> (old) * <h2 id=label>local anchor</h2> (best) * Example of simple table of contents
17
HTML Lists
* Ordered Lists (<ol>, <li>) * Unordered Lists (<ul>, <li>) * When to use each * Definition Lists (<dl>, <dt>, <dd>) * Nested Lists
20
HTML Images
* Images are separate files (compare doc with htm) * <img src=picture.jpg alt=Picture> * ALT is not there to popup text, even though Internet Explorer does it * ALT = alternate text, used if the image fails to load * Use title attribute to popup text Other attributes: width, height, border, title, align, hspace, vspace
21
Use only jpg, gif and png formats * bitmaps are too large * other formats are not always readable Specify a width and a height for the image to make sure page doesn't keep resizing every time an image loads
22
Thumbnailing
* To make a thumbnail, enclose an image in a link <a href=largepic.jpg> <img src=smallpic.jpg alt=> </a> * It is possible to use the same picture and resize it using width and height attributes * Very bad wastes bandwidth!
23
Image Maps
This section is here for completeness' sake and can be skipped * image map => image with clickable areas * <map> tag, id attribute * <area> tag, attributes: alt, coords, href, shape, title * shape can be rect, circle or polygon
24
HTML Tables
* A table is made up of rows and columns * A table can be considered a list of rows * A row can be considered a list of cells * <table>: table * <tr>: table row * <td>: table data (cell) * <th>: table heading
25
* cellpadding and cellspacing (difference between padding and margin) * colspan and rowspan (merging cells) * summary * usual width, height, border, background, bgcolor
27
Page Title
Navigation
Content
28
HTML Frames
* Why frames are/were used * Navigation in one file * Why frames are bad * No logical page structure * Printing problems (old) * Browser compatibility (old) * Search engine difficulties * If a search engine does find a page, that page is isolated * Address bar does not tell you where you are
30
Frames (continued)
* Why frames are bad (continued) * Cannot view source * Bookmarking/deep-linking * Why there is no excuse to use frames * Now there are languages (e.g. PHP) for server-side page inclusion * Targeting links * target attribute: _top, _blank * not recommended!
31
HTML Forms
* Forms are a way of interacting with a website (e.g. an application form) * Forms are useless until you know a language capable of processing them (e.g. PHP) * The <form> tag: * method (difference between get/post) * name/id * action
32
<input> tag used for most inputs * type: button, checkbox, file, hidden, image, password, radio, reset, submit, text * importance of submit button * id attribute (to distinguish input fields) * value attribute (to set a default value)
33
<fieldset>
Creates a border around some elements, good for distinguishing a form or parts of a form <fieldset> <legend>Caption!</legend> <p>Other stuff...</p> </fieldset>
35
Meaning of HTML
Now that you know HTML, you can understand what it stands for. HTML = Hypertext Markup Language Hypertext is about links. A markup language differs from a programming language in that it is text-based and uses tags to 'mark up' text.
36
37
* You can't just throw your tags around the page blindly * There is a document structure that must be adhered to * Each HTML document consists of a head and a body * All your content goes in the body * The head section contains information about the page
40
41
42
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
44
XHTML
XHTML is Extensible HTML * it is based on XML so it is stricter * it is among the latest HTML standards * some handheld devices (e.g. mobile phones) can read XHTML webpages * it is a good way to get used to writing good code
46
HTML to XHTML
* All tags must be closed, even if they are empty tags * <br> becomes <br /> * All tags and attributes must be lowercase * <strong> not <STRONG> * All tags must be closed in the right order * <b><i>wow</b></i> is wrong * Attribute values must be in quotes * <p align=center>text</p> * Use the id attribute instead of name * Use an XHTML DTD
47
XHTML 1.1
* XHTML 1.1 is a bit trickier * It is not just about adding a DTD * An XML version declaration is added at the top before the DTD * This declaration also includes the character encoding, so we no longer need the meta tag * The <html> tag now also has some extra attributes * Don't remember! Copy and paste!
49
<?xml version="1.0" encoding="UTF-8" ?> <!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" xml:lang="en"> <head> ... Remember to omit the <meta> tag for character encoding!
50
Moving On
* HTML on its own is very basic * The next language to learn is definitely CSS * After CSS, you can optionally learn JavaScript * Or you can go straight to a server-side language such as PHP
51