# Build It! HTML

Basic HTML

HTML is the language that web browsers and web servers use to display web pages. HTML "tags," when added to a plain text document, instruct web browsers how to display that content on a web page. If a web page is a house, its HTML code is its blueprint.

True, you don't absolutely need to learn HTML to create your own web site. Programs like Dreamweaver let novice web builders edit HTML pages as easily as word processing documents. (Dreamweaver is covered in the Web Pages chapter) But these programs often generate unnecessary code that can make pages load more slowly and eat up precious bandwidth. When something just doesn't look right on a web page, it helps to have enough knowledge of HTML to go into the code and fix it yourself. Knowing HTML gives you additional control over creating clean, effective pages.

In this chapter, you'll learn the newest variation of HTML, known as XHTML. There's a long, complicated explanation for it – how it combines ordinary HTML with aspects of XML, a newer technology that's designed to be read by computers the way Web pages are read by human beings. (For a full explanation of how to update basic HTML code to today's standards, tryWebmonkey.com's page on XHTML doctypes (http://www.webmonkey.com/tutorial/Update_Your_Old_Site_to_Use_Web_Standards). What you need to know is that using XHTML will make sure that your pages work well on Web browsers for years to come while still looking great for users who have older programs.

Every web browser has its own quirks and bugs. Some pages that look fine in Internet Explorer are a jumbled mess in Firefox, Safari or Chrome. By sticking closely to the rules of XHTML – writing standards-compliant code, as it's called – you can ensure that your pages will look their best on a variety of browsers.

Starting from Scratch

Ready for your first look at XHTML code? While looking at any web page, go to your web browser's View menu and select the option labeled "Source" or "Page Source." A window will pop up showing you the source code that created that page. It may look complicated at first, but, once you learn the basics, it'll make a lot more sense.

Tags: Every bit of code inside < > brackets is a tag, an instruction to the web browser. Under XHTML rules, tags should always be in lower case.

There are two kinds of tags. Paired tags surround text or other tags, and modify whatever they surround. For instance, they make text bold or italicized or create a link to another page. Paired tags look something like this:

<b>This text will be bold.</b>

In a web browser, such a tag will create text that displays like this:

This text will be bold.

In the example above, the <b> tag indicates the beginning, or opening, of boldface in the text. The </b> tag is the ending, or closing, tag. It lets the web browser know where the boldface ends. Notice that extra forward slash "/" before the "b"? Ending tags always include that forward slash. For instance:

<u>This text is underlined,</u> but text outside the tags is not.

In a web browser, that code displays like this:

This text is underlined, but text outside the tags is not.

Paired tags must have both an opening and a closing tag to work correctly.

Stand-alone tags don't modify any other text or tags. They are most frequently used to do such things as create line breaks, place a horizontal line across the page or insert an image.

<br /> creates a single line break.
<hr /> creates a horizontal line or rule.

Stand-alone tags always end with a space, then a forward slash "/" before the final bracket ">", as seen above.

Nesting Tags

What if you want to create text that's both bold and italicized? Simply "nest" one pair of tags inside the other:

<b><i>This text is both bold and italicized.</i></b>

Make sure that you close the innermost set of tags before you close the pair that surrounds it. For example:

Wrong: <b> <i> The end tags are in the wrong order.</b></i>
Right: <b> <i> The end tags are in the right order.</i></b>

Always remember to include both beginning and ending tags:

Wrong: <p> <b> This is missing an ending bold tag, and everything that follows it will mistakenly be bold.</p>
Wrong: <p> This paragraph is missing a beginning bold tag, and will not display as boldface.</b></p>

Images

To add an image to your page, use the <img /> stand-alone tag. But wait – which image are you using? How wide or tall is it? What is its description?

To answer these questions, you need to add attributes to the image tag. Attributes provide more specific information about a tag – in this case, information about the image you want to add. Suppose you have a JPEG photo of a fire truck, named firetruck.jpg, that is 200 pixels wide and 100 pixels high. To put it on your website, you'd enter this code at the place within the page where you want the image to appear:

<img src="/images/firetruck.jpg" height="200" width="100" alt="A large red fire truck" align="left" />

To break those attributes down one by one:

  • src: Specifies the source of the image. What is the name of the image file, and where is it located? Every <img /> tag must include this attribute; the others are optional but useful.

The src attribute must be given a path it can follow, from the top directory of your site all the way to the place on your server where you've stored the image. Each new step on that path is marked with a forward slash "/".

Suppose that you've placed firetruck.jpg in a folder or directory named "images" at the initial level of your website – the same directory where you store the very first page of the site. In that case, its path would be:

