Basic HTML Tags v13
Basic HTML Tags v13
Note: About compatibility of HTML and XHTML and HTML5 (in the works)
1. Absolutely Essential
Html, head, body, title, h1-6, and comments tags and !DOCTYPE declaration
2. Lining Up Text
Paragraph, break line, center and div tags,
Align attribute for paragraphs, headlines, divs, and horizontal lines
Blockquote, and Preformatted tags
Horizontal Rule tags with width, size and noshade attributes
4. Lists
Unordered list (plain and bulleted) and ordered list and list item tags
5. Links
Anchor, hypertext reference tags, name attribute
Relative and absolute addressing
6. Tables
Table, table row, table header, table data item tags, with Align and
vertical align attributes
Width and border attributes for tables
Column span and row span tags
7. Inserting Graphics
Img tag with src and align attribute
Tiling
2. Certain tags are “empty” and in HTML did not require a closing tag- notably <hr>,
<br>, <img>. In XHTML all tags must be closed. So, for example <br />.
Empty tags should be closed in the minimized format, and with a space before the
slash: <hr />, <br />, <img src=”myPhoto.jpg” alt=”me!” />
In HTML5, because many people learned to close empty tags when they wrote
XHTML1, it is permitted but not required to close empty tags. In XHTML5 (and
XHTML1) closing empty tags is required. The same is true in polyglot
HTML5/XHTML5. Accordingly I recommend closing all empty tags.
3. HTML is casual about not requiring that some tags be closed – e.g <p>.
XHTML requires that all tags be closed. If you have an empty tag which may, in
other pages, have content, you are advised (by w3c) not to use the minimized
format. That is, use <p></p>, rather than <p /> because some old browsers may
handle the minimized form incorrectly.
5. You must use a <!DOCTYPE…..> before your <html> tag. There are basically five
good and legal choices: See the guidelines below for more information.
For HTML5 --- and the <meta ….> line is optional but recommended
and goes after the <head> tag.
<!DOCTYPE html>
<html lang=’en’>
<meta charset="UTF-8">
XHTML1.1 is (very) strict and less popular than XHTML1.0. There are
doctypes for HTML4.01, but not always used and will be inferred if
omitted. . Note that XML 2.0 was published in January 2006 and put on
hold in 2009 so that resources could be devoted to HTML5. More
importantly, HTML5 is in the works, so please read Coming
Attractions:HTML5 and XHTML5 in these notes.
6.If you are using the strict DTD (as opposed to the transitional) then you must include
an XML Namespace. Writing in English you might put
More complete information about compatibility with XML agents can be found at
http://www.w3.org/TR/xhtml1/#guidelines
7. HTML5 and XHTML5 are coming. Briefly, HTML5 is expected to be completely supported
by 2012, but is supported by all browsers except IE (and IE9 will support it.). HTML5 may
be written as either HTML or XHTML, and the w3c recommends that most authors use
HTML.
a. If you wish to write HTML5 as HTML you will begin your pages
<!doctype html> or <!DOCTYPE html> followed by :
<html lang=’en’>
<head>
<meta charset = ‘UTF-8’>
The last line is optional and will be inferred if missing; it is recommended that
you include it.
Pages that begin this way will always render with the most current standards.
b. If you wish to write HTML5 as XHTML you may begin your pages
Some features of HTML5 are already supported in popular browsers – e.g. the
canvas tag for bitmaps. IE8 (and presumably other browsers) will support many
other features.
Reading:
1. By the time you finish the HTML coding you should have read all of Robin Williams’
The Non-Designers Design Book. It’s a fabulous little book, on reserve in the library.
You will want to read parts of it more than once. Many of the ideas are also found at
www.peachpitpress.com
2. There is also assigned reading from two other books (on reserve):
Olin Lathrop’s The Way Computer Graphics Works and Lynda Wyman’s Designing
Web Graphics (See also www.lynda.com). I suggest you browse in these books
beyond what is assigned.
1. Absolutely Essential
<!DOCTYPE html>
<html lang=’en’>
<meta charset="UTF-8"> AFTER the head tag
Copy one of the two above into the start of your page.
Either way your document must end with </html>
2. Lining Up Text
<p> </p> ……. Paragraph tags
These mark the beginning and end of a paragraph.
Each paragraph will automatically start on a new line, with one blank line inserted
after the last paragraph.
Of course, these tags come as an opening and closing pair.
But why use something which is not available in HTML5 when there is a perfectly good
way to align items which works in all the versions of HTML and XHTML…
<p style=”text-align:right”>
Now comes a long and boring paragraph, right aligned.
</p >
<div style=”text-align: center”> Everything in here is centered until you come to…</div>
This is useful to center several paragraphs, heading, etc. at once.
Note: The default is left aligned for everything except headings, where the default
is center.
text- align: may be followed by left, right or center.
In addition to controlling layout, a common use of text-align is to right-align a
column of numbers.
In general, it is better to use <strong> … </strong> than <b> …</b>, and it is better to
use <em> …</em> than <i> … </i>. (‘em’ stands for emphasis.) This is because
readers for the visually impaired can render ‘strong’ and ‘em’ but not b(old) and
i(talics).
Font manipulation
Fonts have a font-face (e.g. Arial, Courier, etc.), a font-size, font-weight (e.g. bold),
a font-style (e.g. italic).
Text attributes are used to set alignment (text-align), color (text-color) and
decoration (text-decoration can have the values underline, overline, line-through
or blink).
To have a paragraph in bold red with the Arial font and in the font three times as
large as usual you would write:
<p style=”font-face:Arial; font-weight:bold; font-size:3em;text-color:red”> …</p>
The <font> tage of XHTML1 and HTML4 is no longer available in (X)HTML5.
Accordingly, you may no longer use code such as:
<font> </font> …….. Font tags
These tags are used to specify a particular font - size, face, color in the body.
Size, face and color are the attributes (properties) you are specifying in the font tag.
When the font tag closes, those attributes end.
You may also specify the typeface - but the face must be available on the user's
computer.
<font face="helvetica">This is in Helvetica.</font>
Note: Not all browsers support this, and different browsers/versions may have
different faces available, or different names for the same face (e.g. Times, Times
Roman, Times New Roman.)
face="Times, times, Times Roman, times roman, Times New Roman, times new roman"
will look for these 6 faces (in that order), and then go to the default face.
Colors
Finally, you may specify colors. You should always try to use browser-safe colors.
Colors are described by a set of three hexadecimal numbers. Each of the numbers is of
the form hh.
Since there are three such numbers, the whole thing looks like hhhhhh.
Each of the h's is 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E, or F.
The three numbers specify the level of the Red, Green and Blue lights which
make up the whole color.
Here are some common browser-safe colors:
Red #FF0000
Green #00FF00
Blue #0000FF
White #000000
Black #FFFFFF
The following list of colors is in the transitional but not the strict DTD of XHTML1
and is also available for styling with CSS (hence in HTML5).
There are also 16 widely known color names with their RGB
values:
If you wish the background of your page to be black (not recommended) and all
your text to be white, then set thebackground with the body selector and
use the background-color property and the text-color property in your style
sheet. (See CSS Notes.)
4. Lists
<ul> </ul>……. Unordered List tag (Unordered means not numbered).
The list is indented, and you may nest lists to get levels of indentation.
If the list is not bulleted then end each line with a <br />.
<ul>
My first item <br />
My second item< br />
My third item< br />
My last item
</ul>
<li> …… List Item tag
If you want your list to have bullets, put <li> in front of each item.
The line feed is inserted automatically before each <li>, so omit the <br />’s.
<ul>
<li>My first item </li>
<li>My second item</li>
<li>My third item</li>
<li>My last item</li>
</ul>
It is also possible to style the bullets in a list using
<ul style=”list-style-type:none”> and the <li>, </li>
The value of none in list-style-type will give no bullets. Other possible values are
disc, circle (the default) and square.
<ol>
<li>My first item</li>
<li>My second item</li>
<li>My third item</li>
<li>My last item</li>
</ol>
You may also specify how an ordered list is numbered/lettered using list-style-type.
For example,
<ol style=”list-style-type:upper-alpha”>
Will produce a list with items enumerated by A, B, C etc.
5. Links
Absolute Links or Links to Other Pages
<a href=”http://the_URL”>Words to Underline</a> The anchor tag - absolute
The text in between the two tags is underlined. When the user clicks on it the
browser transfers to the URL in the first tag.
NOTE: the quote marks are the usual ones --- not facing in any particular way.
There is a convention that when a path name is listed (as above) without a file
name at the end, then the browser will look for a file called index.htm or
index.html. So your opening page should be named index.
There is also a convention that user directories (those that start ~username) will
have all their public files in a directory called public_html.
In other words, when a viewer clicks on the text in the example, her browser will
actually get the file www.simmons.edu/~menzin/public_html/index.htm
In this case (the absolute URL) the URL completely defines where the browser is
to go.
Notice that both the a name= tag and the a href= tag have the address in quotation
marks.
In XHTML1 and in HTML4 you did not need the id= part, but beginning in HTML5
you need the id= and further if there is both a name (for legacy browsers) and an
Notice the use of # inside the anchor where the linking is done ---this alerts the
browser to look for a named place, not an absolute or (see below) relative reference.
Your link may go either up or down the page. See the links8a.html and links8b.html
examples.
You may also combine links to other pages and links to named spots on those other
pages. For example, let us suppose that you have built a page at with the URL
SomeComputer/MyBook/Intro.html
And that somewhere in that file you have a named anchor
Then, on some other page, if you wish to link to the Table of Contents you would code:
Notice that there is the usual anchor with an href (in quotes) but that the #namedSpot
comes at the end of the URL.
In this case you will link to a different file (one named OherFileInSameDirectory.htm).
Relative links allow you to keep all related files in the same directory or folder. If you decide
someday to move the whole folder to another computer or another spot on that computer,
then the relative hrefs will still work, but absolute ones will need to be re-typed.
As usual, there are no spaces in URL file names, and file names are case-sensitive.
menzin
cs101 html_programs
href=”../html_programs/fonts4.html”
The ../ gets us from the cs101 directory to the menzin directory.
6. Tables
In HTML tables are used for creating charts and tables, but are no longer recommended for
controlling page layout. Traditionally, a table with two columns (which need not have the same
width) is one way to create the familiar side-bar with links to other parts of a web site. Today,
using CSS is the preferred way to achieve this result.
Position on the page/page layout may be controlled with CSS. This is discussed in the
CSS notes. Controlling position with CSS works better for pages which may be ‘read’
in many formats (e.g. on hand-held devices), but has the disadvantage that an external
style-sheet is not always downloaded from a web page (i.e. the layout is not saved). It
is the preferred method for laying out pages.
A table has rows (which run left to right) and columns (which go up and down, just as on a
building).
A table is described by reading across the first row, then reading across the next row, etc.
<table>
<tr>
The description of the entries in the first row goes here
</tr>
<tr>
The description of the entries in the second row goes here
</tr>
<tr>
The description of the entries in the third row goes here
</tr>
</table>
Notice that I have indented the table rows. Table descriptions can get complex (you can even
put a table inside another table!) and it is a good idea to do this!
Beginning with HTML5, all attributes of tables (border, cellspacing, cellpadding, and
width. etc.), table rows and table cells must be set through CSS.
See the listing for tables10b.html (Remember that file names are case-sensitive!)
<div style=”text-align:center”>
<table>
:
:
</table>
</div>
<table style=”text-align:left”>…</table> Puts the table on the left side of the page, and
the text to the right.
The only choices are left and right.
See the various tables pages for examples, and examples of coloring both all the background and
individual cells.
<table style=”background-color=”red”>……..</table>
An entire table with a red background
<td style=”background-color:blue”> </td> A blue cell
Sometimes you want a cell to stretch across several columns (e.g. for a heading) or down
several rows.
<tr style=”text-align:center”>
</tr>
If you are doing something complex, it is a good idea to make a simple sketch of it before you
start coding. That way when you have a column or row span you will remember which cells
have already been taken described. See tables11c.html
Remember: If you have an empty cell and you want it to be colored, put a <br /> in it.
7. Inserting Graphics:
Please read the pages I e-mailed you about gif’s and jpeg’s and about large files.
Obviously, if you change the height and width to a different ratio than your original gif or jpeg
you will distort the image (which you may choose to do.)
Inside the img tag you may align the image to go on the left (or right) of the accompanying
text.
NOTE: As of HTML5 you are supposed to always set the border. While the border attribute
may still be used inside the <img> tag, it is preferred to set the border with CSS, as above.
I have a long explanation that I want near the icon, which is to the left of the icon.
For simple images, I may align it top, middle or bottom with my line of text, by styling
the vertical-align property.
The hspace attribute will place space between your text and your graphic.
The <br style=”clear:both” /> will clear all alignments. You should be warned that the align tag does
not always work the way you wish it to (especially when you have a lot of text to go
next to your image.) Using a table for layout is a more reliable way to control the
appearance of your page. See the CSS Notes for more information.
Finally
<body style=”background-image:url(“awfulStuff.gif”)>
will cause the entire background of your page to be tiled with the gif you specified.
NOTE: You should always include the alt attribute <img src=”stopSign.gif” alt=”stop sign” />
to get a written description for visually impaired users (and those too impatient to wait for the
image to load) and for search engines.