Learning HTML by yourself


2 - Basic HTML

30/10/2011 13:14

 

Introduction

HTML (HyperText Markup Language was designed as a simple markup language which could be used to produce documents on the internet.  Because of the language's platform-independence, it can be created on wordpad or notepad, but it must be saved in html format.

Let me explain what this means. 

You can type up your html in notepad.  When you type up the tags (the things that tell the computer what to put into your web page)  you will not be able to see what it makes until you can look at it in your browser.  Your browser is what internet program you are using to see the web sites.  When you save what you have created in notepad you have to type the name of what the file will be called but you also have to add the following:

save as:    myfirstpage.html

When naming files they must be together, any words you want, but no spaces and avoid any symbols in the name.  Notice also that there is a period and the html after it.  This makes sure that the browser will read the file.  It makes it html readable. 

Sounds silly but true.  If you still have problems check that you are saving this file as a text file.  Ask you teacher if you are still having problems.

There are four important rules for coding with HTML tags.

 

  1. Tags are always surrounded by angle brackets (less-than/greater-than characters), as in <HEAD>.
  2. Most tags come in pairs and surround the material they affect. They work like a light switch: the first tag turns the action on, and the second turns it off. (There are some exceptions. For instance, the <BR> tag creates a blank line and doesn't have an "off switch." Once you've made a line break, you can't unmake it.)
  3. The second tag--the "off switch"--always starts with a forward slash. For example, you turn on bold with <B>, shout your piece, and then go back to regular text with </B>.
  4. First tag on, last tag off. Tags are embedded (put in), so when you start a tag within another tag, you have to close that inner tag before closing the outer tag. For instance, the page will not display properly with the tags in this order:

    <HEAD><TITLE>Your text</HEAD></TITLE>.

    The correct order is:

    <HEAD><TITLE>Your text</TITLE></HEAD>.

 HTML is always evolving, and older browsers often don't support the newest tags. Plus you will find that some things can be done in Internet Explorer and not in Netscape, and vise versa.  This course tells you when that happens.  When a browser encounters an HTML tag it doesn't understand, it will usually ignore both the tag and the material the tag affects. This way, the newest elements will appear to viewers with newer browsers without causing problems for viewers using older browsers, who will only see material their browsers recognize. On the downside, browsers treat coding errors like unfamiliar code. If you've made a mistake while building your page, you won't necessarily see an error message; you might just see nothing at all. You should always closely check all of your pages in a browser to make sure that everything that's supposed to be there appears properly. You do this by going into FILE, then OPEN, and go BROWSE for your file to   open.  This lets you see what it would look like on the browser you have.

If it's all starting to sound complicated, relax, it's simple once you get started.  A great way to learn about more complicated HTML is to look over the shoulders of other Web page creators. If you see a Web site you like, just view the page's source to see how it was done. You should never just copy another builder's design, but most developers do borrow inspiration from other sites. Methods for viewing source vary by browser, but it's usually as simple as selecting Page Source or Source from the View menu.  When viewing source code, you'll sometimes see organizational comments from the page's author near the top of (or scattered throughout) the file. These comments are inserted with the <COMMENT> or <!--> tag and often contain useful information for those who view them. For a simple exercise in reading source code, try printing a well-commented Web page from your browser and then printing the source code of that page. Compare the two documents side by side, using the author's comments to match sections of code with the visual elements they represent. You'll soon be able to zero in on specific lines of code to understand how to achieve individual effects.  But we're getting ahead of our self.  Lets get back to the basics.

START

There are certain tags you need to put in every HTML document to set it up as a Web page. Begin by opening a new document in your text editor.  In our case Notepad.

<HTML> is the first tag to appear on every Web page. Add the opening and closing tags to your page like this:

<HTML>
</HTML>

All of the page's code will be placed between these two tags, which tell a Web browser it's reading an HTML document.

Below the opening <HTML> tag, enter the <HEAD> tag, which contains information about the document but doesn't appear on the Web page. Your document should now look like this:

<HTML>
<HEAD>
</HEAD>
</HTML>

This puts text in the browser's title bar. Your document should now resemble the example below (remember: First on, last off):

<HTML>
<HEAD>
<TITLE>E-Z Accounting
</TITLE>
</HEAD>
</HTML>

Now you're ready to add opening and closing <BODY> tags. Your document should now look like this:

<HTML>
<HEAD>
<TITLE>My First One
</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>

Everything that appears inside the Web page will go between the <BODY> tags.

Add headings and paragraphs

In HTML there are six levels of headings. H1 is the most important, H2 is slightly less important, and so on down to H6, the least important.

Here is how to add an important heading:

<h1>An important heading</h1>

and here is a slightly less important heading:

<h2>A slightly less important heading</h2>

check out the different sizes.

Each paragraph you write should start with a <p> tag. The </p> is optional, unlike the end tags for elements like headings. For example:

<p>This is the first paragraph.</p>

<p>This is the second paragraph.</p>

Adding a bit of emphasis

You can emphasize one or more words with the <em> tag, for instance:

This is a really <em>interesting</em> topic!
Try these ones out to see what they do:
<strong></strong>
<big></big>

ATTRIBUTES

Start tags may have attributes, which define some characteristics of that tag.  What I  mean is the following:

<P Align="center">, will make all that paragraph center in the page.  You can have "left", "right", "center", or "justify".  Don't forget that if you set your paragraph like this that you have to change it back in the next paragraph.

Pictures have this characteristic also.

SCR="image/firetrck.gif" ALT="A fire engine races to the scene of an accident" ALIGH="center">

What this will do is have a picture of a fire truck.  When you put the mouse over it the words will come up and the picture will be centered on the page.  This is a lot, I know, but once you get the easy part done, all is well.  Try this.  Copy the section below, and past it in a notepad document.  Save it by calling it firetruck.html   and then open the browser and call it up to see it.  Play with what I have put here.

<HTML>
<HEAD>
<TITLE>My First One
</TITLE>
</HEAD>
<BODY>

<b>I can't believe that I can do this!!</b>

<h2>this is a header.  Try others</h2>

write something here.
</BODY>
</HTML>

 

Assignment time.

 

—————

Back