HTML Basics Day1
HTML Basics Day1
HTML Basics Day1
Welcome to HTML Basics. This workshop leads you through the basics of Hyper Text Markup Language
(HTML). HTML is the building block for web pages. You will learn to use HTML to author an HTML page
to display in a web browser.
Objectives:
By the end of this workshop, you will be able to:
Prerequisites:
You will need a text editor, such as Notepad and an Internet browser, such as Internet Explorer or
Netscape.
Mac Users: SimpleText is the default text editor on the Mac. In OSX use TextEdit and change
the following preferences: Select (in the preferences window) Plain text instead of Rich text and
then select Ignore rich text commands in HTML files. This is very important because if you don't
do this HTML codes probably won't work.
One thing you should avoid using is a word processor (like Microsoft Word) for authoring your HTML
documents.
Try It?
Open your text editor and type the following text:
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b>
</body>
</html>
Save the file as mypage.html. Start your Internet browser. Select Open (or Open Page) in the File
menu of your browser. A dialog box will appear. Select Browse (or Choose File) and locate the html
file you just created - mypage.html - select it and click Open. Now you should see an address in the
dialog box, for example C:\MyDocuments\mypage.html. Click OK, and the browser will display the
page. To view how the page should look, visit this web page:
http://profdevtrain.austincc.edu/html/mypage.html
Example Explained
What you just made is a skeleton html document. This is the minimum required information for a web
document and all web documents should contain these basic components. The first tag in your html
document is <html>. This tag tells your browser that this is the start of an html document. The last
tag in your document is </html>. This tag tells your browser that this is the end of the html
document.
The text between the <head> tag and the </head> tag is header information. Header information is not
displayed in the browser window.
The text between the <title> tags is the title of your document. The <title> tag is used to uniquely
identify each document and is also displayed in the title bar of the browser window.
The text between the <body> tags is the text that will be displayed in your browser.
The text between the <b> and </b> tags will be displayed in a bold font.
HTML Tags
Physical tags on the other hand provide specific instructions on how to display the text they enclose.
Examples of physical tags include:
HTML Elements
Remember the HTML example from the previous page:
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
This is my first homepage. <b>This text is bold</b>
</body>
</html>
The purpose of the <b> tag is to define an HTML element that should be displayed as bold.
<body>
This is my first homepage. <b>This text is bold</b>
</body>
This HTML element starts with the start tag <body>, and ends with the end tag </body>. The purpose
of the <body> tag is to define the HTML element that contains the body of the HTML document.
Nested Tags
You may have noticed in the example above, the <body> tag also contains other tags, like the <b> tab.
When you enclose an element in with multiple tags, the last tag opened should be the first tag closed.
For example:
Note: It doesn't matter which tag is first, but they must be closed in the proper order.
Tag Attributes
Tags can have attributes. Attributes can provide additional information about the HTML elements on
your page. The <tag> tells the browser to do something, while the attribute tells the browser how to
do it. For instance, if we add the bgcolor attribute, we can tell the browser that the background color
of your page should be blue, like this: <body bgcolor="blue">.
This tag defines an HTML table: <table>. With an added border attribute, you can tell the browser that
the table should have no borders: <table border="0">. Attributes always come in name/value pairs
like this: name="value". Attributes are always added to the start tag of an HTML element and the
value is surrounded by quotes.
Note: Some tags we will discuss are deprecated, meaning the World Wide Web Consortium
(W3C) the governing body that sets HTML, XML, CSS, and other technical standards decided
those tags and attributes are marked for deletion in future versions of HTML and XHTML.
Browsers should continue to support deprecated tags and attributes, but eventually these tags
are likely to become obsolete and so future support cannot be guaranteed.
The most important tags in HTML are tags that define headings, paragraphs and line breaks.
Headings
Headings are defined with the <h1> to <h6> tags. <h1> defines the largest heading while <h6> defines
the smallest.
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>
<h4>This is a heading</h4>
<h5>This is a heading</h5>
HTML automatically adds an extra blank line before and after a heading. A useful heading attribute is
align.
<h5 align="left">I can align headings </h5>
Paragraphs
Paragraphs are defined with the <p> tag. Think of a paragraph as a block of text. You can use the align
attribute with a paragraph tag as well.
Important: You must indicate paragraphs with <p> elements. A browser ignores any
indentations or blank lines in the source text. Without <p> elements, the document becomes
one large paragraph. HTML automatically adds an extra blank line before and after a paragraph.
Line Breaks
The <br> tag is used when you want to start a new line, but don't want to start a new paragraph. The
<br> tag forces a line break wherever you place it. It is similar to single spacing in a document.
Horizontal Rule
The <hr> element is used for horizontal rules that act as dividers between sections, like this:
The horizontal rule does not have a closing tag. It takes attributes such as align and width. For
instance:
Comments in HTML
The comment tag is used to insert a comment in the HTML source code. A comment can be placed
anywhere in the document and the browser will ignore everything inside the brackets. You can use
comments to write notes to yourself, or write a helpful message to someone looking at your source
code.
Notice you don't see the text between the tags <!-- and -->. If you look at the source code, you
would see the comment. To view the source code for this page, in your browser window, select View
and then select Source.
Note: You need an exclamation point after the opening bracket <!-- but not before the closing
bracket -->.
HTML automatically adds an extra blank line before and after some elements, like before and after a
paragraph, and before and after a heading. If you want to insert blank lines into your document, use
the <br> tag.
Try It Out!
Open your text editor and type the following text:
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1 align="center">My First Webpage</h1>
<p>Welcome to my first web page. I am writing this page using a text editor and plain
old html.</p>
<p>By learning html, I'll be able to create web pages like a pro....<br>
which I am of course.</p>
</body>
</html>
Save the page as mypage2.html. Open the file in your Internet browser. To view how the page
should look, visit this web page: http://profdevtrain.austincc.edu/html/mypage2.html
Character tags like <strong> and <em> produce the same physical display as <b> and <i> but are more
uniformly supported across different browsers.
Some Examples:
The following paragraph uses the <blockquote> tag. In the previous sentence, the blockquote tag is
enclosed in the <samp> Sample tag.
We the people of the United States, in order to form a more perfect Union, establish Justice,
insure domestic Tranquility, provide for the common defense, promote the general Welfare, and
secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this
Constitution for the United States of America.
Although most browsers render blockquoted text by indenting it, that's not specifically what it's
designed to do. It's conceivable that some future browser may render blockquoted text in some other
way. However, for the time being, it is perfectly safe to indent blocks of text with the <blockquote>.
When you hold your mouse pointer over the WWW, text in the title attribute will appear in.
Some characters have a special meaning in HTML, like the less than sign (<) that defines the start of
an HTML tag. If we want the browser to actually display these characters we must insert character
entities in place of the actual characters themselves.
A character entity has three parts: an ampersand (&), an entity name or an entity number, and finally
a semicolon (;). The & means we are beginning a special character, the ; means ending a special
character and the letters in between are sort of an abbreviation for what it's for. To display a less than
sign in an HTML document we must write: < or < The advantage of using a name instead of a
number is that a name is easier to remember. The disadvantage is that not all browsers support the
newest entity names, while the support for entity numbers is very good in almost all browsers.
Non-breaking Space
The most common character entity in HTML is the non-breaking space . Normally HTML will
truncate spaces in your text. If you add 10 spaces in your text, HTML will remove 9 of them. To add
spaces to your text, use the character entity.
HTML Fonts
The <font> tag in HTML is deprecated. The World Wide Web Consortium (W3C) has removed the
<font> tag from its recommendations. In future versions of HTML, style sheets (CSS) will be used to
define the layout and display properties of HTML elements.
HTML Backgrounds
Backgrounds
The <body> tag has two attributes where you can specify backgrounds. The background can be a color
or an image.
Bgcolor
The bgcolor attribute specifies a background-color for an HTML page. The value of this attribute can be
a hexadecimal number, an RGB value, or a color name:
<body bgcolor="#000000">
<body bgcolor="rgb(0,0,0)">
<body bgcolor="black">
Background
The background attribute can also specify a background-image for an HTML page. The value of this
attribute is the URL of the image you want to use. If the image is smaller than the browser window,
the image will repeat itself until it fills the entire browser window.
<body background="clouds.gif">
<body background="http://profdevtrain.austincc.edu/html/graphics/clouds.gif">
The URL can be relative (as in the first line above) or absolute (as in the second line above).
If you want to use a background image, you should keep in mind:
Will the background image increase the loading time too much?
Will the background image look good with other images on the page?
Will the background image look good with the text colors on the page?
Will the background image look good when it is repeated on the page?
Will the background image take away the focus from the text?
Note: The bgcolor, background, and the text attributes in the <body> tag are deprecated in
the latest versions of HTML (HTML 4 and XHTML). The World Wide Web Consortium (W3C) has
removed these attributes from its recommendations. Style sheets (CSS) should be used instead
(to define the layout and display properties of HTML elements).
Try It Out!
Open your text editor and type the following text:
<html>
<head>
<title>My First Webpage</title>
</head>
<body background="http://profdevtrain.austincc.edu/html/graphics/clouds.gif"
bgcolor="#EDDD9E">
<h1 align="center">My First Webpage</h1>
<p>Welcome to my <strong>first</strong> webpage. I am writing this page using a text
editor and plain old html.</p>
<p>By learning html, I'll be able to create webpages like a <del>beginner</del>
pro....<br>
which I am of course.</p>
</body>
</html>
Save your page as mypage3.html and view it in your browser. To view how the page should look,
visit this web page: http://profdevtrain.austincc.edu/html/mypage3.html
Notice we gave our page a background color as well as a background image. If for some reason the
web page is unable to find the picture, it will display our background color.
HTML Colors
Color Values
Colors are defined using a hexadecimal notation for the combination of red, green, and blue color
values (RGB). The lowest value that can be given to one light source is 0 (hex #00). The highest value
is 255 (hex #FF). This table shows the result of combining red, green, and blue:
Color Names
A collection of color names is supported by most browsers. To view a table of color names that are
supported by most browsers visit this web page:
http://profdevtrain.austincc.edu/html/color_names.htm
Note: Only 16 color names are supported by the W3C HTML 4.0 standard (aqua, black, blue,
fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow). For
all other colors you should use the Color HEX value.
HTML Lists
HTML provides a simple way to show unordered lists (bullet lists) or ordered lists (numbered lists).
Unordered Lists
An unordered list is a list of items marked with bullets (typically small black circles). An unordered list
starts with the <ul> tag. Each list item starts with the <li> tag.
Ordered Lists
An ordered list is also a list of items. The list items are marked with numbers. An ordered list starts
with the <ol> tag. Each list item starts with the <li> tag.
Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc.
Definition Lists
Definition lists consist of two parts: a term and a description. To mark up a definition list, you need
three HTML elements; a container <dl>, a definition term <dt>, and a definition description <dd>.
Inside a definition-list definition (the <dd> tag) you can put paragraphs, line breaks, images, links,
other lists, etc
Try It Out
Open your text editor and type the following:
<html>
<head>
<title>My First Webpage</title>
</head>
<body bgcolor="#EDDD9E">
<h1 align="center">My First Webpage</h1>
<p>Welcome to my <strong>first</strong> webpage. I am writing this page using a text
editor and plain old html.</p>
<p>By learning html, I'll be able to create web pages like a pro....<br>
which I am of course.</p>
Here's what I've learned:
<ul>
<li>How to use HTML tags</li>
<li>How to use HTML colors</li>
<li>How to create Lists</li>
</ul>
</body>
</html>
Save your page as mypage4.html and view it in your browser. To see how your page should look visit
this web page: http://profdevtrain.austincc.edu/html/mypage4.html
HTML Links
HTML uses the <a> anchor tag to create a link to another document or web page.
The <a> tag is used to create an anchor to link from, the href attribute is used to tell the address of
the document or page we are linking to, and the words between the open and close of the anchor tag
will be displayed as a hyperlink.
Email Links
To create an email link, you will use mailto: plus your email address. Here is a link to ACC's Help Desk:
To add a subject for the email message, you would add ?subject= after the email address. For
example:
To link directly to the top section, add a # sign and the name of the anchor to the end of a URL, like
this:
Note: Always add a trailing slash to subfolder references. If you link like this:
href="http://profdevtrain.austincc.edu/html", you will generate two HTTP requests to the
server, because the server will add a slash to the address and create a new request like this:
href="http://profdevtrain.austincc.edu/html/"
Named anchors are often used to create "table of contents" at the beginning of a large document. Each
chapter within the document is given a named anchor, and links to each of these anchors are put at
the top of the document. If a browser cannot find a named anchor that has been specified, it goes to
the top of the document. No error occurs.
HTML Images
<img src="graphics/chef.gif">
Not only does the source attribute specify what image to use, but where the image is located. The
above image, graphics/chef.gif, means that the browser will look for the image name chef.gif in a
graphics folder in the same folder as the html document itself.
src="chef.gif" means that the image is in the
same folder as the html document calling for it.
src="../../../other/images/chef.gif" means
this goes multiple layers up.
The browser puts the image where the image tag occurs in the document. If you put an image tag
between two paragraphs, the browser shows the first paragraph, then the image, and then the second
paragraph.
The alt attribute tells the reader what he or she is missing on a page if the browser can't load images.
The browser will then display the alternate text instead of the image. It is a good practice to include
the alt attribute for each image on a page, to improve the display and usefulness of your document for
people who have text-only browsers or use screen readers.
Image Dimensions
When you have an image, the browser usually figures out how big the image is all by itself. If you put
in the image dimensions in pixels however, the browser simply reserves a space for the image, then
loads the rest of the page. Once the entire page is loads it can go back and fill in the images. Without
dimensions, when it runs into an image, the browser has to pause loading the page, load the image,
then continue loading the page. The chef image would then be:
Open the file mypage2.html in your text editor and add code highlighted in bold:
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1 align="center">My First Web page</h1>
<p>Welcome to my first webpage. I am writing this page using a text editor and plain old html.</p>
<p>By learning html, I'll be able to create web pages like a pro....<br>
which I am of course.</p>
<!-- Who would have guessed how easy this would be :) -->
<p><img src="graphics/chef.gif" width="130" height="101" alt="Smiling Happy Chef"
align="center"></p>
<p align="center">This is my Chef</p>
</body>
</html>
Save your page as mypage5.html and view it in your browser. To see how your page should look visit
this web page: http://profdevtrain.austincc.edu/html/mypage5.html
Tables
Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag), and each row
is divided into data cells (with the <td> tag). The letters td stands for table data, which is the content
of a data cell. A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables,
etc.
Open up your text editor. Type in your <html>, <head> and <body> tags. From here on I will only be
writing what goes between the <body> tags. Type in the following:
<table border="1">
<tr>
<td>Tables can be used to layout information</td>
<td> <img src="http://profdevtrain.austincc.edu/html/graphics/chef.gif">
</td>
</tr>
</table>
Save your page as mytable1.html and view it in your browser. To see how your page should look
visit this web page: http://profdevtrain.austincc.edu/html/mytable1.html
Headings in a Table
Headings in a table are defined with the <th> tag.
Cellpadding is the pixel space between the cell contents and the cell border. The default for this
property is also zero. This feature is not used often, but sometimes comes in handy when you have
your borders turned on and you want the contents to be away from the border a bit for easy viewing.
Cellpadding is invisible, even with the border property turned on. Cellpadding can be handled in a style
sheet.
Table Tags
Tag Description
<table> Defines a table
<th> Defines a table header
<tr> Defines a table row
<td> Defines a table cell
<caption> Defines a table caption
<colgroup> Defines groups of table columns
<col> Defines the attribute values for one or more columns in a table
Table Size
Table Width
The width attribute can be used to define the width of your table. It can be defined as a fixed width or
a relative width. A fixed table width is one where the width of the table is specified in pixels. For
example, this code, <table width="550">, will produce a table that is 550 pixels wide. A relative table
width is specified as a percentage of the width of the visitor's viewing window. Hence this code, <table
width="80%">, will produce a table that occupies 80 percent of the screen.
One very common practice with HTML, is to An HTML <table> is used to divide a part of
use HTML tables to format the layout of an this Web page into two columns.
HTML page. The trick is to use a table without borders,
A part of this page is formatted with two and maybe a little extra cell-padding.
columns. As you can see on this page, there No matter how much text you add to this
is a left column and a right column. page, it will stay inside its column borders.
This text is displayed in the left column.
Try It Out!
Let's put everything you've learned together to create a simple page. Open your text editor and type
the following text:
<html>
<head>
<title>My First Web Page </title>
</head>
<body>
<table width="90%" cellpadding="5" cellspacing="0" >
<tr bgcolor="#EDDD9E">
<td width="200" valign="top"><img src="graphics/contact.gif" width="100"
height="100"></td>
<td valign="top"><h1 align="right">Janet Doeson</h1>
<h3 align="right">Technical Specialist</h3></td>
</tr>
<tr>
<td width="200">
<h3>Menu</h3>
<ul>
<li><a href="home.html">Home</a></li>
<li> <a href="faq.html">FAQ</a></li>
<li> <a href="contact.html">Contact</a></li>
<li> <a href="http://www.austincc.edu">Links</a> </li>
</ul></td>
<td valign="top"><h2 align="center">Welcome!</h2>
<p>Welcome to my first webpage. I created this webpage without the assistance of a
webpage editor. Just my little text editor and a keen understanding of html.</p>
<p>Look around. Notice I'm able to use paragraphs, lists and headings. You may not
be able to tell, but the layout is done with a table. I'm very clever. </p>
<blockquote>
<p>I always wanted to be somebody, but now I realize I should have been more
specific.</p>
<cite>Lily Tomlin </cite> </blockquote> </td>
</tr>
</table>
<hr width="90%" align="left">
<address>
Janet Doeson<br>
Technical Specialist<br>
512.555.5555
</address>
<p>Contact me at <a href="mailto:[email protected]">[email protected]</a> </p>
</body>
</html>
Save your page as mytable2.html and view it in your browser. To see how your page should look
visit this web page: http://profdevtrain.austincc.edu/html/mytable2.html
I have indented some of the HTML code in the above example. Indenting the code can make your
HTML document easier to read.
It’s time to create your own page. Use your text editor to create a page which contains the following:
Save the file as xyhtml_basics.html where xy is your initials. Email the file to [email protected].