It’s official: the beta version of my first tutorial is complete. Why is it a beta version? Because I’m not sure if it’s non-technical enough for a lot of people to understand what I’m saying. The test run will probably come tonight or tomorrow night when I show it to my wife and (hopefully) let her write her first web page.
In any case, it’s done, and at the moment, that’s relief enough. After completing the tutorial and fitting it to my own site’s design, the total size weighed in at 28 KB without loading the style sheet. I have to admit, that’s a bit lengthy even for me. Hopefully, though, it’s the kind of lengthy that’s good. I want to be sure that I’m thorough, and that what I’m saying can be understood by the average computer user.
That said, I’m going to try to post the tutorial here in its entirety. Seeing as it was originally written with my own site’s design in mind, it might look a bit odd here on WordPress. We’ll just see how that pans out. So, without further ado, here’s my tutorial in its current infantile state:
HTML – The Very Basics
So, you want to design your own website, or maybe all you want to do is modify the website you already have. Perhaps you’ve made a site using Microsoft Word, or a similar product that doesn’t require you to know any code at all but wanted to know what’s going on behind the scenes. Over the course of this tutorial, I plan to show you how to write and modify your own basic HTML code.
But what’s HTML code? HTML is the basic building block of almost every website in existence. HTML is involved in some way, shape, or form in any website you view online. It’s even the building block for the majority of the help files contained in most commercial programs. But what is it?
HTML is a coding language. In a sense, HTML truly is a language in the sense that it tells the computer what you want it to do. You want to make your text bold? HTML tells your web browser to make your text bold. Or purple, or big, or small, maybe you want it on the right side of your screen instead of the left… HTML tells your web browser how to do all of these things and a whole lot more.
HTML is an abbreviation that stands for “Hypertext Markup Language.” Right now, you do not need to know what all of this means. All you need to know at this point is that HTML is a language that you use to tell the web browser what you want it to do, much like any spoken language is used to convey information. Now you just need to know how to speak it, in a sense.
Ah, but where to begin? Start by opening up any basic text application. In Windows, your ideal application would be Notepad. For Macintosh users, I recommend TextEdit.
FOR WINDOWS USERS:
To open Notepad, simply click the Start menu and select Run. A dialog box should open telling you to type the name of the program you want to run. Type in “notepad” and click OK. Notepad should open for you.
FOR MACINTOSH USERS:
Find the icon on your dock for Finder and click on it. On the left side of the Finder window should be a list of places for you to go. Click on Applications and find the TextEdit application. Double-click on it to open TextEdit.
So you have your application open. Now what? Well, now it’s time to start with the fun stuff.
The first thing you have to know about HTML code is that everything on your page should be contained in a tag. Tags define starting points and ending points for anything and everything on your page. HTML on its own does not know when you’ve started one paragraph or ended another; you have to tell it that you have. Notice that earlier I said everything should be in a tag… but it doesn’t have to be. HTML is very forgiving of small mistakes, but it’s still a good idea to go ahead and start building good habits now before the bad ones have a chance to sink in.
The proper syntax for a tag is as follows: a starting tag starts with a less-than sign (<), the name of the tag (html, for instance), and ends with the greater-than sign (>). Ending tags add a slash before the name of the tag. Let’s see what these look like:
<html> – Starting tag for the “html” element.
</html> – Ending tag for the “html” element.
The very first tag in any basic HTML document is the HTML tag. This tells the browser that you are writing a page in HTML. This should almost always be the first line of any HTML document that you write, and the HTML end tag (</html>) should always be the last tag of your document. Type these into your blank file and then save the file as index.html (for Windows users, I recommend saving your file in My Documents or for Macintosh users, saving it in Documents for quick reference). The .html file extension lets your operating system (Windows or Macintosh) know that this file is a web page. What you should have in your document right now should be the following:
<html>
</html>
Now open your file with your web browser. The easiest way of doing this is to double-click on the file. Not much there, huh? Actually, the page should be completely white. HTML tags are not displayed in your web browser. All they do is tell the web browser what you want to do with the information contained inside of them, and seeing as you have nothing inside of your <html> tags, there’s nothing to do. So the page is white. Now let’s experiment a little with the paragraph tag.
The paragraph tag is represented thusly: the starting tag is <p>, and the ending tag is </p>. Anything within these two tags is considered a paragraph. So, let’s write our first paragraph. Remember that this is HTML information, so it has to go between your two HTML tags. Now your document’s code should look something like this:
<html>
<p>This is my first paragraph written in HTML!</p>
</html>
Let’s take a look at our page again. First save your index.html file, and if you still have the page open in your web browser you can simply click in your web browser’s window to activate it and hit the F5 key to refresh the page. If not, double click on the file once again to open it. Now you should have some fairly ugly text on the screen that says what you wrote in your paragraph. Try writing a few more paragraphs this way, save your index.html file and refresh the page by pressing F5.
If you entered your code correctly you should notice that each paragraph is separated from the previous one; there is a blank line between them. If your paragraphs do not do this, make sure that you have started each paragraph with the <p> tag and closed each paragraph with the </p> tag. After fixing your code, save your index.html file once again and refresh your browser. Make sure that you save your index.html file each time you make a change to it so that your web browser knows that it has been changed.
Now you know how to start an HTML document (with the <html> tags) and write a few basic paragraphs with the <p> tags. But what more can you do with HTML? A whole lot.
But before I start diving into some more HTML code, there are a few things that need to be said about the general practice of HTML coding. Firstly, you may have noticed that all of the HTML tags so far have the same name for both their start tags and end tags (<html> and </html>, for instance). The only difference between the two is that the end tag has a slash in it before the tag’s name. This is always the case! There are only a few HTML tags that don’t have an end tag, but all of the ones that do have an end tag that matches their starting tag. The <p> tag is always ended with </p>.
Secondly, you may have noticed that all of the HTML tags are written in lowercase. This is technically unnecessary. You can write HTML in all capitals if you want to, but it’s a good general practice to write them in lowercase. You can even write them in any combination of lowercase and uppercase, but this serves no purpose and simply makes your code harder to understand and, more importantly for you, write.
And last but certainly not least is the fact that HTML is used to convey meaning. For example, technically the <p> tag is not necessary, but it’s important because it conveys the meaning of a paragraph. These days it is bad practice to use HTML to make your website look pretty; there’s another coding language for that called CSS. HTML is there to make your website organized, not beautiful. Until you learn about CSS I recommend that you not try to make your sites look really nice, but rather focus on their organization. Think of HTML as an outline, if you will. CSS is what makes it look good, so don’t even worry about what it looks like right now. Throughout these tutorials I won’t even cover the HTML tags that only exist for presentation to make things easier to understand.
Now that I’ve gotten that out of the way, I think it’s time for us to learn a little more HTML! As I said in my last paragraph, HTML is used to organize information. If all you have are paragraphs, it’s a little difficult to organize, don’t you think? So on that note I will introduce HTML headers.
Headers are used to name sections of your site, thus making them more organized. For example, let’s say that you want to make a personal website. Maybe you want a section for current events at home and work, a section for your favorite books and movies, and one last section for your pictures. This is what HTML headers were designed for.
There are six levels of HTML headers, and they are represented thusly: <h1>, <h2>, <h3>, <h4>, <h5>, and <h6>. The <h1> header should only be used on your site once! For this reason I recommend using the <h1> tag to name your page. Here’s how I might start writing a page for myself:
<html>
<h1>Welcome to my website!</h1>
<p>Hi there, and welcome to my website! My name is Kevin Owen. This is my personal website, so feel free to poke around and see what's going on in my life!</p>
</html>
Try writing a level 1 header for yourself and provide a short description of your site in a paragraph. Once you’re finished make sure to save your index.html file and refresh your browser so you can see the changes. The first thing you should notice is that the <h1> tag makes the text within it much larger than a normal paragraph! If all of your text seems to be bigger, make sure that you properly closed your <h1> tag with its end tag, </h1>.
Each level of header in HTML gets smaller and smaller in text size. A level 6 header (<h6>) is the smallest header, and is actually smaller than the normal paragraph’s text size. Please note that it’s generally good web design practice to only use the headers in order. You can use as many <h2> to <h6> tags as you want on your page, so you don’t have to feel restricted when using headers. Also make sure to remember that headers are there to keep your page organized. Going back to the example of a personal website, here’s how I might code mine:
<html>
<h1>Welcome to my website!</h1>
<p>Hi there, and welcome to my website! My name is Kevin Owen. This is my personal website, so feel free to poke around and see what's going on in my life!</p>
<h2>Current Events</h2>
<p>Here are the things going on in my life right now:</p>
<h3>Current Events at Home</h3>
<p>My daughter, Aidan, just recently learned how to use a straw. This is so wonderful, and certainly makes feeding her much easier now than it was before! She just amazes me every day.</p>
<h3>Current Events at Work</h3>
<p>I'm really starting to get a feel for the place now. I've only been working here for a couple of months now, but I'm already starting to feel like I know the place! It's a good feeling, I'll tell you that. Getting lost for the first two weeks was no fun at all.</p>
<h2>My Favorites</h2>
<h3>Favorite Movies</h3>
<p>My favorite movies right now are Black Hawk Down, Cold Mountain, American Beauty and End of Evangelion. Call me artsy, but I love them all.</p>
<h3>Favorite Books</h3>
<p>Lately I've been reading a lot of books on how to write better code. My favorites right now are Essential PHP for Web Developers and Fresh Designs for Web Designers. I'm a nerd, I know!</p>
<h2>Pictures</h2>
<p>Uh oh... I don't have any pictures yet!</p>
</html>
Whew… now I know that took a little while to do, but go ahead and save your index.html file and refresh your browser. Take a look at your page now! Looks a little better, right? Certainly more organized than if you didn’t have headers! If your page doesn’t look how you expected it to, make sure that all of your tags are opened and closed properly. The life of a web designer is one of trial and error, so make sure you save your pages often.
At this point you may have noticed that there’s nothing under the Pictures header, seeing as we don’t know how to add images to our web pages yet. You also may have noticed that all of our tags so far have both starting and ending tags. The next tag that I am about to show you, <img>, does not have an end tag. This tag allows you to add images to your web pages.
The <img> tag requires a bit of explanation. The more technical may notice that the <img> tag can’t possibly know what image you want. All it does is tell the web browser that you want an image, but there doesn’t appear to be a way to show the browser what image you actually want. Now it’s time to introduce attributes.
The simplest way to describe an attribute is that it supplies more information to a tag. Attributes come in many different forms, but all of them serve the same general purpose: to provide more information about a tag. In the case of the <img> tag, the src attribute points to an image to be displayed. The abbreviation src is shorthand for “source.” To make things simple, I recommend that you place any images you want for your web page in the same folder that you have your index.html file saved. In my case, I placed my index.html file in My Documents on my Windows XP laptop and in the Documents folder on my Macintosh. Place any pictures you want on your web page in the exact same folder that your index.html file is.
In order to display an image on your page you need to type in the <img> tag with the attribute src pointing to your image. Here’s an example of what the <img> tag would look like for a picture titled pic1.jpg:
<img src="pic1.jpg">
Notice the syntax for an attribute. It goes after the name of the starting tag (img) and before the less-than sign for the starting tag followed by an equals sign and, in the case of the src attribute, the name of the picture surrounded in quotation marks. Anything in between the quotation marks is referred to as a value for its attribute. In this case, the value for src is pic1.jpg. You could read the tag above as saying “the source of this image is pic1.jpg.”
Also notice that the <img> tag does not have a closing tag. There is no need for one, as there is no information to be enclosed. It’s simply an image. Try adding some images to your page now. Remember to make sure that the image source you type in is exactly the same as the image’s name in your folder, including spaces! Now save your index.html file and refresh your browser.
If you included more than one image in your page, you may notice something. Images don’t space themselves out like paragraphs do. Each time you start a new paragraph, a new line is automatically started for you leaving a blank space in between your new paragraph and the old one. Images don’t do this; in fact, they’ll display directly next to each other, no matter how you type it in your text editor. Press Enter as many times as you want, but those images will be right next to each other. Now we’re going to have to force a line break with, you guessed it, an HTML tag.
The <br> tag forces HTML to create a new line. When you start and end a paragraph HTML forces line breaks for you, but for some tags (like <img>) there is no line break. So, we have to force it down. The <br> tag is another HTML tag that does not have an end tag, as it does not require any information. It simply forces a line break. In fact, br is shorthand for “break.” So let’s try this out. If you only have one image for your page you can still try this out by simply using the same image twice. Let’s take a look at what the code might look like:
<img src="pic1.jpg"><br>
<img src="pic2.jpg">
Try this code on your page, save the index.html file and refresh your browser. That’s much better, isn’t it? You can use the <br> tag at any point in your page to force the line down, even in the middle of a paragraph. This comes in handy in those situations where you need fine control over the way your information is presented.
There are still a few things to show you about your HTML page before this tutorial is complete. Most notably, you may have noticed while viewing your web page that it has no official title; your web browser just shows the path to your HTML file instead of an actual title at the top of the window. There is a quick and easy way to add a title to your web page, but it requires a minor restructuring of your current page.
The tag for giving your page a title is the <title> tag; however, this tag cannot be used just anywhere on your page. As you may recall, the <html> tag is used to define HTML information. Within the <html> tag there are two other commonly used tags. These are the <head> tag and the <body> tag, used to define HTML heading information and body information respectively. The body of your HTML document is where all of your code that will be displayed is stored. The heading contains information that isn’t necessarily displayed, but is used by the browser nonetheless.
Knowing this, let’s restructure our page accordingly. The <title> tag belongs in the <head> tag, and everything else goes into the <body> tag. Let’s take a look at what our HTML might look like now:
<html>
<head>
<title>Welcome to my website!</title>
</head>
<body>
<h1>Welcome to my website!</h1>
<p>Hi there, and welcome to my website! My name is Kevin Owen. This is my personal website, so feel free to poke around and see what's going on in my life!</p>
<h2>Current Events</h2>
<p>Here are the things going on in my life right now:</p>
<h3>Current Events at Home</h3>
<p>My daughter, Aidan, just recently learned how to use a straw. This is so wonderful, and certainly makes feeding her much easier now than it was before! She just amazes me every day.</p>
<h3>Current Events at Work</h3>
<p>I'm really starting to get a feel for the place now. I've only been working here for a couple of months now, but I'm already starting to feel like I know the place! It's a good feeling, I'll tell you that. Getting lost for the first two weeks was no fun at all.</p>
<h2>My Favorites</h2>
<h3>Favorite Movies</h3>
<p>My favorite movies right now are Black Hawk Down, Cold Mountain, American Beauty and End of Evangelion. Call me artsy, but I love them all.</p>
<h3>Favorite Books</h3>
<p>Lately I've been reading a lot of books on how to write better code. My favorites right now are Essential PHP for Web Developers and Fresh Designs for Web Designers. I'm a nerd, I know!</p>
<h2>Pictures</h2>
<img src="pic1.jpg"><br>
<img src="pic2.jpg"><br>
<img src="pic3.jpg">
</body>
</html>
Save your index.html page once again and refresh your browser. If you used the <head>, <title> and <body> tags correctly you should see that your page now has a title in your web browser’s title bar and all of your information is displayed correctly on the page inside of the <body> tag. If the page isn’t displaying in the way you expected, make sure that you have properly opened and closed all of your tags. Always be sure that the <head> tag is closed before starting the <body> tag, and be sure that the <body> is closed before closing your <html> tag. A basic template for almost any web page under the sun is as follows:
<html>
<head>
<title>This is the page's title</title>
</head>
<body>
<p>This is where the page's content goes.</p>
</body>
</html>
Notice that in the above example I made an extra space between the <head> and <body>. I did this to make the code slightly easier to read. HTML does not care if you have empty spaces like that in your code; it just ignores them. In some cases, such as keeping your code organized, this is great. In others, it’s not, such as when you really want that empty space there. This is where the previously mentioned <br> tag comes into play.
In any case, these are the absolute basics of HTML. There’s still a lot to learn, but now that you’ve read this tutorial (and hopefully understood it), you should know the essentials of how to write your own web page from scratch. The next tutorial, Linking Your Pages Together, shows you how to create a web site from any number of web pages by linking the pages together, as well as showing you more hints and tips about how to write correct HTML.
Thank you for reading!