HTML Basics



index
Disabled back button Next Section
printable version

Section 1: Overview

HTML (hypertext markup language) is the most predominant markup language for pages on the World Wide Web.

The original version of HTML was developed by a physicist named Tim Berners-Lee in the 1980s.

Components of a web page.

Components of a Web Page


Layered web design is also referred to as progressive enhancement.

The components work together like this:

What is Progressive Enhancement, and why it matters discusses some of the benefits of progressive enhancement.

The first part of this course focuses on how to build a static web page using HTML5, and how to control its appearance using CSS.

Section 2: Basic Page Structure

HTML is written in the form of labels (known as tags), surrounded by angle brackets (< and >).

Your basic HTML document is little more than a text document that contains markup tags with a .html or .htm file extension (rather than .txt).

Let's create a simple HTML document in Notepad using the following code:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Spiffy Page</title>
</head>
<body>
<h1>My First Page</h1>
<p>Check out my spiffy page!</p>
</body>
</html>

Here's how:

  1. Highlight the text above and copy it to your clipboard by pressing the Ctrl key and the C key at the same time.
  2. Start Notepad (or some other text editor).
    • On my Windows machine I click the Search icon, then start typing "Notepad" in the search area, and when Notepad popps up as an option I click it.
  3. Paste the code from the clipboard into Notepad by pressing the Ctrl key and the V key at the same time.
  4. Select "File" from the menu, then click "Save As...".
  5. In the resulting "Save As" window:
    • Choose a folder in which to save your new html program (Desktop is always easy to find).
    • Change the value in the "Save as type:" drop down box to "All Files (*.*)".
    • Specify a file name in the "File name:" text field like "test.html" or "test.htm".
  6. You've just created your first web page! Open your choice of web browsers and open the file you just created by pressing Ctrl-O.
  7. Navigate to where you saved the file, and open it.
  8. If all went well, you'll be staring at your first web page.
  9. Pat self on back!

Structure

So what's all that stuff that you just copied? Here's a breakdown of what the code represents:

<!DOCTYPE html>

The doctype tells browsers and validators the html specification to which the html code conforms.

<html lang="en">

The html opening and closing tags indicate the beginning and end of the HTML document (respectively).

<head>

The head opening and closing tags mark the beginning and end of the document header.

<title>

<title> states the title of the document.

Meta Tags

Meta tags are used to provide data about the web page that will not be seen by the web surfer unless they view your web site's HTML.

<body>

The <body> tags delineate the section that holds everything that is actually displayed.

More to come

The above example also includes the <h1> and <p> tags, which will be discussed in the upcoming "Page Contents" section.

Section 3: Page Contents

The content of your HTML page resides within the <body> tag.

Headings

Headings add section titles to a page.

HTML defines six levels of headings.

Here is what is displayed by the above code (using default formatting):

Think of headings as items in an outline.

Headings 4 through 6 aren’t visually interesting, but they do have meaning in terms of the document’s structure.

Notes about Headings
SEO and Headings

In her (now vanished from the web) article titled Why Do Search Engines Like H1 Tags, professional web developer and author Jennifer Kyrnin explained

Paragraphs

Ordinary paragraphs can be added to a page using the <p> tag.

When browsers read a paragraph tag they automatically add an extra blank line before and after a paragraph.

Incidentally, this line, as well as the two above it, are paragraphs. Like paragraphs in an essay, they can be made up of multiple lines.

Here is an example:

<p>Actually, all education is self-education. A teacher is only a guide, to point out the way, and no school, no matter how excellent, can give you education. What you receive is like the outlines in a child’s coloring book. You must fill in the colors yourself.</p>

This is what the code above produces (using default formatting):

Line Breaks

The <br> tag is used when you want to end a line, but don't want to start a new paragraph.

The following example shows a simple paragraph in which each line ends with a <br> (except for the last, which ends with a closing </p> tag):

<p>Life’s but a walking shadow; a poor player,<br> That struts and frets his hour upon the stage,<br>And then is heard no more: it is a tale <br> Told by an idiot, full of sound and fury,<br> Signifying nothing.</p>

This is what the text above looks like using default formatting when viewed in a browser:

Horizontal Rule (Solid Line)

The <hr> tag is used when you want to insert a horizontal line in an HTML page.


Simple Lists

The web pages you create with HTML5 often contain data organized into lists, which can stand alone or be nested within each other.

There are various types of lists in HTML5, but for now we'll limit ourselves to simple ordered and unordered lists.

Here is an example of each.

Ordered list
  1. First item.
  2. Second item.
  3. Third item.

Unordered list
  • First item.
  • Second item.
  • Third item.

Ordered and Unordered Lists

Links

To create a link in an HTML page, you use the <a> tag.

Syntax

You create a link with the following syntax:

<a href="http://www.isu.edu">Idaho State University</a>

The href attribute is used to specify the URL of the document to which to link, and the words between the open and close of the anchor tag will be displayed as a link.

The example code above results in the following link:

Idaho State University

More coverage of link syntax can be found in the Hyperlinks notes.

SEO and Anchor Text

Anchor text is the visible, clickable text in a hyperlink.

Search engines use anchor text to help determine the subject matter of the linked-to document.

List of Links

You can create lists of links using anchor tags in list items:

<ul>
<li><a href="http://www.isu.edu/">Idaho State University</a></li>
<li><a href="http://isu.edu/cob/">ISU College of Business</a></li>
<li><a href="https://www.isu.edu/business-informatics/">Informatics @ ISU</a></li>
</ul>

The example code above results in the following list of links:

Section 4: Grouping Tags

This section will discuss the legacy grouping tags (<div> and <span>) and the new section tags (<header>, <section>, <article>, <nav>, <aside>, and <footer>).

<div> tag

A <div> tag is used to define a generic container or division within the content of an an HTML document.

Click the plus sign to see a <div> tag in action: plus

<span> tag

The span element is an inline container for pieces of text, used for grouping and applying styles to inline elements.


Section 5: Comments

The comment tag is used to insert a comment in the HTML source code.

Justification for Comments

As HTML has evolved toward "semantic" HTML, in which tags actually provide context or meaning, HTML comments may seem less critical than in the past.

It is a good practice to add comments into your HTML code, especially in complex documents, to indicate sections of a document, and any other notes to anyone looking at the code. Comments help you and others understand your code and increases code readability.

Commenting in HTML allows developers to leave notes about their code, its functionality or to indicate necessary changes for the future.

The page How Good Are Your HTML and CSS Comments? provides great explanations of why you should include comments.

Caution

Be careful when inserting comments before the !DOCTYPE line. It seems to be accepted now, but it used to make the validator angry!

Section 6: Validation

There are several good reasons to validate HTML documents

Section 7: Let's Play

Click the "Edit and Click Me >>" to see the results of the html code in the left panel in the panel on the right.

Then, play around with the html code, making changes and seeing the effect of those changes in the right panel.

Section 8: Resources