Menu
Document Structure & Metadata

<base> Tag

Set a base URL for all relative links on the page.

1Setting a Base

A single <base> tag in <head> rewrites every relative href and src to resolve from the given URL. Use it carefully — it affects the whole document.

Example Code
css
<head>
  <base href="https://cdn.example.com/v2/" />
  <!-- /img.png will resolve to https://cdn.example.com/v2/img.png -->
</head>

2Put the element in context

A base URL changes how relative URLs throughout the document are resolved. That can affect links, images, stylesheets, and section anchors in unexpected ways. Most small websites do not need a base element; ordinary relative or absolute paths may be easier to understand.

3Practice with a small page

Create a test document with a relative image and link, then add a base URL and inspect where they resolve. Remove it and compare again. Check fragment navigation carefully before keeping a base element in a production document.

Finished reading?

Mark this topic as complete to track progress.