HTML Tags: <base>

Overview

base

Somehow the <base> tag remains unknown to most of the web developers, but that’s quite normal. However let see what it can do. By adding the <base> tag in the head of the page you tell every link into that page how to open and a default href value. Thus if you have:

<base href="http://www.stoimen.com/blog/">

every link without a href attribute will open this link. That’s really useful in some cases. However the most interesting part of the base tag is the target attribute.

target=”_blank”

Everybody knows what will result from this attribute attached to a anchor tag.

<a href="http://www.stoimen.com" target="_blank">Click Here</a>

But with only adding this base tag:

<base target="_blank">

into the head … all the links will open in a new tab/window, depending on the browser preferences.

Watch out!

If you add the line above somewhere into the <body> tag the browser, will put it into the <head> which will make it difficult to track. A good practice is to place it directly into the <head>!

One thought on “HTML Tags: <base>

  1. You might be surprised how many people I’ve seen implement this incorrectly, setting the hostname portion of the URL to the server name the site runs on instead of the site URL.

    Or setting it to a URL of a dev or test site then deploying to the live servers.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>