"Grow Wise, Grow Happy," get organized, simplify, get motivated, increase productivity, accomplish goals, get healthy, raise happy kids, find your authentic self, improve your relationships, achieve success...

Using XHTML

Updated on November 24, 2007

XHTML is the backbone of the web page. It tells the computer how to display or handle the information.

The Tag

XHTML is based on tags. Every tag is enclosed in angle brackets < >.

The codes in the tags are the instructions. These codes must be written in lower case. (We'll talk about exceptions to this rule later.)

<tag>

All tags have an opening and a closing. The opening tag tells the browser where to start doing something, and the closing tag tells them computer when to stop doing it. (Notice the forward slash at the beginning of the closing tag.)

<tag>Stuff the tag deals with.</tag>

Some tags contain empty elements, elements that don't have stuff in the middle to deal with (e.g. image tags, horizontal rule tags, line breaks, etc.). An empty element doesn't have opening and closing tags, just a single tag with with a space and a forward slash ( /) at the end of the tag code.

<tag />

Elements

Every tag contains an element. The element is what the tag is all about.

This tag creates a table element. Everything between the opening and closing tags (the content) is in the table.

<table>
</table>

Attributes

Some elements have attributes. Attributes describe the element. The values of the attributes must be enclosed in quotes (" ").

This tag creates a table that is 100% wide.

<table width="100%">
</table>

The <!DOCTYPE ...> Tag

The first line of an XHTML document is the document type definition (DTD) tag. This tag tells the browser specifically what type of document the file is and how to display it. The following is a transitional XHTML 1.0 DTD (the transitional DTD is more flexible than the strict DTD because it allows you to use HTML formatting rather than just CSS).

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Check out http://www.w3.org/QA/2002/04/valid-dtd-list.html if you would like to see other DTDs you can use.

<html></html> Tags

The <html> tag tells the browser "This is the beginning of the HTML document." (Ok, so technically we're using XHTML code, but it's still considered an HTML document.)

The </html> tag tells the browser "This is the end of the code." The end tag is the very last line.

<head></head> Tags

The <head> tag marks the beginning of the page header and is placed immediately after the <html> tag.

The </head> marks the end of the page header.

The page header is where information about the page is kept.

The most common tags you'll find inside of the header are the <title></title> tags. These tags tell the browser the title of the page. (If you bookmark the page, this is what your bookmark will be called.)

You'll also find <meta>, <link>, <style>, <script>, and <base> tags.

<body></body> Tags

The <body> tag marks the beginning of the page content and is placed immediately after the </head> tag.

The </body> tag marks the end of the page content and is followed by the closing </html> tag.

The body of the document is where you would put everything you want displayed in the browser, such as text and images as well as objects.

Putting It All Together

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>This is the title of my page.</title>
</head>
<body>
<p>Example Text</p>
<img src="/images/sample.jpg" />
</body>
</html>

Properly Nested Tags

XHTML is very picky about its structure. Everything is nested in something else.

Think of every tag as a container.

Big Container: contains jelly beans + a medium container

Medium Container: contains chocolate pieces + a small container

Small Container: contains toffee pieces

If you were to describe these containers with tags, you would need opening and closing tags. The opening tag is the base of the container; the closing tag is the lid.

<big container>
Jelly Beans are in here!
<medium container>
Chocolate Pieces are in here!
<small container>
Toffee pieces are in here!
</small container>
</medium container>
</big container>

Here is the rule: You cannot let the contents of one container spill into another. If a container spills, the computer can't figure out what belongs where.

Example: This is a spill. Notice how it doesn't make sense. Logically the small container cannot be both inside and outside the medium and big container. It's either in it, or it's outside of it. It can't be both.

<big container>
Jelly Beans are in here!
<medium container>
Chocolate Pieces are in here!
<small container>
Toffee pieces are in here!
</medium container>
<big container>
</small container>

Likewise, your XHTML tags must be nested properly as well.

<p><b>Bold Text</b></p>

Notice how the following code isn't properly nested because the <b></b> tags are simultaneously inside and outside the <p></p> tags at the same time.

<p><b>Bold Text</p></b>
Scroll down to comment on this article.

Related Items

Similar topics

See other Kristen's Guide topics in this category.

----------

If you like this page, please share it with your friends.

Get Kristen's Guide Updates XML via Feed | via Email | via Facebook | via Twitter


All content written by Kristen Brooke Beck

© 2002-2012 Kristen Brooke Beck Company and its affiliates and assigns and licensors. All rights reserved.

TM Kristen's Guide , "Grow Wise, Grow Happy!", and the Kristen's Guide flower logo are trademarks of the Kristen Brooke Beck Company. Trademarks may be registered in some jurisdictions and may not be used without written permission. All other trademarks are the property of their respective owners.

DO NOT distribute without explicit written permission. Request Permission to Reprint an Article or Printable

Information on Kristen's Guide: http://www.kristensguide.com is an expression of personal opinion intended for educational and entertainment purposes and is not a substitute for services from a licensed professional. By accessing this website or using the information from this website in any way, you are agreeing to the terms of the User Agreement at http://www.kristensguide.com/user_agreement.asp.

Search
Custom Search

Get Updates XML via Feed
via Email
via Facebook
via Twitter

Free Tools Free Printables
Free Calculators

Guides to Finding Happiness
Helping the World

Getting Healthy
Losing Weight
Looking Beautiful

Managing Your Home
Getting Organized
Food
Emergencies
Gardening

Family & Parenting
Genealogy
Relationships & Friendships

Etiquette & Courtesy
Holidays & Gift Ideas
Travel

Money
Career & Business

Computers
Website Design
Writing

Kristen's Picks Books
Software Programs
Charities
Favorite Sites
Alex Haddox Personal Protection

About KG

Who is Kristen: The BIO+FAQ

What is Kristen's Guide?

Reprint an Article/Printable
Organizations that Reprinted Articles/Printables

Testimonials
Site Map
User Agreement & Privacy Policy
Contact Info
Home Page

Advertising

Advertise on KG
Site Statistics

Reviews of Your Products

Spread the Love If you like this page, please share it with your friends.

Latest Updates

Waist to Height Ratio Fixed on the Weightloss Profile Calculator

2012 Exercise/Fitness Planner Now Ready & Available

New Menu and Exercise Planners for New Year's Resolutions

More 2012 Calendars Still to Come

More New 2012 Weekly Calendars Are Ready on Kristen's Guide


See All Updates


Stay Updated...

XML via Feed
via Email
via Facebook
via Twitter

Most Talked About


Stay Updated...

XML via Feed
via Email
via Facebook
via Twitter

Get
Kristen's Guide
Updates

XML via Feed
via Email
via Facebook
via Twitter

Get
Kristen's Guide
Updates

XML via Feed
via Email
via Facebook
via Twitter