HTML: Basics

Anatomy of a Website

Content: Text, Media

+  HTML: Structure + Semantics

+   CSS: Presentation + Design

+    JS: Interactivity

= Your Website

HTML: "HyperText Markup Language"

It is:

- A text file that is "marked up" with tags
- Saved with .html extension
- The native language of web browsers.

It should be:

  • Semantic
  • Accessible

☞ Read more: How disabled people use the internet

Anatomy of an HTML tag

Each tag has a "start tag", "end tag", some content in between, and optional attributes.

<tagname attribute="value">

<a href="" >

Think of a tag as a "command" to the browser and of the attributes as modifiers of that command.

The Basic HTML file

<!DOCTYPE html>

The doctype isn't an actual tag, but it needs to be at start at every HTML page to tell browser which version of HTML you're using (HTML5 here).

The html tag is always the first, root tag in the page.


<!DOCTYPE html>
  <meta charset="utf-8">
  <title>Title of your page goes here</title>

The head contains "meta" information about the page, information that the browser needs before rendering.

The Body

<!DOCTYPE html>
  <meta charset="utf-8">
  <title>Title of your page goes here</title>
  Bulk of your content here.

The body contains the actual content of the page.

What goes in the body?


<h1>Header 1</h1>
<h2>Header 2</h2>
<h6>Header 6</h6>

Header 1

Header 2

Header 6


<p>Paragraph 1</p>
<p>Paragraph 2</p>
<p>Paragraph 3</p>

Paragraph 1

Paragraph 2

Paragraph 3

Line Breaks

Imagine there's no Heaven <br>
It's easy if you try <br>
No hell below us  <br>
Above us only sky <br>

Imagine there's no Heaven
It's easy if you try
No hell below us
Above us only sky

Notice: This tag does not need to be closed, since it doesn't encapsulate anything.


  <li>Item 1</li>
  <li>Item 2</li>
  • Item 1
  • Item 2
  • ...

Ordered Lists

  <li>Item 1</li>
  <li>Item 2</li>
  1. Item 1
  2. Item 2
  3. ...

Formatted Text

<em>Emphasized Info</em>
Emphasized Info
<strong>Important Info!</strong>
Important Info!
You can have <em>emphasized info</em>
and <strong>important info</strong>
in the same paragraph.

You can have emphasized info and important info in the same paragraph.


<img src="" 
<img src="" 
  alt="Google" height="50">
<img src="
lights-christmas-graphic55.gif" alt="">

When Should Alt Text Be Blank?

- Show how to copy/paste image URL in browser - Explain dangers of hotlinking. - Talk about relative vs. absolute URLs - Talk about not loading giant images.


<a href="">Google</a>
<a href="">
  <img src="" 
<a href="" target="_blank">Google</a>
Google (in new window)

Why External Links Should Open in New Tabs

Internal Links

<p>Jump to <a href="#chapter1">the first chapter!</a> </p>

<h1 id="chapter1">Chapter 1</h1>

<p>Most exciting story in the world. To be continued...</p>

<p>
<a href="">Wikipedia</a>

Jump to the first chapter!

Chapter 1

Most exciting story in the world. To be continued...

Read more on Wikipedia

HTML Comments

<!-- I can comment for humans here. -->

I can write a comment that
spans multiple lines too.
Commonly used by snippet providers (like AddThis):
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
  <a class="addthis_button_preferred_1"></a>
<script src="">
<!-- AddThis Button END -->

HTML Readability

  • Use quotes around attributes
  • Indent to represent nesting
  • Use same capitalization
<ul><li><a href=>Google</a></li>
   <li><a href="">Google</a></li>
Using Whitespace for Readability in HTML/CSS

Developing & Debugging

HTML: Editors

Since HTML files are just text files, many programs can be used to create them. Some programs provide special assistance for handling HTML, like syntax-highlighting or autocompletion.

Free Notepad++ TextWrangler, Smultron Cloud9 IDE, JSBin
$$ E-Text Editor SublimeText, TextMate, Coda, Espresso

HTML Debugging

  • Chrome: Right-click -> "Inspect Element"
  • Firefox: Right-click -> "Inspect Element" -> "HTML"
  • IE: Open Tools -> Developer Tools


HTML Validators

Browsers will often render HTML that has mistakes in it, using different error correction strategies.

To check that your HTML is actually valid according to the standard, run it through the W3C validator.

You can also install the validator add-on for Firefox.

HTML Resources

When you're on your own and trying to code HTML, do a search for the tag you're using ("img tag" or "li tag") and you will usually find good references at the top.

W3Schools is a simple to read reference with interactive examples & will often be the top result. The HTML spec is the official reference, but can be harder to read.

For more tutorial type sites, check out Mozilla Developer Network and the Opera Web Standards curriculum.