Beginner's Guide to HTML
This is intended as a concise introduction to very basic HTML
programming for the purpose of generating simple web pages. Detailed
explanations, tutorials and more advanced guides to HTML are available
from the W3C website and elsewhere on
the web, or visit your local bookstore for a handy reference. Another
good way to learn is by example: if you see a page you like,
right-click on the page and select "View Page Source" to see the
underlying HTML that created it (this only helps if the page is
cleanly scripted). As an example, view a simple HTML page with all the
basics.
HTML documents are written in ascii (plain-text) and can
be created using your favourite text editor (e.g. Emacs, vi,
Notepad, SimpleText). If you are using word-processing software,
be sure to save your document as "text only with line breaks".
Example markup is shown below in red, and
the results are generally shown in green.
Note that the tag contents are case-insensitive.
Contents:
Page essentials:
- The first line must be one which tells the browser that it is looking
at an HTML file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- All documents must then begin with the <HTML> tag, and end with the </HTML> tag. ALL of the document
source goes between these tags.
- Every document should include a header. This header can include
a document title (which appears on the top bar of most browsers) and
various other items that we won't go into here. Include the following
after the opening <HTML> tag of your document and enter whatever
page title you want:
<HEAD>
<TITLE>This
is my page title</TITLE>
</HEAD>
- Next, start the body of the document with a <BODY> tag, and end it with a </BODY> tag. All of the content (text,
images, etc.) of your document should go between these body
tags.
You can specify certain page decorations in the opening body tag, such
as background image or colour, font colour, margins and so on.
For example:
<BODY background="bgimage.gif" bgcolor="#DDDDDD" text="black"
link="blue" vlink="red">
would set the background image to be bgimage.gif (tiled), the
background colour to light gray (#DDDDDD), text to black, links
to blue and visited links to red.
--- Top ---
Headings:
Headings can be specified on a page by surrounding them with
the appropriate header tag, as shown below. Font sizes may vary,
depending on your local setup.
- <H1>Very Important Heading</H1>
Very Important Heading
- <H2>Important Heading</H2>
Important Heading
- <H3>Less Important Heading</H3>
Less Important Heading
- ... and so on down to H6.
--- Top ---
How to centre:
Simply enclose the item in <CENTER>
and </CENTER> tags (note the spelling).
You can do this to an entire document, a single paragraph, table or
heading.
--- Top ---
Spaces, line breaks and paragraphs:
- A forced line break is made using <br>
- Each new paragraph should begin with a <p> tag, and (optionally) end with </p>.
- A no-break space is created using (note the trailing semi-colon).
You can string a line of these together if you want to leave more
space, although this can be rather inelegant.
- Horizontal lines can be generated using
<hr>. You can specify the width
and length
of the rule using (for example) size="4" and width="50%" within the tag,
respectively.
--- Top ---
Example of a Basic Web Page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>A Basic Web Page</TITLE>
</HEAD>
<BODY>
<CENTER>
<H1>My Web Page</H1>
</CENTER>
<P>Welcome to my very basic web page.
Here is my first paragraph.</P>
<P>And here is my second paragraph.</P>
</BODY>
</HTML>
Copy the paragraph above into a file called index.html, and
view the file using your browser to see how it looks.
--- Top ---
Text Decorations and Colour:
To add emphasis to words:
- bold:
<b>bold</b>
- italics:
<i>italics</i>
- emphasis:
<em>emphasis</em>
- underline:
<u>underline</u>
- typed:
<tt>typed</tt>
Font tags (note that you can combine colour and size settings
in a given tag):
- Blue Text: <FONT
COLOR="blue">Blue Text</FONT>
- Text of Another Colour: <FONT COLOR="#FF22BB">Text of Another
Colour</FONT>
specified as hexadecimal
numbers for red, green and blue
- Bigger Text: <FONT
size="+1">Bigger Text</FONT>
- Smaller Text:
<FONT size="-1">Smaller Text</FONT>
--- Top ---
Special Characters:
<, >, and & have special meanings in HTML, so you must use
the following escape sequences to enter these characters. Some other
useful special characters are also shown below.
Note that these are case sensitive!
- < <
- > >
- & &
- ± ±
- × ×
- ÷ ÷
- ˜ ˜
|
- é é
- ¢ ¢
- µ µ
- °C °C
- Å Å
- x² x²
- y³ y³
|
- § §
- ¶ ¶
- © ©
- ® ®
- ™ ™
- – –
- — —
|
Warning: Some older browsers (e.g. Netscape 4) may not render some of
these characters correctly.
--- Top ---
Lists of Various Kinds:
- Unordered Lists (with bullets):
Begin with <UL> and end with
</UL>.
Each list item begins with <LI>
and (optionally) ends with </LI>
- Ordered Lists (numbered items):
Begin with <OL> and end with
</OL>.
Each list item begins with <LI>
and (optionally) ends with </LI>
- Definitions:
Begin with <DL> and end with
</DL>.
Each defined term is enclosed in <DT>
and </DT> tags.
Each term's definition follows the closing </DT> tag, and
is itself enclosed in <DD>
and </DD> tags.
--- Top ---
Simple tables:
- Tables always begin with a <TABLE>
tag, and end with </TABLE>
- Each row of the table is surrounded by table row tags <TR> and </TR> (TR = table row)
- Each table cell entry is within <TD>
</TD> tags (TD = table data).
- You may specify column headings within <TH> and </TH> tags
(TH = table heading).
Here is an example of a 2 column by 3 row table:
<TABLE>
<TR> <TH>Student</TH> <TH>Grade</TH> </TR>
<TR> <TD>Jack</TD> <TD>70%</TD> </TR>
<TR> <TD>Jill</TD> <TD>82%</TD> </TR>
</TABLE>
would appear as follows:
| Student | Grade |
| Jack | 70% |
| Jill | 82% |
More table features:
- Add a border around your table by including border="1" within
the opening table tag. Use numbers
greater than 1 for thicker borders.
- Stretch your table by including width="100%" (this will make it
the full width of your browser window).
- You can specify a background colour for the table using
bgcolor="colourname" within the opening table tag. You can also
specify this in an opening table row tag or table data tag to control
the colours of particular cells.
- The internal spacing of the cells is controlled by the
cellpadding option within the opening table tag.
- Control alignment within the table using align="center", align="left"
or align="right". You can do this in the opening table tag or in individual
table cells.
<TABLE bgcolor="#BBBBBB" border="1" cellpadding="10" width="60%">
<TR bgcolor="#999999" align="center">
<TD>Student<br> Number</TD>
<TD>Assignment Mark<br> (40)</TD>
<TD>Exam Mark<br> (60)</TD></TR>
<TR> <TD>555-1234</TD> <TD>36</TD> <TD>50</TD> </TR>
<TR> <TD>555-5678</TD> <TD> </TD> <TD>34</TD> </TR>
<TR> <TD>556-9912</TD> <TD>29</TD> <TD>48</TD> </TR>
</TABLE>
would appear as follows:
Student Number |
Assignment Mark (40) |
Exam Mark (60) |
| 555-1234 | 36 | 50 |
| 555-5678 | | 34 |
| 556-9912 | 29 | 48 |
Additional table tips:
- Tables are generally a great way to "format" a page,
to arrange text blocks, lists and/or images in an appealing fashion.
You can nest tables within cells of other tables, just take care
to keep track of your opening and closing tags!
- If you use a border, empty cells should contain a no-break space
( )
--- Top ---
Links:
To link to another web page, surround a relevant piece of text
with a link tag as follows:
<A href="http://www.google.ca">Google
Search</A>
results in the link
Google Search
Don't forget the quotes around the URL (href=""). These tags are also
called "hyperlinks" or "anchors".
If you are linking to a local file, you don't need the
http://www.webpage.com part, but
you should include the absolute path to the HTML file (this depends on
how your web server is set up). If in doubt, precede the file name with
http:// and the complete URL as shown above.
--- Top ---
Embedded Images:
- The image tag specifies the name of the source image file,
including its path:
<IMG src="path/filename">
The image file itself must be world-readable for the image to appear.
Note that there is no closing image tag.
- Acceptable embedded image formats include jpegs, gifs and pngs.
- Include an alt="title" statement in the image tag, in case the
image cannot be loaded or someone is browsing your page with a
text-based browser.
- You can control the width of your image using statements like
width="350" (absolute pixel width) or width="20%" (relative width,
changes with browser size) within the image tag. It is generally
preferable to scale the image itself to make it the size you want
(so it takes less time to load and maintains its resolution). You
can specify the height as well (e.g. height="500"), but beware the
dangers of messing with natural image aspect ratios.
- You can place the image tag within link tags if desired. If you
want to get rid of the border around the image in this case, add
border="0" within the image tag.
<A href="http://www.physics.queensu.ca/"><IMG
src="stirling.gif" alt="Stirling"></A>
gives
--- Top ---
A Few Tips:
- Close your tags! For example, if you have a
<CENTER> tag, you should also have a </CENTER> tag
later on.
- Not all web browsers are created equal: If your web page
looks stunning under Internet Explorer, it may not look quite
so nice under Netscape, Mozilla, Galeon, w3m, links, etc. If
you follow the official HTML standards, you are probably fine.
Run your page through the HTML Validator to make
sure. Also, try viewing your web page using different browsers
to see how it looks.
- Bandwidth limitations: Much of the world is still
browsing the web by modem, and download time is a serious
issue. Large images take a long time to view over a slow
network connection: a mere 5 kbytes per second can typically be
downloaded with a 56K modem. Typical users will wait for 10-15
seconds for a page to download before losing patience. Keep
the end user in mind and make your embedded images relatively
small.
- Use quotes. When specifying parameter values within
tags, use the quotes as shown above. For example, while
<IMG src=stirling.gif> will still work under most
browsers, it is not valid HTML. <IMG
src="stirling.gif"> is the way to do it.
- Stop spam! We all hate getting junk email. Ever wonder
how They got your email address? One easy way is to put it on
your web page: automated "spambots" hunt the web for email
addresses and add them to spam lists. Our advice is to keep
your email address out of your HTML pages entirely, or at least
to hide it using something like: user@[snip this
out].com (this may not always work).
- Frames: There are certain cases when frames within web
pages are useful, but be aware that not all browsers support
frames. The core Physics pages you see here are 100%
frame-free thanks to the use of tables, although this method
also has its drawbacks. We don't recommend the use of frames
within departmental web pages.
- Java and JavaScript: If you want to add Java applets or
JavaScript bells and whistles to your page, go ahead. It's not
generally a good idea to rely on browsers having either of
these enabled: the world should be able to easily manoeuver
your pages without requiring them. Again, keep the end-user
and bandwith limitations in mind.
--- Top ---
Now What?:
So, now you have enough to make up a simple HTML page. See our sample for a complete
example. Now what do you do?
Your file should have a .html extension: name your front web page
index.html, for example. You need to make the document and any
of its embedded images accessible from a web server (a computer which
"serves up" web pages) within a directory which can be read by the
general browsing public. This may be a directory called
public_html on the Physics web server (or your group's). You
should contact your system administrator for instructions about
this.
By the way, you can make separate web pages for things like research,
teaching, and photos of your kids. Give each HTML page a .html extension
(e.g. research.html) and link to them as specified above.
More about building a local website
More about HTML from W3C
--- Top ---