chapter 4 Introduction to HTML Study Notes on HTML and Web Technologies
Web Pages and HTML Fundamentals
- Method of Creation and Delivery: Web pages are created, stored, and transmitted in an encoded form. A web browser acts as a converter, transforming the encoded source into the visual representation seen on a computer screen.
- Hypertext Markup Language (HTML): This is the primary language used to define the visual characteristics of a web page, including background color, font choices, and general layout.
- Essential Development Tools:
- Web Browser: Applications such as Firefox, Internet Explorer (IE), or Google Chrome are required to render the code.
- Simple Text Editor: Tools like Notepad++ are necessary for writing HTML as plain ASCII text. Document processors like Microsoft Word should be avoided as they add extra formatting information that interferes with the source code.
- File Naming and Execution:
- Files must be saved with the
.html extension (e.g., starterPage.html). - Double-clicking an
.html file will open it in the default browser. - A basic HTML file can serve as a template or model for all future web page development.
Basic HTML Document Structure
- Overall Enclosure: Every document begins with an opening
<html> tag and ends with a closing </html> tag. - The
<head> Section:- Contains preliminary material such as the title and information that applies globally to the page.
- The
<meta charset="UTF-8" /> tag is required to specify character encoding. - The
<title> tag defines the text displayed in the browser's title bar.
- The
<body> Section:- Contains the actual content of the page, such as text, images, and links.
- Example Template:
html
<html>
<head>
<meta charset="UTF-8" />
<title> Starter Page </title>
</head>
<body>
<p> Hello, World! </p>
</body>
</html>
- Mark Up Concept: HTML uses hidden tags to describe how words on a page should look, including font, size, color, bolding, and indentation. This is also referred to as XHTML (Extensible Hypertext Markup Language).
- Paired Tags: Most tags come in pairs, consisting of a beginning and an end tag enclosed in angle brackets
< >. For example: <title></title>.- Tags are not case-sensitive.
- The actual text located between the tags is case-sensitive.
- Singleton Tags: Certain tags do not surround content and thus lack a closing form. Instead, the closing angle bracket is replaced by
/>. Examples include:<hr />: Inserts a horizontal rule (line).<br />: Inserts a line break to continue text on a new line.
| Start Tag | End Tag | Meaning | Required |
|---|
<html xmlns="fn"> | </html> | XHTML document (first and last tags; fn=http://www.w3.org/1999/xhtml) | Yes |
<title> | </title> | Title bar text describing the page | Yes |
<head> | </head> | Preliminary material (e.g., title) | Yes |
<body> | </body> | The main part of the page content | Yes |
<p> | </p> | Paragraph | No |
<hr /> | (Singleton) | Line (horizontal rule) | No |
<h1> … <h6> | </h1> … </h6> | Headings (levels 1-6, use in order) | No |
<b> | </b> | Bold | No |
<i> | </i> | Italic | No |
<a href="fn"> | </a> | Anchor reference (hyperlink; fn is a pathname) | No |
<img src="fn" /> | (Singleton) | Image source reference (fn is path to .jpg, .png, or .gif) | No |
<br /> | (Singleton) | Break text to a new line | No |
Content Formatting
- Headings: Headings and subheadings indicate the structure of a document. They automatically display content on a new line.
<h1>: Largest and boldest level-one heading.<h2> through <h6>: Progressively smaller heading levels.
- Text Styling:
- Bold:
<b>...</b> - Italic:
<i>...</i> - Underline:
<u>...</u> - Big/Small:
<big>...</big>, <small>...</small> - Emphasis/Strong:
<em>...</em>, <strong>...</strong> - Subscripts/Superscripts:
<sub>...</sub>, <sup>...</sup> - Monospaced:
<tt>...</tt> (typewriter text). - Quotes:
<q>...</q> for short quotes; <blockquote>...</blockquote> for quotes longer than one line.
- Nested Tags: Formatting tags can be combined. They must be closed in the reverse order they were opened (last-in, first-out sequence). Example:
<b><i>Veni, Vidi, Vici!</i></b>.
Handling White Space
- White Space Definition: White space refers to spaces, tabs, and new lines (returns/enters) inserted into the code for readability.
- Browser Interpretation: By default, HTML ignores extra white space. Any sequence of white space characters within
<p> tags is collapsed into a single space. <pre> Tag: Information contained within <pre> and </pre> tags is "preformatted," meaning the browser displays it exactly as it appears in the text editor, including all white space.- Line Width: The width of a line of text is generally determined by the browser window's width; resizing the window causes lines to break in different locations.
Markup Validation and Technical Standards
- Validation: Using the Markup Validation Service ensures a web page functions correctly across all browsers.
- Document Type Declaration: To adhere to standards, specific lines should be added before the
<html> tag:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">. - Character Encoding: To specify UTF-8 (Unicode Translation Format for bytes), the following meta tag is used within the
<head> section:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />.
Special Characters and Escape Symbols
- The Escape Symbol (
&): Used to display characters that the browser would otherwise interpret as HTML code. - Common Entities:
< displays as <.> displays as >.& displays as &.— displays as an em dash (—).
- Accent Marks (Western European):
- Structure:
& + letter + accent name + ;. à (à), è (è), ì (ì), ò (ò), ù (ù).á (á), é (é), í (í), ó (ó), ú (ú).â (â), ê (ê), î (î), ô (ô), û (û).ä (ä), ë (ë), ï (ï), ö (ö), ü (ü).ñ (ñ), ã (ã), õ (õ), å (å), ø (ø), ç (ç).- Numeric codes can also be used, such as
ñ for ñ or ê for ê. - For uppercase accented letters, capitalize the text following the
& (e.g., À).
Anchors and Hyperlinks
- Two Sides of a Link:
- Anchor Text: The visible, highlighted text that the user clicks.
- Hyperlink Reference: The URL or filename address where the link "goes."
- Syntax:
<a href="filename">Link Text</a>. - Pathnames:
- Absolute Pathnames: Used for remote pages at other websites. Requires a full URL (e.g.,
http://server/directory_path/filename). - Relative Pathnames: Used for pages stored in the same or nearby directories. These are more flexible for moving groups of files.
./filename: Current directory.../filename: Parent directory (one level up)../subdir/filename: Down into a sub-directory.
Working with Images
- Image Tag Syntax:
<img src="filename" alt="description" />.src: The source location of the image file.alt: Alternative text displayed if the image fails to load; essential for audio screen readers.
- Clickable Pictures: Images can be nested inside anchor tags to serve as links:
<a href="fullsize.jpg"><img src="thumbnail.jpg" /></a>. - File Formats:
- GIF (Graphic Interchange Format): 8 bits (256 colors).
- JPEG (Joint Photographic Experts Group): 24 bits (millions of colors with compression).
- PNG: A newer form of graphic format.
- Attributes for Size and Positioning:
- Dimensions:
<img src="puffer.jpg" width="200" height="200" />. If one dimension is omitted, the browser preserves the original proportions. - Text Flow: Use the style attribute
float:left or float:right to allow text to wrap around the image. - Manual Line Placement: Enclose the
<img> tag in <p> tags to force it onto its own line.
HTML Attributes and Inline Styling
- Attributes: Located inside the opening tag after the tag name. They follow the format
attribute="value".- Example:
<p align="center"> (though the default is left). - Horizontal Rule attributes:
<hr width="50%" size="3" /> specifies width and thickness.
- The Style Attribute: Controls various properties of the look of the page. Values are separated by semicolons.
- Example:
<body style="background-color: black; color: green">. - Example:
<h1 style="text-align: center; color: yellow; font-family: arial">.
- Original HTML Color Keywords: include black, silver, white, gray, red, fuchsia, maroon, purple, blue, navy, aqua, teal, lime, green, yellow, and olive.
- Span Tag:
<span>...</span> tags are used to apply styles where no other specific tag is available.
Handling Lists
- Unordered (Bulleted) List:
- Surrounded by
<ul> and </ul>. - Items enclosed in
<li> and </li>.
- Ordered (Numbered) List:
- Surrounded by
<ol> and </ol>. - Uses the same
<li> tags for items.
- Definitional List:
- Surrounded by
<dl> and </dl>. - Terms enclosed in
<dt> and </dt>. - Definitions enclosed in
<dd> and </dd> (indented by the browser).
- Sublists: Lists can be nested by inserting a new list within the
<li></li> tags of an existing list.
Handling Tables
- Table Tags:
<table>...</table>: Defines the table.<tr>...</tr>: Defines a table row.<td>...</td>: Defines a table data cell.<th>...</th>: Defines a table header cell (typically bold and centered).<caption>...</caption>: Creates a centered title at the top of the table.
- Arrangement Control: Tables can be used to organize information, such as a row of links across the top of a page. If the window is too small, a table keeps items in a row with a scroll bar, whereas plain text would wrap to the next line.
Cascading Style Sheets (CSS)
- Purpose: Allows for systematic and uniform styling across multiple pages or elements. This defines a "theme" for a site.
- Global Style: Defined within the
<head> section using <style> tags.
css
¨K38K
- Overriding Styles: Local styles (inline attributes in the body tags) take precedence over global styles. In CSS, the "closest" rule wins.
- Style Classes: Different collections of styles can be defined as classes (e.g.,
table.sum and table.fall) and applied selectively using the class="classname" attribute. - External Style Files: Styles can be moved to a separate
.css file (e.g., myStyle.css). The <style> tags are excluded from the .css file itself. The file is linked in the HTML <head> section:
<link rel="stylesheet" type="text/css" href="myStyle.css" />.
Composition Strategies
- Compose and Check: Maintain two windows open: the text editor and the browser. Write a few tags, save, and then reload/refresh the browser to see the result.
- Grow the Code: Start with a simple template and add content in small increments. This approach, known as the "slow-n-steady construction strategy," ensures better syntax and easier troubleshooting than trying to write a "monolith" all at once.