/images/firetruck.jpg

The first forward slash tells the web browser to start looking for the image at the very top level of your site. The next part, "images/" then instructs the browser to look inside a directory named "images". Finally, it's told to find the image inside that directory named "firetruck.jpg."

Remember this system. It's also used when you create a link between pages on your own site.

  • height and width: The dimensions of the image, in pixels.
  • alt: A text description of your image for people who have images turned off, or for blind visitors using special screen-reading web browsers.
  • align: If you want the image to appear flush left or flush right on the page, with the rest of your text wrapping around it, give align a value of "left" or "right." If you just want the image to appear as part of the regular flow of text, leave out the align attribute.

Links

To insert a link to a page within your site or on another site, use the <a> and </a> pair of tags. A link looks like this:

<a href="http://www.j-lab.org">J-Lab</a>

In paired tags, attributes always go inside the beginning tag. The href attribute stands for hypertext reference, which is a fancy name for "link." It answers the question, "If I click on this link, where will it take me?"

In the example above, the presence of the <a> and </a> tags tell the browser, "Make the word 'J-Lab' a link." The href attribute then tells the browser, "This link should take users to http://www.j-lab.org/."

When linking to an outside site, always begin the link with "http://". This tells the web browser to look for an outside site, rather than searching the pages within your own site.

When linking to another page on your own site, use the same sort of paths discussed for finding images. For example, if you want to link the words "Local News" from your home page to a page on your site called local.html, stored in a directory named "news," the link might look like this:

<a href="/news/local.html">Local News</a>

A Basic Document

In XHTML, all documents are divided into two parts: the head and the body. The body is that part you see on screen. The head contains information about the document, like the document's title, its author, any necessary styles or scripts, and other information telling the browser about how to display the page. The bare-bones format of an HTML document looks like this:

<html>
<head>
<title>The name of the page goes here. It will appear at the top of the web browser window when the page is viewed.</title>
</head>
<body>
The content of your page goes here.
</body>
</html>

XHTML takes this basic setup and adds a few extra elements to it.

Adding XHTML to a Basic Document

The following text may not make sense, but it's an important part of proper XHTML formatting. It tells the browser what kind of file it's reading, and how to interpret the code in that file. Make sure you put it at the very beginning of every XHTML file you create.

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> The title and other head information goes here. </head> <body> The content of your page goes here. </body> </html>

For more detail see:
http://www.w3.org/TR/xhtml1/#xhtml
http://www.w3.org/MarkUp/2004/xhtml-faq
http://www.codeproject.com/html/htmltoxhtml.asp

Additional Simple Tutorials

There are dozens of other tags we haven't discussed. For more information, we recommend the following links:

http://www.htmlgoodies.com/primers/basics.html
http://www.webmonkey.com/tutorial/tag/web_basics
http://www.w3schools.com/default.asp
http://www.w3.org/MarkUp/Guide/

> READ NEXT ARTICLE: Creating Forms

 

