HTML Tutorial
In this HTML tutorial you will learn how to use HTML to create your own Web site. HTML is very easy to learn! You will enjoy it!
What is an HTML File?
Do You Want to Try It?If you are running Windows, start Notepad. If you are on a Mac, start SimpleText. In OSX start TextEdit and change the following preferences: Open the the "Format" menu and select "Plain text" instead of "Rich text". Then open the "Preferences" window under the "Text Edit" menu and select "Ignore rich text commands in HTML files". Your HTML code will probably not work if you do not change the preferences above! Type in the following text:
Save the file as "mypage.htm". 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.htm" - select it and click "Open". Now you should see an address in the dialog box, for example "C:\MyDocuments\mypage.htm". Click OK, and the browser will display the page. Example ExplainedThe first tag in your HTML document is . This tag tells your browser that this is the start of an HTML document. The last tag in your document is . This tag tells your browser that this is the end of the HTML document. The text between the tag and the tag is header information. Header information is not displayed in the browser window. The text between the The text between the The text between the and tags will be displayed in a bold font. HTM or HTML Extension?When you save an HTML file, you can use either the .htm or the .html extension. We have used .htm in our examples. It might be a bad habit inherited from the past when some of the commonly used software only allowed three letter extensions. With newer software we think it will be perfectly safe to use .html. Note on HTML Editors:You can easily edit HTML files using a WYSIWYG (what you see is what you get) editor like FrontPage or Dreamweaver, instead of writing your markup tags in a plain text file. However, if you want to be a skillful Web developer, we strongly recommend that you use a plain text editor to learn your primer HTML. Frequently Asked QuestionsQ: After I have edited an HTML file, I cannot view the result in my browser. Why? Q: I have edited an HTML file, but the changes don't show in the browser. Why? Q: What browser should I use? Q: Does my computer have to run Windows? What about a Mac? HTML documents are text files made up of HTML elements. HTML elements are defined using HTML tags. HTML Tags
HTML ElementsRemember the HTML example from the previous page:
This is an HTML element:
The HTML element starts with a start tag:
The purpose of the tag is to define an HTML element that should be displayed as bold. This is also an HTML element:
This HTML element starts with the start tag , and ends with the end tag . The purpose of the tag is to define the HTML element that contains the body of the HTML document. Why do We Use Lowercase Tags?We have just said that HTML tags are not case sensitive: means the same as . If you surf the Web, you will notice that plenty of web sites use uppercase HTML tags in their source code. We always use lowercase tags. Why? If you want to follow the latest web standards, you should always use lowercase tags. The World Wide Web Consortium (W3C) recommends lowercase tags in their HTML 4 recommendation, and XHTML (the next generation HTML) demands lowercase tags. HeadingsHeadings are defined with the totags.defines the largest heading.defines the smallest heading.
HTML automatically adds an extra blank line before and after a heading. ParagraphsParagraphs are defined with the tag.
HTML automatically adds an extra blank line before and after a paragraph. Don't Forget the Closing TagYou might have noticed that paragraphs can be written without end tags :
The example above will work in most browsers, but don't rely on it. Future version of HTML will not allow you to skip ANY end tags. Closing all HTML elements with an end tag is a future proof way of writing HTML. It also makes the code easier to understand (read and browse) when you to mark both where an element starts and where it ends. Line BreaksThe
Try it yourself The
|
|
Note that you need an exclamation point after the opening bracket, but not before the closing bracket.
Recap on HTML Elements
- Each HTML element has an element name (body, h1, p, br)
- The start tag is the name surrounded by angle brackets:
- The end tag is a slash and the name surrounded by angle brackets
- The element content occurs between the start tag and the end tag
- Some HTML elements have no content
- Some HTML elements have no end tag
Basic Notes - Useful Tips
When you write HTML text, you can never be sure how the text is displayed in another browser. Some people have large computer displays, some have small. The text will be reformatted every time the user resizes his window. Never try to format the text in your editor by adding empty lines and spaces to the text.
HTML will truncate the spaces in your text. Any number of spaces count as one. Some extra information: In HTML a new line counts as one space.
Using empty paragraphs
to insert blank lines is a bad habit. Use the
tag instead. (But don't use the
tag to create lists. Wait until you have learned about HTML lists.)
HTML automatically adds an extra blank line before and after some elements, like before and after a paragraph, and before and after a heading.
We use a horizontal rule (the
tag), to separate the sections in our tutorials.
Basic HTML Tags
If you lookup the basic HTML tags in the reference below, you will see that the reference contains additional information about tag attributes.
You will learn more about HTML tag attributes in the next chapter of this tutorial.
Tag | Description |
---|---|
| Defines an HTML document |
| Defines the document's body |
to | Defines header 1 to header 6 |
| Defines a paragraph |
| Inserts a single line break |
Defines a horizontal rule | |
| Defines a comment |
Attributes provide additional information to an HTML element.
HTML Tag Attributes
HTML tags can have attributes. Attributes provide additional information to an HTML element.Attributes always come in name/value pairs like this: name="value".
Attributes are always specified in the start tag of an HTML element.
Attributes Example 1:
defines the start of a heading.
has additional information about the alignment.
Attributes Example 2:
defines the body of an HTML document.
has additional information about the background color.
Attributes Example 3:
"Computer Output" Tags
Tag | Description |
---|---|
| Defines computer code text |
| Defines keyboard text |
| Defines sample computer code |
| Defines teletype text |
| Defines a variable |
| Defines preformatted text |
|
|
|