www.htmlgoodies.com/primers/html/article.php/3478151
|
By Joe Burns December 30, 2008 (with updates by editorial staff) Use these to jump around or read it all Hello and welcome to day two! No doubt you've attempted to write a small document on your word processor and save it as TEXT for MAC or ASCII TEXT DOS or TEXT for your PC. You also remembered to save the document with the .htm or .html suffix, I'm sure. Good, now let's move on to today's lesson, for today we actually write some code! HTML TagsHTML works in a very simple, very logical, format. It reads like you do, top to bottom, left to right. That's important to remember. HTML is written with TEXT. What you use to set certain sections apart as headings, subtitles, bold text, underlined text, etc is a series of what we call "tags". Think of tags as making your structure. Let's say you want a heading. You will put a tag at the exact point you want the heading to start and another tag where you want the heading to stop. If you want a specific word to be emphasized, you will place a start emphasis tag at the beginning of the word and an end emphasis tag at the end of the word. Is this making sense so far? Tag FormatAll tag (I sometimes call them command) formats are the same. They begin with a less-than sign: < and end with a greater-than sign: >. Always. No exceptions. What goes inside the < and > is the tag. Learning HTML is learning the tag to perform whatever command you want to do. Here's an example: The tag for a paragraph is "p". That makes sense. For example: <p>Joe</p> In the old HTML standards, we used to use B for bold, and I for italics, etc. With the latest standards it is now accepted practice to separate content from presentation - by which we mean you set out the structure of your document in HTML, and control how it displays using a CSS file (more on CSS here!) This means we can mark our keywords using strong and em tags, which have the same effect, but comply with the latest standards. <strong>Joe</strong> and <em>Burns</em> Look At What's Happening:
Some QuestionsQ. Is the end tag for other commands simply the begin tag with the added slash? Q. Will the tags show up on my page? Q. Do I use capitals or lower case? I've seen people using both. Q. Must everything have a tag to show up on the page? Q. What if I forget to add the end tag or forget to add the slash to the end tag command? Q. Do all HTML tags require both a begin and end tag, like above? Open and Close TagsThe majority of HTML tags do require both an open and a close tag (a begin and end tag). Most are very easy to understand because the tag is obvious. Here are a few and what they do to text:
Note: the strong and em tags are normally found inside a paragraph. There is a technical reason for this which we'll cover later. Can I Use Two Tags at Once? Yes. Just make sure to begin and end both. Like so: <strong><em>Strong and emphasis</em></strong> gives you Bold and Italic If you do use multiple tags to alter text, make a point of not getting the end tags out of order. Look at this:
In terms of format, the example above is not correct. The end tags are out of order in relation to the start tags. Follow this rule: Here, again, is the example above in correct form:
Notice the strong tags are on the far ends. Next in line are the emphasis tags. Just keep setting commands at the farthest ends each time you add them and you'll stay in good form. Single TagsThe open and close tag format dominates the majority of the available HTML tags, but there are tags that stand alone. Here are two useful ones:
Writing Your First PageSo, here we go... you're going to write your first HTML page using what you have learned above plus a few other items. And these other items are important to every page you will ever write. Why? Because they will be on every page you ever write. For a properly formed document, you need a 'doctype'. For example: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" This tells the browser exactly what version of html you are using. Whilst this won't make any difference to you early on, when you get into CSS and positioning it will have a huge impact, so get into good habits now to avoid the problems later! You will always have this tag: <HTML> Your next tags will always be these: <TITLE> and </TITLE> Finally, you'll end every page you write with this tag: </HTML> So, Here We Go!I want you to play around with these commands. Just remember that HTML reads like you do, top to bottom, left to right. It will respond where you place the start tag and stop where you place the end tag. Just make sure your tags are within the < and > items. Here's a sample page to show you what I mean for you to do tonight:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" Click here to view the sample page. Notice I only used the tags I showed you on this page. Yes, it's a simple page, but you're just starting out. Notice the <HTML> and </HTML>. Notice the <TITLE> and </TITLE>. See how there's a beginning and end tag when I alter the text and that the P and BR commands are used to go to new lines? Look at the program above and then what it produced. Look at the source code when you open the page. See how the HTML tags denoted where text was affected? Good! I knew you would. Now go! Go into the world -- or at least to your text editor -- and create. Follow the instructions in HTML Primer #1 to help you save and then display your first HTML page.
|