recent comments

  • As one who has just started to dabble with HTML, I found your presentation (1) demystifying; (2) graphically effective.  thanks, jack driscoll

    Posted by driscoll  on  08/31  at  03:41 PM
  • The webmonkey link above seems no longer to be going to the right place. (http://webmonkey.wired.com/webmonkey/authoring/html_basics/)

    Posted by  on  02/09  at  11:50 PM
  • I’ve fixed the Webmonkey links. Thanks for the heads up.

    Posted by Craig Stone  on  02/12  at  09:17 AM
  • Keep in mind that by using an XHTML DOCTYPE, the use of <b>, <i> and <u> are invalid.

    Posted by Patrick Beeson  on  01/08  at  02:36 PM
  • Very well written post, but it lacks the buttons(post) usage which is very important for begginers, and used in even the most basic html pages around

    Posted by vagrantly  on  08/14  at  01:04 PM
  • Useful summary of HTML and XHTML.  I agree with the points made early in the article - it is easy these days to produce websites without knowing any HTML at all, but it is very useful to have a grasp of at least the basics in order to modify things or correct things you don’t like.

    Posted by MartinP  on  08/26  at  05:13 AM
  • Nice concise overview of HTML - certainly one to point newbies at.  To be honest even those who think they are beyond the basics could often benefit from a little refresher!

    Posted by GregS  on  08/31  at  02:34 PM
  • very useful. thanks for sharing

    Posted by barney  on  10/06  at  12:20 PM
  • most web designer are using a programm for building a web page - but it is goog to know some basics

    Posted by krankenversicherung  on  11/17  at  09:06 AM
  • What a terrific resource. As someone who blogs a lot and needs to use HTML this is excellent.

    Posted by Framingham MA Real Estate  on  01/17  at  09:34 PM
  • Yes, programs like DreamWeaver, Joomla, Wordpress are convenient but don’t totally eliminate the need for basic HTML programming. 

    You often need to apply some HTML for “tweaking.” These are useful, basic commands listed here.

    Posted by applied  on  02/09  at  12:47 AM
  • As you correctly say in your article, more and more there is no need for new developers to ever actually ‘get their hands dirty’ and write HTML as there are so many higher-level tools available.  However, an understanding at the level outlined in your article is very valuable - it’s always good to have an appreciation of the underlying coding.

    Posted by Tony  on  02/10  at  08:38 AM
  • i think the modifiers are important too i.e. align etc.

    Posted by werdnax  on  02/12  at  04:57 PM
  • This is a very useful article for webdesign-beginners. I gave this information to my brother, and he has now made his first website.

    Posted by lenen bkr  on  02/20  at  05:06 PM
  • Thats really helped me figure out some stuff on my wordpress template. thanks.

    Posted by getsixpackabs  on  03/04  at  06:23 PM
  • Nice summary on HTML and XHTML. Quite helpful for me. I am learning HTML now a days. I found that your tutorial is nice for students like me.

    Posted by used cisco switches  on  03/24  at  02:51 PM
  • Thanks for the heads up!

    Posted by maxalt  on  05/10  at  09:35 PM
  • The href attribute stands for hypertext reference, which is a fancy name for “link.” It answers the question, “If I click on this link, where will it take me?”

    Posted by woodpellet  on  06/04  at  07:51 AM
  • This is a really great tutorial and information for someone such as myself who is just starting to really learn the in’s and out’s of HTML.

    Posted by John Murphy  on  06/04  at  08:27 AM
  • This is a very good example of basic HTML for beginners who are just starting out. I found it helpful.

    Posted by djenkins4242  on  07/14  at  10:30 PM
  • I agree with it

    Posted by fiwedding  on  08/09  at  08:53 PM
  • This is a nice little intro guide.  Sometimes my these little things slip my mind since I use wordpress and themes for the majority of my projects.  When I have little side projects I want to draw up real quick its nice to have this resource available.  Saved me quite a bit of time because its all centrally located.  Thanks

    Posted by bob marley t-shirt  on  08/12  at  01:52 PM
  • Thanks for sharing this well-done article! I was feeling like in school learning step by step HTML codes. And i can tell you, that it was really exciting! it is perfect, when you get everything clear just through reading!

    Posted by dissertation writer  on  08/16  at  04:47 AM

post a comment

You must be registered (free) in order to post a comment.

 

More on This Topic

Evaluate This Page

How useful was this article?
(5 is extremely useful)

rate this a 1 rate this a 2 rate this a 3 rate this a 4 rate this a 5

Others have rated
this article: 3.9 / 5

discuss this topic

Post a comment

on Using Twitter for promotion and community

thanks for the help.i have been using twitter for a couple of months and its something that every business must use.Especially small businesses must not miss the opportunity at any cost.

on RSS Feeds

See some health resources tanning beds | aparate bronzat | health news | the cirrhosis | skin cancer | wellness menu |hygiene centre which will help you improve your view.

on Using Twitter for promotion and community

supra shoes supra skytop supras supra skytop 2 Supra Vaider coach outlet coach bags coach outlet store online coach handbags outlet coach shoes chanel bags, chanel online, chanel handbags, chanel handbags 2010, chanel 2.55 bags louis vuitton outlet, louis vuitton sale, louis vuitton handbags, louis vuitton wallet, louis vuitton bags gucci bags, gucci handbags, gucci outlet, gucci handbags, gucci wallets MBT Shoes, Anti Shoes, MBT Shoes Sale, Womens MBT Shoes, mens MBT Shoes
  thank you chicken23

nike air max, nike air max 90, nike air max shoes, nike air max 90, nike air max 180 MBT shoes, anti shoes, cheap mbt, womens mbt shoes, mens mbt shoes coach bags, coach outlet, coach outlet store online, coach wallets,coach handbags chanel bags, chanel online, chanel handbags, chanel handbags 2010, chanel 2.55 bags louis vuitton bags, LV handbags, louis vuitton outlet, louis vuitton wallet, LV coach outlet, coach outlet store online, coach handbags, coach wallets, coach handbags outlet
 

on Using Twitter for promotion and community

so good!

on Using Twitter for promotion and community

Thanks for the information!

Regards
6 bottle wine coolers