I am learning how to code on w3schools.com. There is an explanation on what is for but it's not very helping. All it says is "Defines a default address or a default target for all links on a page" why do we even need to do this?
-
When using `
` in your `` you cna define the path of the for example, image folder. so you dont have to use them everytime with ` ` and just only the image name. – Carl0s1z Apr 19 '14 at 21:12
-
4Your first mistake is in trying to learn from w3schools.com; it is widely considered to be of poor quality (see http://www.w3fools.com/) and there are better sources out there. Your second mistake is in assuming that you will ever actually need what is a rather obscure and old-fashioned bit of HTML. – IMSoP Apr 19 '14 at 21:14
-
possible duplicate of [Is it recommended to use the
html tag?](http://stackoverflow.com/questions/1889076/is-it-recommended-to-use-the-base-html-tag) – Wesley Murch Apr 23 '14 at 22:04 -
@IMSoP, how did the OP make the "mistake" of assuming that he needed `
`? He *asked* if he needed it. He assumed nothing. Your comment was rude, and missed that the questioner was... asking a question. (The base element is quite handy for HTML files/pages that might be downloaded and saved, which should be encouraged, like articles, posts, ebooks, etc. That way the browser always knows the root path to various resources, since the site path won't be in the URL bar when such files are opened.) – LearningFast Aug 03 '21 at 16:56 -
@LearningFast Since more than 7 years have gone by, I can only really guess at my own thought process, and on balance, you're right that it comes across a bit blunt. I think the point I was trying to make is that looking through a reference book (or its online equivalent) at every possible HTML tag and wondering why you'd use them is not a great way to learn, since there will be a lot of cases where the answer is "you wouldn't". It's a bit like learning a foreign language by reading the dictionary A to Z and asking for usage examples of words that you'll never use. – IMSoP Aug 03 '21 at 17:14
3 Answers
You normally don’t need the base
element. It is sometimes used when most URLs on a page refer to a site other than the site of the page; in that case, <base href="...">
lets you use relative URLs for those; but then all other URLs must be absolute. In the past, <base target=...>
was sometimes used on frameset pages in order to make link open in a particular frame.

- 195,524
- 37
- 270
- 390
When using <base>
in your <head>
you can define the path of the for example, image folder. so you dont have to use them everytime with <img scr="">
and just only use the image name.
So instead of : <img src="myFolder/images/image.png"
you can set it in your base.
Like this: <base href="http://www.mywebsite.com/images/" target="_blank">
And than write the image path like this. <img src="image.png"

- 4,683
- 7
- 32
- 47
-
This isn't a great example, because the base URL would also apply to all relative links, so if you pointed it at an image directory, you'd have to make every link an absolute URL. – IMSoP Apr 20 '14 at 11:15
Defines the base location for links on a page.
Relative links within a document (such as <a href="someplace.html"... or <img src="someimage.jpg"...)
will become relative to the URI specified in the base tag.
The base tag must go inside the head element.
Example
<head>
<title>Peppers</title>
<base href="http://www.somedomain.com/directory/" />
</head>
<body>
<p><a href="someplace.html">This</a> will actually link to http://www.somedomain.com/directory/someplace.html.</p>
<div><img src="someimage.jpg" alt="Some image" /></div>
<p> The location of the above image will be actually be http://www.somedomain.com/directory/someimage.jpg.</p>
</body>
Click Here It contains a bit clear explanation.

- 1,534
- 1
- 10
- 22
-
It is strongly encouraged not to leave answers consisting only of a link, as the contents of that link may change, and someone glancing at the page cannot see whether your answer is useful. Instead, consider quoting or paraphrasing the page, and including the link as acknowledgement / further reading. – IMSoP Apr 19 '14 at 21:16
-
Thank you for your suggestion @IMSoP. I will do in that way from next time. – Sailesh Babu Doppalapudi Apr 19 '14 at 21:20