Content · Web Development · HTML

HTML Base Element Side Effects on Fragment Links

The base element changes how relative URLs are resolved. This includes fragment-only links, which may unexpectedly resolve against the base URL instead of the currently displayed file.

1 views Published Oct 19, 2026 Updated Oct 19, 2026 Admin

The base element changes how relative URLs are resolved. This includes fragment-only links, which may unexpectedly resolve against the base URL instead of the currently displayed file. The important question is always where the link leads and whether the person reading the page can predict it.

What You Need to Know


Because it changes many links at once, it can create subtle bugs. Prefer explicit working paths unless a base URL solves a real document-level requirement.

Links are the pathways through a website. The words on a link should help someone choose where to go before clicking it.

Example: See It in Action


Add this example to the appropriate part of a practice HTML page. Read each line before you open the page in your browser.

If this is only part of a document, place metadata and style elements in the head of a complete HTML page. Keep ordinary visible content in its body.

<head>
    <base href="https://example.test/manual/">
    <title>Link Resolution</title>
</head>
<body><a href="#safety">Safety section</a>
    <h2 id="safety">Safety</h2>
</body>

Let’s Understand the Example


  • An a element becomes a working link when it has an href. Its visible text should tell readers where they will go.
  • The head contains useful page information for the browser, such as its title and character encoding.
  • The base element changes how relative links are resolved across the document. It can surprise you if used casually.
  • Href contains the destination of a link. A value starting with # points to an id on the same page.
  • Id gives one element a unique name within the page, so a link, label, or script can point to it.

The first example link points to https://example.test/manual/. Check whether that destination exists relative to the document. A link changes where readers go; it does not perform an action such as saving a form.

What Should You See?


You should see a link named “Safety section”. Selecting it leads to #safety when that destination exists. Try it with the mouse and the keyboard.

Imagine this link is read out of context. Would its text still explain the destination? Rename unclear links before trying to make them look nicer with CSS.

Try It Yourself


  1. Remove base from the example and describe how the fragment target changes.
  2. Save your changes, open or refresh the page, and compare the result with the original example.
  3. Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.

Common Beginner Mistakes


  • Adding a base element without retesting fragment navigation.
  • Avoid dead links, empty href values and clickable-looking text without a real destination.

Key Takeaways


  • The base element changes how relative URLs are resolved.
  • An a element becomes a working link when it has an href. Its visible text should tell readers where they will go.
  • Because it changes many links at once, it can create subtle bugs. Prefer explicit working paths unless a base URL solves a real document-level requirement.
Share this resourceSend this page to someone who may find it useful.