scriptygoddess

13 May, 2002

base href

Posted by: kristine In: How to's

I saw a question about some html come acrossed one of the maililng lists I'm on this morning, and thought I'd share some about it! Since it was a relatively new piece of knowledge to me, I thought maybe it would be helpful to someone.

The <base> tag: The base element defines a default reference to external resources.

There are definite advantages to being able to specify a default location. It means that you don't need to use absolute URLs to images when using PHP or SSI headers which will be used acrossed multiple directories and subdirectories. Same goes for templates on journal/weblogs, even when you are using the design throughout the system even in archive directories. I just stick this tag inside my head before my stylesheet link:

<base href="http://your-site.com/images">

Then the src to a image only looks like this:

<img src="smile.gif">

So basically, it just makes sure that your pages know where they are in the directory structure instead of using a lot of relative paths that look like ../../image and trying to keep track of where in the structure you are! Isn't it nice to know something that could make your html files smaller or save a few keystrokes? :)

7 Responses to "base href"

1 | Lynda

May 13th, 2002 at 7:16 pm

Avatar

Thanks for this, Kristine! I never really understood the use of the base href. :) Woot!

2 | kristine

May 13th, 2002 at 8:06 pm

Avatar

Oh, and I forgot to add…. with MT and GM, you can set this path to be equal to the URL of your blog automatically (so that if you change your location of your journal, it will auotmatically change the path) by using these:
For Movable Type:

<base href="<$MTBlogURL$>">

For Greymatter:

<base href="{{logwebpath}}">

3 | Jennifer

May 13th, 2002 at 10:25 pm

Avatar

WOW! Great tip!!! Did not know that one!!!! Your rock! :)

4 | Row

May 14th, 2002 at 3:53 am

Avatar

I didn't know that :) Although I think I will keep doing it with the absolute urls, because otherwise I'll do something like try to link to another page or something and it will go looking for images/aboutme.php, or whatever.

5 | kristine

May 14th, 2002 at 7:56 am

Avatar

Row, so just start the base href one level higher. Use
<base href="http://your-site.com/"> and then when you use images, do
<img src="images/image.gif">
and this will make it so if you point to aboutme.php, it will be under the main directory

recap – so the image is in http://yoursite.com/images/image.gif
and the file is in http://your-site.com/aboutme.php

Does that make more sense? :)

6 | Row

May 15th, 2002 at 12:37 am

Avatar

Yes! Enough so that I will probably implement it. :) Thanks.

7 | Linda Cox

February 3rd, 2005 at 12:26 am

Avatar

Can you use a base href in email?

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements