CpS 401 Lecture Notes

Crash Course in HTML


What is HTML?

Basic Example

 

Basic Content Formatting

 

Markup Tags

 

Character Entities 

You may have wondered how > and < symbols get included on a web page, if they are used to define tags. For example, how do we get the browser to display the text <b> instead of turning on boldface?

We use &lt; and &gt; to get the < and > brackets, respectively, displayed on a web page. These are called HTML character entities.

 

HTML Versions and the <!DOCTYPE> element

The current HTML standard version is HTML 5.

The <!DOCTYPE> element specifies the HTML version to which a particular HTML document conforms. When used, it appears at the very beginning of an HTML document.

There are a number of combinations of attributes you might see in a <!DOCTYPE> tag. Here are some of the possibilities:

The <!DOCTYPE> element is checked by browsers, and controls a browser's backwards compatibility mode.

The <!DOCTYPE> element is used by HTML validator tools to determine which version of the standard should be used when validating the document. Web publishers use these tools to check the correctness of their documents before publishing them on the web.

 

Layout with Tables

For a long time, web designers relied on tables to obtain sophisticated page layouts. Although Style Sheets are now available to help with layout, tables are still the simplest way to go in many cases.

 

Links

The <a> tag is used to create a link. Format: <a href="url">Hyperlink text</a>

 

Relative vs. Absolute URL's

A URL (Uniform Resource Locator) is the address of a resource on the web. It has the form

An absolute URL contains all of these elements (ex: http://www.bju.edu/index.asp). The browser must have an absolute URL to be able to load a document.

Often, hyperlinks in an HTML page omit the protocol and web server name in the URL; they specify a relative URL. Here's an example:

When the user clicks this hyperlink, the web browser creates an absolute URL from this relative URL by filling in the missing pieces with information from the current web page. For example, if the URL of the current web page is

the browser would attempt to load

Relative URL's can also include .. and / marks. For example, if the link were defined this way:

the browser would attempt to load

And if the link were defined this way:

the browser would attempt to load

The use of relative URL's makes it easier to move a set of web pages from one server to another, or one subdirectory to another, and still have the links work correctly.

 

URL Encoding

Certain characters may not appear in the URL. Spaces and certain other punctuation characters

< > % # { } | \ ^ [ ] ` "

must be encoded using a special escape sequence: a percent symbol followed by the character's UNICODE number in two hexadecimal digits. For example, since the UNICODE value of a space is 32, %20 is used to encode a space in a URL.

Example: to link to a file with a space in the name, like .../top story.html, the URL would be encoded using %20, like this: .../top%20story.html.

In addition, the following characters, when appearing in a query string name/value pair, must be encoded:

; / ? : @ & = + , $
 

 

Inline Links

A long document can contain several screenfuls of text. An inline link is a link that takes the user to a specific spot in the target document (a bookmark).

  1. Create the "bookmark" using the <a> tag in the target document: <a name="bookmarkname" />

    Example: <a name="faculty" />
     

  2. Reference the bookmark in the hyperlink: <a href="targetdocumenturl#bookmarkname">

    Example: <a href="departmentinfo.html#faculty">Faculty info</a>

 

Using Images

The <img /> tag is used to include an image on a web page. Format: <img src="url" alt="alt text" />

The width and height attributes can be used to specify the size of the image.

If the values are larger or smaller than the image's true size,  the browser will shrink or stretch the image to fit.

 

Relative vs. Absolute URL's

Often the full image URL ("absolute" URL) is not used if the image resides on the same server as the web page itself. Instead, a relative URL is given. Here are some example possibilities of using relative URL's:

 

Laying out Text and Images

Tables are very helpful when you need to control the position of text and graphics on a page.

 

 

HTML Forms

An HTML form is a region of a web page that contains data-entry controls.

Here's a sample HTML page containing a form:

Encrypt.html

<html><body>

  <h2>Encryption System</h2>
  <hr>
  Welcome to the Crypt.<br>  
  <br>
  <form action='http://somewhere.net/crypt.php'>
    Enter some text to encrypt: 
      <input type='text' name='PLAINTEXT' value='Enter text to encrypt'><br>
    Enter secret key: <input type='password' name='SECRETKEY'><br>
    <input type='submit' name='ENCRYPT' value='Encrypt me!'>
  </form>
</body></html>

 

Note features of this page:

Creating HTML Prototypes

When designing web applications, it is common for developers to construct HTML prototypes.

To create a client-side HTML prototype that does not need to be deployed to a web server to be viewed, use these tips to enable navigation: