HTML Tutorial – basics

On this page:

top

This tutorial: how to use it
The basic tags:   page structure paragraph: <p>
line break: <br />
headings: <h1><h6>
lists: <ol> <li> , <ul> <li> , <dl> <dt> <dd>
formatting text bold: <b>
italic: <i>
links anchor: <a>
id: id="x"
graphical elements image: <img src="image.jpg" />
tables: <table> <tr> <th> <td>
All these tags are of two kinds:   block tags and inline tags
A real web page also has these page tags: html <html>
head <head>
title <title>
body <body>
And the web page code may have comments: <!-- a comment would go here -->
 
How to use this tutorial

top

  1. Read 1-how_to_learn_html.html to learn how to make web pages.
  2. Practice, practice, practice:
    • Using your text editor, type the code examples on this page.
    • Using your web browser, view the results!
    • Change code in your editor ... view in the web browser ...
    • And do it again. And again.
  3. Learn how to fix problems
  4. Find answers to html questions
How this page is organised

top

The left column gives explanations about the html tags.

The right column gives the:

html code to type in your editor

and the:

result you should see in your web page
 
Tags for page structure:

top

paragraph | headings | list
paragraphs

Make paragraphs:

<p> - the paragraph tag

<p>
some text
</p>

Creates a paragraph. Puts extra space above and below.

example code:

<p> Here is a paragraph. Notice that the browser doesn't care about "white space". The browser will make one long line for the paragraph, and it will "wrap" the line to the width of the paragraph. </p> <p> Here is another paragraph, to show how the p tag will put some space between paragraphs. </p>

result in web page:

Here is a paragraph. Notice that the browser doesn't care about "white space". The browser will make one long line for the paragraph, and it will "wrap" the line to the width of the paragraph.

Here is another paragraph, to show how the p tag will put some space between paragraphs.

Align the paragraph text:

With the attribute align:

<p align="DIRECTION">
some text
</p>

Aligns a paragraph horizontally.

"DIRECTION" is either "left", "right", or "center".

example code:

