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? :)

Related posts:

  1. Striping IMG tags from the_content in WordPress (and how to fudge page excerpts) Background: For a site I was working on, I was...

Related posts brought to you by Yet Another Related Posts Plugin.

7 Responses to "base href"

1 | Row

May 15th, 2002 at 12:37 am

Avatar

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

2 | Lynda

May 13th, 2002 at 7:16 pm

Avatar

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

3 | 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}}">

4 | Jennifer

May 13th, 2002 at 10:25 pm

Avatar

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

5 | 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.

6 | 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? :)

7 | Linda Cox

February 3rd, 2005 at 12:26 am

Avatar

Can you use a base href in email?

Featured Sponsors

About


Advertisements