Wednesday, June 29, 2011

Lesson 5: What have you learned so far?

Always start with the basic template we made in the previous lesson:

        
        <html>
          <head>
          <title></title>
          </head>
 
          <body>
          </body>
 
        </html>
        
        
In the head section, always write a title: <title>The title of your page</title>. Notice how the title will be shown in the upper left corner of your browser:

The title is especially important because it is used by search engines (such as Google) to index your website and is shown in the search results.

In the body section, you write the actual content of the page. You already know some of the most important elements:
        
        <p>Is used for paragraphs.</p>
        <em>Emphasis text.</em>
        <h1>Heading</h1>
        <h2>Subhead</h2>
        <h3>Sub-subhead</h3> 
        
        
Remember, the only way to learn HTML is by trial and error. But don't worry, there is no way you can destroy your computer or the Internet. So keep experimenting - that is the best way to gain experience.

What is that supposed to mean?

Nobody becomes a good website creator by learning the examples in this tutorial. What you get in this tutorial is simply a basic understanding of the building blocks - to become good you must use the building blocks in new and creative ways.
So, get out in the deep water and stand on your own two feet... Okay, maybe not. But give it a go and experiment with what you have learned.

So what's next?

Try to create a few pages yourself. For instance, make a page with a title, a heading, some text, a subhead and some more text. It is perfectly okay to look in the tutorial while you make your first pages. But later, see if you can do it on your own - without looking.

Saturday, June 25, 2011

Lesson 4: Create your first website

With what you learned in the previous lessons, you are now only minutes away from making your first website.

How?

In Lesson 1 we looked at what is needed to make a website: a browser and Notepad (or similar text editor). Since you are reading this, you most likely already have your browser open. The only thing you need to do is to open an extra browser window (open the browser one more time) so you can read this tutorial and see your new website at the same time.
Also, open Notepad (in Accessories under Programs in the Start menu):

Now we are ready!

What can I do?

Let us start with something simple. How about a page that says: "Hurrah! This is my first website." Read on and you'll find out how simple it is.
HTML is simple and logical. The browser reads HTML like you read English: from the top down and from left to right. Thus, an simple HTML document begins with what should come first and ends with what should come last.
The first thing you need to do is to tell the browser that you will "talk" to it in the language HTML. This is done with the tag <html> (no surprises there). So before you do anything else type "<html>" in the first line of your document in Notepad.
As you may recall from the previous lessons, <html> is an opening tag and must be closed with a closing tag when you are finished typing HTML. So to make sure you don't forget the HTML close tag now type "</html>" a couple of lines down and write the rest of the document between <html>and </html>.
The next thing your document needs is a "head", which provides information about your document, and a "body", which is the content of the document. Since HTML is nothing if not logical, the head (<head> and </head>) is on top of the body (<body> and </body>).
Your document should now look like this:
        
        <html>
 
          <head>
          </head>
 
          <body>
          </body>
 
        </html>
        
        
Note how we structured the tags with new lines (using the Enter key) as well as indents (using the Tab key). In principle, it does not matter how you structure your HTML document. But to help you, and others reading your coding, to keep an overview, it is strongly recommended that you structure your HTML in a neat way with line breaks and indents, like the above example.
If your document looks like the above example, you have made your first website - a particularly boring website and probably not what you dreamt of when you started this tutorial but still some sort of a website. What you have made will be the basic template for all your future HTML documents.

So far so good, but how do I add content to my website?

As you learnt earlier, your HTML document has two parts: a head and a body. In the head section you write information about the page, while the body contains the information that constitutes the page.
For example, if you want to give the page a title which will appear in the top bar of the browser, it should be done in the "head" section. The element used for a title is title. I.e. write the title of the page between the opening tag <title> and the closing tag </title>:
        
        <title>My first website</title>
        
        
Note that this title will not appear on the page itself. Anything you want to appear on the page is content and must therefore be added between the "body" tags.
As promised, we want the page to say "Hurrah! This is my first website." This is the text that we want to communicate and it therefore belongs in the body section. So in the body section, type the following:
        
        <p>Hurrah! This is my first website.</p>
        
        
The p in <p> is short for "paragraph" which is exactly what it is - a text paragraph.
Your HTML document should now look like this:
        
        <html>
 
          <head>
          <title>My first website </title>
          </head>
 
          <body>
          <p>Hurrah! This is my website.</p>
          </body>
 
        </html>
        
        
Done! You have now made your first real website!
Next all you have to do is to save it to your hard drive and then open it in your browser:
  • In Notepad choose "Save as..." under "File" in the top menu.
  • Choose "All Files" in the "Save as type" box. This is very important - otherwise, you save it as a text document and not as an HTML document.
  • Now save your document as "page1.htm" (the ending ".htm" indicates that it is an HTML document. ".html" gives the same result. I always use ".htm", but you can choose whichever of the two extensions you prefer). It doesn't matter where you save the document on your hard drive - as long as you remember where you saved it so you can find it again.

Now go to the browser:
  • In the top menu choose "Open" under "File".
  • Click "Browse" in the box that appears.
  • Now find your HTML document and click "Open".

It now should say "Hurrah! This is my first website." in your browser. Congratulations!
If you absolutely want the whole world to see your masterpiece right away, you can jump to Lesson 13 and learn how to upload your page to the Internet. Otherwise, be patient and read on. The fun has just begun.

Saturday, March 26, 2011

Lesson 3: Elements and tags

You are now ready to learn the essence of HTML: elements.
Elements give structure to a HTML document and tells the browser how you want your website to be presented. Generally elements consists of a start tag, some content, and an end tag.

"Tags"?

Tags are labels you use to mark up the begining and end of an element.
All tags have the same format: they begin with a less-than sign "<" and end with a greater-than sign ">".
Generally speaking, there are two kinds of tags - opening tags: <html> and closing tags: </html>. The only difference between an opening tag and a closing tag is the forward slash "/". You label content by putting it between an opening tag and a closing tag.
HTML is all about elements. To learn HTML is to learn and use different tags.

Can you show me some examples?

Okay, the element em emphasis text. All text between the opening tag <em> and the closing tag</em> is emphasised in the browser. ("em" is short for "emphasis".)
Example 1:
        
        <em>Emphasised text.</em>
        
        
Will look like this in the browser:
Emphasised text.
The elements h1, h2, h3, h4, h5 and h6 is used to make headings (h stands for "heading"), whereh1 is the first level and normally the largest text, h2 is the second level and normally slightly smaller text, and h6 is the sixth and last in the hierarchy of headings and normally the smallest text.
Example 2:
        
        <h1>This is a heading</h1>
        <h2>This is a subheading</h2>
        
        
Will look like this in the browser:

This is a heading

This is a subheading

So, I always need an opening tag and a closing tag?

As they say, there's an exception to every rule and in HTML the exception is that there are a few elements which both open and close in the same tag. These so-called empty elements are not connected to a specific passage in the text but rather are isolated labels, for example, a line break which looks like this: <br/>.

Should tags be typed in uppercase or lowercase?

Most browsers might not care if you type your tags in upper, lower or mixed cases. <HTML>, <html> or <HtMl> will normally give the same result. However, the correct way is to type tags in lowercase. So get into the habit of writing your tags in lowercase.

Where do I put all these tags?

You type your tags in an HTML document. A website contains one or more HTML documents. When you surf the Web, you merely open different HTML documents.
If you continue to the next lesson in 10 minutes you will have made your first website.

Friday, March 18, 2011

Lesson 2: How does CSS work?

In this lesson you will learn how to make your first style sheet. You will get to know about the basic CSS model and which codes are necessary to use CSS in an HTML document.
Many of the properties used in Cascading Style Sheets (CSS) are similar to those of HTML. Thus, if you are used to use HTML for layout, you will most likely recognize many of the codes. Let us look at a concrete example.

The basic CSS syntax

Let's say we want a nice red color as the background of a webpage:
Using HTML we could have done it like this:
        
        <body bgcolor="#FF0000">
        
        
With CSS the same result can be achieved like this:
        
        body {background-color: #FF0000;}
        
        
As you will note, the codes are more or less identical for HTML and CSS. The above example also shows you the fundamental CSS model:

But where do you put the CSS code? This is exactly what we will go over now.

Applying CSS to an HTML document

There are three ways you can apply CSS to an HTML document. These methods are all outlined below. We recommend that you focus on the third method i.e. external.

Method 1: In-line (the attribute style)

One way to apply CSS to HTML is by using the HTML attribute style. Building on the above example with the red background color, it can be applied like this:
        <html>
          <head>
               <title>Example</title>
          </head>
          <body style="background-color: #FF0000;">
               <p>This is a red page</p>
          </body>
        </html>
        

Method 2: Internal (the tag style)

Another way is to include the CSS codes using the HTML tag <style>. For example like this:
        <html>
          <head>
               <title>Example</title>
               <style type="text/css">
                 body {background-color: #FF0000;}
               </style>
          </head>
          <body>
               <p>This is a red page</p>
          </body>
        </html>
        

Method 3: External (link to a style sheet)

The recommended method is to link to a so-called external style sheet. Throughout this tutorial we will use this method in all our examples.
An external style sheet is simply a text file with the extension .css. Like any other file, you can place the style sheet on your web server or hard disk.
For example, let's say that your style sheet is named style.css and is located in a folder namedstyle. The situation can be illustrated like this:








The trick is to create a link from the HTML document (default.htm) to the style sheet (style.css). Such link can be created with one line of HTML code:
        <link rel="stylesheet" type="text/css" href="style/style.css" />
        
Notice how the path to our style sheet is indicated using the attribute href.
The line of code must be inserted in the header section of the HTML code i.e. between the <head>and </head> tags. Like this:
        <html>
          <head>
               <title>My document</title>
               <link rel="stylesheet" type="text/css" href="style/style.css" />
          </head>
          <body>
          ...
        
This link tells the browser that it should use the layout from the CSS file when displaying the HTML file. 
The really smart thing is that several HTML documents can be linked to the same style sheet. In other words, one CSS file can be used to control the layout of many HTML documents.



















This technique can save you a lot of work. If you, for example, would like to change the background color of a website with 100 pages, a style sheet can save you from having to manually change all 100 HTML documents. Using CSS, the change can be made in a few seconds just by changing one code in the central style sheet.
Let's put what we just learned into practice.

Try it yourself

Open Notepad (or whatever text editor you use) and create two files - an HTML file and a CSS file - with the following contents:

default.htm

        <html>
          <head>
               <title>My document</title>
               <link rel="stylesheet" type="text/css" href="style.css" />
          </head>
          <body>
               <h1>My first stylesheet</h1>
          </body>
        </html>
        

style.css

        body {
          background-color: #FF0000;
        }
        
Now place the two files in the same folder. Remember to save the files with the right extensions (respectively ".htm" and ".css")
Open default.htm with your browser and see how the page has a red background. Congratulations! You have made your first style sheet!
Hurry on to the next lesson where we will take a look at some of the properties in CSS.
Related Posts Plugin for WordPress, Blogger...