Skip to content
The <head> Observatory

/static/observatorio/en/astro/base-href/

Menu

HED-021 · Behavior

<base href>

Changes the ruler for every relative address in the document — every single one.

One line, and every relative URL in the document — links, images, stylesheets, scripts, forms — starts resolving against the declared address instead of the page's own. There can be only one <base>, and it must come before any element that uses a URL.

It is almost always a bad idea because of its reach: even anchors obey, and an innocent href="#top" becomes a navigation to another page. One oversight affects the whole document. It survives where it truly makes sense — HTML email, site mirrors, generated documentation meant to be served from any folder.

<base href="https://exemplo.org/docs/">
<!-- <a href="#topo"> now leads to /docs/#topo -->
Even the internal anchors obey the new ruler.