<p> This paragraph is aligned to the left. (If you don't give any "align" at all, the paragraph will always align to the left.) </p>

result in web page:

This paragraph is aligned to the left. (If you don't give any "align" at all, the paragraph will always align to the left.)

example code:

<p align="right"> This paragraph will be aligned to the right. It will still be the full width – the right edge will be lined up, instead of the left. </p>

result in web page:

This paragraph will be aligned to the right. It will still be the full width – the right edge will be lined up, instead of the left.

example code:

<p align="center"> This paragraph will be aligned in the center. We don't use this very often, because it is hard to read. </p>

result in web page:

This paragraph will be centered. We don't use this very often, because it is hard to read.

Make a line break:

<br />

The break tag.

You can use the break tag for any text: in paragraph, headings, lists – anywhere.

We don't use this tag often.
Don't use 2 break tags when you mean another paragraph!

example code:

<p> Here is some text <br /> and some more. </p>

result in web page:

Here is some text
and some more.
headings

Make page headings and sub-headers:

Don't confuse the 'heading' tags (<h1>, <h2>, etc.) with the 'head' tag (<head>) they are different!

<hl> - the heading tag

<hl>some text</hl>

Creates the top-level headline – the title of your page

example code:

<h1> This is a level 1 heading </h1>

result in web page:

This is a level 1 heading

<h2>some text</h2>

Creates a second-level headline – a subsection of your page.

The heading tag goes down to level 6 (<h6>), but we usually don't go down further than h3.

example code:

<h2> This is a level 2 heading </h2>

result in web page:

This is a level 2 heading

lists
There are three kinds of lists in html:
ordered lists
unordered lists
definition lists

ordered lists:

<ol></ol>
Creates an ordered list

<li></li>
Makes one line for each list item, and adds a number

example code:

<ol> <li> ice cream </li> <li> oats porridge </li> <li> chocolate </li> </ol>

result in web page:

  1. ice cream
  2. oats porridge
  3. chocolate

unordered lists

<ul></ul>
Creates an unordered list

<li></li>
Encloses each list item, and adds a bullet.

example code:

<ul> <li> ice cream </li> <li> oats porridge </li> <li> chocolate </li> </ul>

result in web page:

  • ice cream
  • oats porridge
  • chocolate

definition lists

<dl></dl>
Creates a definition list

<dt>term</dt>
For each "definition term"

<dd>definition</dd>
For each "definition data".
Usually indents from the <dt> term.

We don't use the definition list very often.

example code:

<dl> <dt> ice cream </dt> <dd> Food of the gods. </dd> <dt> oats porridge </dt> <dd> A delicious and filling breakfast, especially in winter. </dd> <dt> chocolate </dt> <dd> The best chocolate is bittersweet and hard to bite. </dd> </dl>

result in web page:

ice cream
Food of the gods.
oats porridge
A delicious and filling breakfast, especially in winter.
chocolate
The best chocolate is bittersweet and hard to bite.


Formatting text

top

Here are the html tags for making text bold or italic. We don't use these tags very often. To change font size, color, and many other nice things, we usually use stylesheet (css) language.

<b> - the bold tag

<b>some text</b>

Makes text to be bold

example code:

<p> Here are some <b>bold words</b>. </p>

result in web page:

Here are some bold words.

<i> - the italic tag

<i>some text</i>

Makes text be italic.

example code:

<p> Here are some <i>italic words</i>. </p>

result in web page:

Here are some italic words.


Links

top

Links are what the web is all about! The <a> tag makes links.

Linking to websites, pages, or parts of a page: <a> - the a tag. Makes an anchor.

<a href="URL">some text</a> creates a link, or hyperlink reference.

The "URL" is the web address. It is the name of the file you want to go to. It can be a file on your website, or another website.

"some text" is the words that the user will see in the web browser, that they can click on.

Link to a website:

http:// tells the web browser, that we want to go to a different website.

The section between the // and the next / is the "domain name" or "host name" of the website.

Anything after that is the path to the web page you want to link to.

<p> The <a href="http://tibetangeeks.com/"> TibetanGeeks.com</a> pages have (almost) everything James knows about the web. </p>

result in web page:

The TibetanGeeks.com pages have (almost) everything James knows about the web.

Link to another page on your website:

example code:

<p> Read about <a href="3-how_to_fix_html_problems.html"> how to fix html problems</a>. </p>

result in web page:

Link to a location in the same web page:

This requires two tags:

The "target" location has an id:

id="NAME"

Any tag can have an id. So your target could be a paragraph, a subheading, an image, etc. For example:

<h2 id="about">About our school</h2>

Then the link gives that target name, with a #:
<a href="#about">Read about this school</a>

example code:

<p id="here"> Here is the target. </p>

result in web page:

here is the target


example code:

<p> Click to go to the <a href="#here">target</a>. </p>

result in web page:

Click to go to the target.

Link to a location in another web page:

This also requires two tags:

The "target" location with the id, is in the page you want to link to:

id="NAME"

<h2 id="about">About our school</h2>

Then the link gives that web page filename, and the target name with a #:
<a href="our_school.html#about">Read about this school</a>

example code – This is in another page: 4-html_faq.html

<th id="writing_good_code"> writing good code </th>

result, in the web page 4-html_faq.html

writing good code

example code, in this page:

<p> Read about how to <a href="4-html_faq.html#writing_good_code"> write good code</a>. </p>

result in this page:

Read about how to write good code.


Graphical Elements

top

images

Show an image (photo, graphic, etc):

<img> - the img tag. Displays an image in the page.

<img src="LOCATION"
alt="DESCRIPTION" />

src means "source".
"LOCATION" means "the path to the image file" — that is, the folder where the image file is. The folder should be inside the same folder with your other web pages. In the example on the right, the dalai_lama-sm.jpg file is in a folder called images. And this folder is in the same folder with the html page.

alt means "altternate".
"DESCRIPTION" is a word or two that tells what the image is about. It is an "alternate", or "other", way to tell about the image.

There are other attributes we can use for the img tag: width, height, align, and more.
For more about images, see 5-media_tutorial.html, and also follow the links below.

(Remember that the image is still a separate file. It does not become part of your html file, as it would for instance in MSWord become part of your Word file.)

example code:

<img src="images/dalai_lama-sm.jpg" alt="His Holiness Dalai Lama" />

result in web page:

his holiness and the himalayas

An image seems like it would be a "block tag", because we see a rectangle in the browser. But the img tag is actually an inline tag: Images will float next to other images or text, inline. We can tell the image which direction to float, with the align attribute:

example code:

<p> <img src="images/dalai_lama-sm.jpg" align="right" alt="His Holiness Dalai Lama" /> Here is a picture of His Holiness ... </p>

result in web page:

his holiness and the himalayas Here is a picture of His Holiness the Dalai Lama. We are using it to also demonstrate how we align a picture with some text. By using align="right", we tell the browser to float the picture to the right, and wrap the text to the left around the picture.

Movies, sound, etc.

See 5-media_tutorial.html



Tables

top

The <table> tag was invented for scientists to display their data, the same way you would use an Excel spreadsheet. In the old days we also used table code to lay out our page design. Now we use <div> tags and CSS language for page design.

making a table

<table> - the table tag

<table></table>
Starts and ends a table.
The only thing that can go between the table (<table>) tags, are the row (<tr>) tags (and then the cell <th> or <td> tags). Any other tags will "float" outside the table!
<tr></tr>
The table row tag marks each row of a table.
The only thing that can go between the row tags, are the cell (<td>) or heading (<th>) tags. Anything else may "float" outside the table, or do something unpredictable.
<td></td>
The table data tag sets off each cell in a row.
Any html can go between the cell tags - text, an image, even another table.
<th></th>
The table heading tag sets off a table heading cell (a normal cell, with usually bold, centered text)
Any thing can go between the heading tags also.

table attributes

To see how to use these attributes, look at the code for the example tables to the right.

<td colspan="NUM">
'colspan' = sets number of columns a cell should span

<td rowspan="NUM">
'rowspan' - sets the number of rows a cell should span.

<table border="NUM">
'border' - sets the width of the border around the table cells. Later in real pages we will make table and cell borders with CSS language

<table cellpadding="NUM">
'cellpadding' - sets amount of space between a cell's border and its contents.

<table cellspacing="NUM">
'cellspacing' - sets the amount of space between table cells.

<table width="NUM">
or
<table width="NUM%">
'width' - sets width of table, in pixels or as a percentage of page width.

Later we will learn how to do all these things with CSS language.


column (cell) display attributes

A "column" (cell) is a <td> or a <th>

We can use CSS language to set the width and text alignment of a cell:

<td style="width: NUM;">
width - sets how wide the cell should be
NUM can be a number (which will mean pixels), or a percent (which will mean the percentage to use of the entire table width).

<td style="text-align: ALIGN">
text-align - sets alignment for content of cell(s).
ALIGN can be left, center, right.

examples:

here is a simple (and boring) table:

<table> <tr> <td>one</td> <td>two</td> <td>three</td> </tr> <tr> <td>༡</td> <td>༢</td> <td>༣</td> </tr> </table>

one two three

The same table with some attributes

<table cellpadding="20" cellspacing="0" border="1"> <tr> <td>one</td> <td>two</td> <td>three</td> </tr> <tr> <td>༡</td> <td>༢</td> <td>༣</td> </tr> </table>

one two three

Using th (table heading)
and
Using colspan

<table cellpadding="8" cellspacing="0" border="1"> <tr> <th colspan="3">Parts of Tibet</th> </tr> <tr> <td>Amdo</td> <td>Kham</td> <td>Lhasa</td> </tr> <tr> <td>Dhomey</td> <td>Dho du</td> <td>U-Tsang</td> </tr> </table>

Parts of Tibet
Amdo Kham Lhasa
Dhomey Dho du U-Tsang

Now what can we do with tables!

  • Tables are made to be used for data: rows and columns of information.
  • We can put anything inside a table cell — even another table!

One example: Check your email: the lines of emails with date, subject, and who from is made with table code.)

Below are some small examples. (They are using CSS language for the colors, background, etc.)

This table is used to display images.
It is using the same table code as the simple tables above, but the cells with photos contain img tags inside the td tags, and the captions are in p tags inside the td tags.

Dalai Lama Kalmiopsis Valley A logo

His Holiness Dalai Lama

The Kalmiopsis Valley in Oregon, USA

A logo

This table uses a small repeating image for the background.
Click to see the code for this table.

animals we like
sheep In asia sheep are small and wooly. In america sheep are very fat and wooly, and really really stupid. Goats everywhere look intelligent, but maybe they aren't. Yak and dri live only in tibet, because they are very intelligent.
goats
yak
dri

This table uses one image for the background.
Click to see the code for this table.

This is one of james' homes. It is called the Kalmiopsis, in southern Oregon. The animals of james' home are:
eagle
hawk
owl
elk
deer
wolf


Table exercise

top

When you are able to lay out a complicated table, you will be ready to do page design and learn CSS language.

Exercise 1:
Make a table that looks like this

Follow the instructions below:

  • Put some nice words where it says 'words' and 'list'.
  • Put a small image where it says 'image'.

Hints:
The table has 5 rows and 3 columns.
You will need to use colspan and rowspan.

Exercise 2:
Make a table that looks like this

Follow the instructions below:

  • Put some nice words where it says 'words'.
  • Put a small image where it says 'image'.
  • I put dotted lines across the rowspans and colspans, to help you see the rows and columns in your mind. Don't make them in your table!

Hints:
The table has 4 rows and 4 columns
You will need to use colspan and rowspan.


 
Three kinds of tags

top

All web pages are made with html tags.
Each tag makes a "box".
There are three different types of tags: block, inline and page tags.
  • block and inline are both tags for displaying in the web browser.
    They are only in the <body> part of the file.
    They display in the browser.
  • page tags are directions for the web browser itself.
    They are only in the <head> part of the file.
    They don't display in the browser.
1. block
The block tags are those such as <p>, <h1> Like a stack of bricks, one block will be underneath another block.
2. inline
The inline tags are those such as <b>, <i>, and <a>.
They float along "inline" with the other contents inside a block.
<table> and <img> are not actually block tags! They are inline tags.
The best way to understand block and inline tags:
Try in a web page, mixing them together, and see which ones stack like blocks, and which ones flow inline.
3. page
page tags are directions for the web browser itself. They don't display in the browser.
Real web pages use the page tags explained below ↓
 
A real web page

top

Real web pages have some basic parts that we always use on real websites.

The page tags tell the browser which part of the web page is information for the browser (in the <head> tag), and which part is to be displayed (in the <body> tag).

Two little things: doctype and meta character set tags

A web page is like many parts in a little machine. So we need to tell the web browser some things to help it run our machine.

  1. Which version of html we are using
    We do this by showing something called "document type".
    How to do it: Paste the following into the very first line of all your html pages, before the <html> tag:
      <!DOCTYPE html>
      

  2. It is also good to tell the browser which "character set" we are using. This enables the browser to display Tibetan font, and other good things.
    How to do it: Paste this before the <title> tag (in the <head> part of your html page):
      <meta charset="utf-8" />

This template shows where we put the doctype and character set tags.

All your web pages should have these two things. You don't really need to know everything about these now! Just do it :) Later we can learn more what these are all about.

The structure of a web page

<html> </html>
Starts and ends an HTML page

<head> </head>
Holds the title tag. The title is displayed at the top of the browser window.
Also holds other information that isn't displayed on the Web page itself (like meta tags, stylesheet, javascript), which we will learn later.

<body> </body>
Holds the part of the web page that you see in the browser. The html tags that you learned above all go between the body tags.
[more about the body tag]

A web page, like a person, has one head and one body - no more and no less!

example code:

Here is the code for a basic web page:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title> Your Page Title Goes Here </title> <link rel="stylesheet" href="/path_to_css_file/style.css" /> </head> <body> <h1> Your Page Heading </h1> <p> Your content goes here. With more tags and images and all the good things. </p> </body> </html>

And this will make a web page that looks (more or less :) ) like this:

