~~SLIDESHOW~~ We recommend that you view this document in slideshow mode first then go back and read the notes. ====== The Structural Layer ====== We start by revising the most commonly used subset of the eXtensible Markup Language (XHTML). * [[eg-259:lecture2#origins_and_evolution_of_html|Origins and Evolution of HTML]] * [[eg-259:lecture2#basic_syntax|Basic Syntax]] * [[eg-259:lecture2#standard_xhtml_document_structure|Standard HTML Document Structure]] * [[eg-259:lecture2#day-to-day_markup|Day-to-day Markup]] * [[eg-259:lecture2#other_elements|Other Elements]] * [[eg-259:lecture2#more_advanced_markup|More Advanced Markup]] * [[eg-259:xhtml#syntactic_differences_between_html_xhtml|Syntactic Differences between HTML & XHTML]] ===== Origins and Evolution of HTML ===== * There is a comprehensive History of the evolution of HTML in this Wikipedia article: [[wp>HTML#History|HTML -- History]]. * Mark Pilgrim gives a very readable account of the road to HTML5 in [[http://diveintohtml5.info/past.html|Dive Into HTML5 -- How Did We Get Here?]] ===== Reasons to use the XHTML syntax rather than HTML ===== * HTML has lax syntax rules, leading to sloppy and sometimes ambiguous documents * HTML processors do not even enforce the few syntax rule that do exist in HTML * XHTML syntax is stricter, leading to clean and clear documents in a standard form * The syntactic correctness of XHTML documents can be validated * HTML5 allows both the less strict conventions of HTML5 and the stricter XHTML syntax. * To avoid relearning what you already know, we will continue to use the XHTML syntax except where HTML5 syntax is simpler to understand. ===== Basic Syntax ===== * //Elements// are defined by //tags// (markers) which act as containers for //content//: e.g. '' content ''. * The opening tag and its closing tag together specify a container for the content they enclose * Not all elements have content: if a tag has no content, its form is '''' * The container and its content together are called an //element// * If a tag has //attributes//, they appear between its name and the right bracket of the opening tag: e.g '' content '' * Comment form: '''' ---- //**Notes**// * Tag format: * Opening tag: '''' * Closing tag: '''' * Attributes: * in the example ''[name="value"]*'' means that an attribute -- defined as a name followed by ''='' followed by a quoted value -- can appear 0 or more times in an element's opening tag. Thus attributes are optional, but when they appear they must have the form ''name="value"''. Furthermore if there are attributes, there can be any number of attributes. * Browsers ignore comments, unrecognizable tags, line breaks, multiple spaces, and tabs * Even if they are recognized by the browser, tags are only //suggestions// to the browser. ===== Standard HTML5 Document Structure ===== * Every HTML5 document begins with the simple DOCTYPE declaration: * The elements '''', '''', '''', and ''<body>'' are required in every document * The whole document must have ''<html>'' as its root * For compatibility with XHTML specifications the ''html'' element may use the ''xmlns'' attribute: <code html> <html lang="en"> </code> ---- The language of the document is declared in the ''lang'' attribute. This is useful for browsers who may be visiting your site from another non-english speaking country (particular if that country uses a different character set). ===== A Minimal XHTML Document ===== * A document consists of a //head// and a //body// * The ''<title>'' element is used to give the document a title * A ''<meta>'' element that specifies the character encoding used for the document should be included * Text is normally placed in //paragraph elements// (''<p>'') in the body of the document * W3C HTML Validation Service http://validator.w3.org/file-upload.html ---- //**Notes**// * The content of the ''<title>'' element is normally displayed in the browser's window title bar (at the top of the display). * Prior to XHTML 1.1, a document could have either a //body// or a //frameset// * A common setting for the ''<meta>'' tag is ''utf-8'' defined like this <code html> <meta charset="utf-8" /> </code> * Paragraph Elements * The ''<p>'' tag breaks the current line and inserts a blank line -- the new line gets the beginning of the content of the paragraph * The browser puts as many words of the paragraph's content as will fit in each line ===== An Example Minimal Valid Document ===== <code html|Our first document> <!DOCTYPE html> <!-- example.html: A trivial document --> <html lang="en"> <head> <meta charset="utf-8" /> <title> Our first document

Greetings from your Webmaster!

* I recommend that you download a copy of this document ([[/eg-259/examples/lecture2/example.html|example.html]]) and use it as a template. [ [[eg-259:css|Jump to CSS]] ] ===== Day-to-day Markup ===== * **//Basic Text Markup//** * [[eg-259:lecture2#line_breaks|Line Breaks]] * [[eg-259:lecture2#headings|Headings]] * [[eg-259:lecture2#quotations|Quotations]] * [[eg-259:lecture2#font_styles_and_sizes|Font Styles and Sizes]] * [[eg-259:lecture2#subscripts_and_superscripts|Subscripts and Superscripts]] * [[eg-259:lecture2#character_entities|Character Entities]] ===== Line Breaks ===== * The effect of the ''
'' tag is the same as that of ''

'', except for the blank line * An [[/eg-259/examples/lecture2/line-breaks.html|example]] of paragraphs and line breaks:

On the plains of hesitation

bleach the bones of countless millions
who, at the dawn of victory
sat down to wait, and waiting, died.

---- //**Notes and Details of the Example**// * Note that ''
'' has no closing tag! * The example of paragraphs and line breaks: [[/eg-259/examples/lecture2/line-breaks.html|line-breaks.html]] Paragraphs and Line Breaks

On the plains of hesitation

bleach the bones of countless millions
who, at the dawn of victory
sat down to wait, and waiting, died.

* Typical display:

On the plains of hesitation

bleach the bones of countless millions
who, at the dawn of victory
sat down to wait, and waiting, died.

===== Headings ===== * Six sizes, 1---6, specified with ''

'' to ''

'' * 1, 2, and 3 use font sizes that are larger than the default font size * 4 uses the default size * 5 and 6 use smaller font sizes * An example of headings: [[/eg-259/examples/lecture2/headings.html|headings.html]] ----- * //**Code for the Example**// Headings

Aidan's Airplanes (h1)

The best in used airplanes (h2)

"We've got them by the hangarful" (h3)

We're the guys to see for a good used airplane (h4)

We offer great prices on great planes (h5)
No returns, no guarantees, no refunds, all sales are final (h6)
* //**Typical Display**// {{eg-259:l2-headings.png|An example of the use of the headings elements}} ===== Quotations ===== * Content of ''
'' * To set a block of text off from the normal flow and appearance of text * Browsers often indent, and sometimes italicize * Example: [[/eg-259/examples/lecture2/blockquote.html|blockquote.html]] ---- **//Code for the Example//** Blockquotes

Abraham Lincoln is generally regarded as one of the greatest presidents of the U.S. His most famous speech was delivered in Gettysburg, Pennsylvania, during the Civil War. This speech began with

"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.

Now we are engaged in a great civil war, testing whether that nation or any nation so conceived and so dedicated, can long endure."

Whatever one's opinion of Lincoln, no one can deny the enormous and lasting effect he had on the U.S.

//**Typical Display**// {{eg-259:l2-blockquote.png|An example of the use of the blockquote element}} ===== Font Styles and Sizes ===== The sleet in Crete
lies
completely
in
the street
The sleet in Crete
lies
completely
in
the street ---- * Can be nested * Boldface -- '''' * Italics -- '''' * Larger -- '''' * Smaller -- '''' * Monospace -- '''' These tags are not affected if they appear in the content of a ''
'', unless there is a conflict (e.g., italics) ===== Subscripts and Superscripts ===== * Subscripts with ''sub'' * Superscripts with ''sup'' x23 x23 ---- **//Very Important Note//** * All of this font size and font style stuff can (and should) be done with style sheets, but the tags are not yet deprecated * Block elements **CANNOT** be nested in in-line elements ===== Character Entities ===== Needed to enter certain special characters into a web page ^ Char ^ Entity ^ Meaning ^ | & | & | Ampersand | | < | < | Less than | | > | > | Greater than | | " | " | Double quote | | ' | ' | Single quote | | ¼ | ¼ | One quarter | | ½ | ½ | One half | | ¾ | ¾ | Three quarters | | ? | ° | Degree | |(space) |   | Non-breaking space | ---- **//Notes//**: The first four character entities are needed to display the characters that are used by XHTML elements and attributes. For example to display ''

Hello World!

'' in a web page we have to enter ''<p class="greeting">Hello World!</p>'' and to display the ''&'' symbol we have to use ''&amp;''. This can make the display of HTML code in a web page quite a challenge! For a full list of the 252 usable character entities see [[http://www.cookwood.com/html/extras/entities.html|1]] and [[http://www.w3.org/TR/html401/sgml/entities.html|2]]. ===== Other Elements ===== * [[eg-259:lecture2#horizontal_rules_and_meta_tags|Horizontal Rules and Meta Tags]] * [[eg-259:lecture2#images|Images]] * [[eg-259:lecture2#hypertext_links|Hypertext Links]] ===== Horizontal Rules and Meta Tags ===== * Horizontal rules * ''
'' draws a line across the display, after a line break * The ''meta'' element (for search engines) * Used to provide additional information about a document, with attributes, not content ===== Images ===== * GIF (Graphic Interchange Format) * JPEG (Joint Photographic Experts Group) * Both use compression, but JPEG compression is better * Portable Network Graphics (PNG) ---- * GIF -- 8-bit color (256 different colors) * JPEG -- 24-bit color (16 million different colors) * Both use compression, but JPEG compression is better * PNG * Relatively new * Should eventually replace both GIF and JPEG ===== Images – Markup ===== Picture of comets * Images are inserted into a document with the '''' tag with the ''src'' attribute * The ''alt'' attribute is required by XHTML * The '''' tag has 30 different attributes, including ''width'' and ''height'' * Example Document: [[/eg-259/examples/lecture2/image.html|image.html]] ---- * Purpose of the ''alt'' attribute: - Non-graphical browsers - Browsers with images turned off - Accessibility, e.g. screen readers ----- //**Code for the Example**// Images

Aidan's Airplanes

The best in used airplanes

"We've got them by the hangarful"

Special of the month

1960 Cessna 210
577 hours since major engine overhaul
1022 hours since prop overhaul

Picture of a Cessna 210
Buy this fine airplane today at a remarkably low price
Call 999-555-1111 today!

//**Typical Display**// {{eg-259:l2-image.jpg|An example of a document with an image}} ===== Hypertext Links ===== * Hypertext is the essence of the Web! * A link is specified with the ''href'' (hypertext reference) attribute of '''' (the anchor tag) * The content of '''' is the visual link in the document * If the target is a whole document (not the one in which the link appears), the target need not be specified in the target document as being the target * Example: [[/eg-259/examples/lecture2/link.html|link.html]] ---- //**Notes**// Relative addressing of targets is easier to maintain and more portable than absolute addressing //**Code for the Example**// A link

Aidan's Airplanes

The best in used airplanes

"We've got them by the hangarful"

Special of the month

1960 Cessna 210
Information on the Cessna 210

//**Typical Display**// {{eg-259:l2-link1.jpg|An example of a document with links}} //**Link Target**// The Link Target is [[/eg-259/examples/lecture2/C210data.html|C210data.html]] 1960 Cessna C210

1960 Cessna 210

577 hours since major engine overhaul
1022 hours since prop overhaul

Picture of a Cessna 210
Buy this fine airplane today at a remarkably low price
Call 999-555-1111 today!

**//Typical Display//** {{eg-259:l2-link_target.jpg|The Target of the Link Example}} ===== Hyperlink Targets ===== * If the target is not at the beginning of the document, the target spot must be marked * Target labels can be defined in many different tags with the ''id'' attribute, as in:

Baskets

* The link to an id must be preceded by a "//pound sign//" (''#''); If the ''id'' is in the same document, this target could be: What about baskets? * If the target is in a different document, the document reference must be included: Baskets ---- * **Style note**: a link should blend in with the surrounding text, so reading it without taking the link should not be made less pleasant * Links can have images: Small picture of an airplane Info on C210 ===== Exercises to Demonstrate Basic XHTML ===== - Create, test and validate an XHTML document for yourself. including your name, address, and e-mail address. You must include your student number, course and level. This document must use several headings and '''', '''', ''
'', ''

'' and ''
'' tags. - Add pictures of yourself and at least one image (e.g. of your friend, spouse, pet) to the document created in Exercise 1. - Add a second document to the document created for Exercise 1 that describes part of your background, using the word ''background'' as the link content. This document should have a few paragraphs of your personal history. ===== More Advanced Markup ===== * //**Lists**// * [[eg-259:lecture2#unordered_lists|Unordered Lists]] * [[eg-259:lecture2#ordered_lists|Ordered Lists]] * [[eg-259:lecture2#nested_lists|Nested Lists]] * [[eg-259:lecture2#definition_lists|Definition Lists]] * [[eg-259:lecture2#tables|Tables]] * [[eg-259:lecture2#frames|Frames]] ===== Unordered Lists ===== * The list is the content of the ''

    '' tag * List elements are the content of the ''
  • '' tag: [[/eg-259/examples/lecture2/unordered.html|unordered.html]] ---- Unordered list

    Some Common Single-Engine Aircraft

    • Cessna Skyhawk
    • Beechcraft Bonanza
    • Piper Cherokee
    ===== Ordered lists ===== * The list is the content of the
      tag * Each item in the display is preceded by a sequence value: [[/eg-259/examples/lecture2/ordered.html|ordered.html]] ---- Ordered list

      Cessna 210 Engine Starting Instructions

      1. Set mixture to rich
      2. Set propeller to high RPM
      3. Set ignition switch to "BOTH"
      4. Set auxiliary fuel pump switch to "LOW PRIME"
      5. When fuel pressure reaches 2 to 2.5 PSI, push starter button
      ===== Nested lists ===== * Any type list can be nested inside any type list * The nested list must be in a list item: [[/eg-259/examples/lecture2/nested_lists.html|nested_lists.html]] ---- Nested lists

      Aircraft Types

      1. General Aviation (piston-driven engines)
        1. Single-Engine Aircraft
          1. Tail wheel
          2. Tricycle

        2. Dual-Engine Aircraft
          1. Wing-mounted engines
          2. Push-pull fuselage-mounted engines

      2. Commercial Aviation (jet engines)
        1. Dual-Engine
          1. Wing-mounted engines
          2. Fuselage-mounted engines

        2. Tri-Engine
          1. Third engine in vertical stabilizer
          2. Third engine in fuselage
      ===== Definition lists ===== * For glossaries, etc. * List is the content of the ''
      '' tag * Terms being defined are the content of the ''
      '' tag * The definitions themselves are the content of the ''
      '' tag: [[/eg-259/examples/lecture2/definition.html|definition.html]] ---- Definition lists

      Single-Engine Cessna Airplanes

      152
      Two-place trainer
      172
      Smaller four-place airplane
      182
      Larger four-place airplane
      210
      Six-place airplane - high performance
      ===== Exercises to Demonstrate Lists ===== - Create, test and validate an XHTML document to describe an unordered list of a typical supermarket shopping list you write. (If you've never made such a list, use your imagination). - Create, test and validate an XHTML document to describe an unordered list of at least 4 countries. Each element of the list must have a nested list of at least three cities in the country. - Create, test and validate an XHTML document to describe an ordered list of your five favourite movies. - Modify the list of Exercise 6 to add nested, unordered lists of at least two actors and/or actresses in each of your favourite movies. ===== Tables ===== * A table is a matrix of cells, each possibly having content * The cells can include almost any element * Some cells have row or column labels and some have data * A table is specified as the content of a '''' tag * A ''border'' attribute in the ''
      '' tag specifies a border between the cells * Tables are given titles with the ''
      '' tag, which can immediately follow '''' ---- //**Notes**// * If border is set to ''"border"'', the browser's default-width border is used * The border attribute can be set to a number, which will be the border width * Without the border attribute, the table will have no lines! ===== Table Rows and Cells ===== * Each row of a table is specified as the content of '''' tag * The *row headings* are specified as the content of a ''
      '' tag * The contents of a *data cell* is specified as the content of a '''' tag * An example table: [[/eg-259/examples/lecture2/table.html|table.html]] ---- A simple table
      Fruit Juice Drinks
      Apple Orange Screwdriver
      Breakfast 0 1 0
      Lunch 1 0 0
      Dinner 0 0 1
      ===== More Table Elements and Attributes ===== For information on column and row spanning, cell alignment, cell spacing and padding see the notes. ----- **//Tables -- colspan//** * A table can have two levels of column labels, e.g.
      Fruit Juice Drinks
      Orange Apple Screwdriver
      * If so, the ''colspan'' attribute must be set in the ''
      '' tag to specify that the label must span some number of columns: : :
      Fruit Juice Drinks
      Apple
      //**Tables -- rowspan**// * If the rows have labels and there is a spanning column label, the upper left corner must be made larger, using ''rowspan'', e.g.
        Fruit Juice Drinks
      Apple Orange Screwdriver
      * Is created with: : :
        Fruit Juice Drinks
      Apple
      * Download the colspan/rowspan example: [[/eg-259/examples/lecture2/cell_span.html|cell_span.html]]. Here is the complete source code: Rowspan and colspan
      Fruit Juice Drinks and Meals
        Fruit Juice Drinks
      Apple Orange Screwdriver
      Breakfast 0 1 0
      Lunch 1 0 0
      Dinner 0 0 1
      ===== Table Sections ===== * Header, body, and footer, which are the elements: ''thead'', ''tbody'', and ''tfoot'' * If a document has multiple ''tbody'' elements, they are separated by thicker horizontal lines ===== Exercises to Demonstrate Tables ===== - Create, test and validate an XHTML document to describe a table with the following contents: * The columns of the table must have the headings Pine, Maple, Oak and Fir * The rows must have labels Average Height, Average Diameter, Typical Lifespan, and Leaf Type. * You can make up the data cell values. - Modify, test and validate an XHTML document from Exercise 1 to add a second level column label, Tree, and a second-level row label, Characteristics. - Create, test and validate an XHTML document to describe a table with columns for country, national language, capital city and population. There must be at least five countries in the table. ===== Frames ===== * Frames are rectangular sections of the display window, each of which can display a different document * Because frames are no longer part of HTML5, you cannot validate a document that includes frames * For this reason we shall say no more about them in this module! ===== Syntactic Differences between HTML & XHTML ===== * Case sensitivity * Closing tags * Quoted attribute values * Explicit attribute values * ''id'' and ''name'' attributes ===== The Structural and Presentation Layers ===== * [[eg-259:lecture2|Lecture Home]] * [[eg-259:xhtml|The Structural Layer]] * [[eg-259:css|The Presentation Layer]] * [[eg-259:html5|XHTML 2 and HTML5]] * [[eg-259:css3|CSS 3]]