Your Page Heading

Your content goes here. With more tags and images and all the good things.



Title Tag

<title> - the title tag Puts the text in the title bar of the browser.

The title tag never has any attributes, and there are never any html tags in the text of the title.

The title may seem like a small thing, but it can be really helpful, or very unhelpful, to your user:

The title text is also used by the browser in its history list, bookmarks ("favorites"), and 'back' and 'forward' button menus. Also it is used by search engines, to display when they find your page.

example code:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title> My Great Page </title> </head>

Now the title bar at the top of the web browser will say "My Great Page".



Body Tag

<body> - the body tag

The body tag holds the content that you see in the browser. That is, everything that the user sees in the web page, is inside the <body> tag. All the block and inline tags go between the <body> tags.

<body>
all the content of
the web page goes here
</body>

example code:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title> My Great Page </title> </head> <body> <p> all page content goes here. </p> </body> </html>

result in web page:

all page content goes here.


 

Comment Tag

And here's one last thing, that is not required, but is very useful to you:

<!-- --> - the comment tag

The comment tag is for notes you want to make for yourself. Nothing inside the comment tag is seen on the web page.

example code:

<-- note to self --> <p> all page content goes here. </p>

result in web page:

all page content goes here.



 
 
More information
  • In this directory there are more files explaining about html.

This page has only the most common tags. There are more!

  • This links page lists some good websites about HTML.


copyright / license

top

Q: Can i copy this file? Can i give to other people?

Answer:

Sure, you can give it to anyone, according to the terms of the license below. It is copyright © 2004 James Walker.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included here.

If not found, find it at www.fsf.org - the Free Software Foundation.



translation

top

It would be very useful to have translations of this document in any language. Most preferred would be Tibetan and Chinese. Please contact me if you can do a translation for us.



contact

top

Was this helpful? Is it clear, or confusing? I would be happy to hear anything about how to make this better. You can contact me at the email address i have given you, or at http://www.webwalker.to/contact.php