🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEhtml

html Documentation

LOADING ENGINE...

HTML Base Tag

Set a global baseline URL for all relative links. Learn to harness the power of the <base> element.

index.html
<!-- Global Resource Path -->
<head>
<base
href="https://cdn.example.com/"
target="_blank"
/>
</head>
🚀
All systems go
base-url.html
1 / 8
🏠

Tutor:The <base> tag specifies the base URL for all relative URLs in a document. It must be placed in the <head> section, and there can only be one <base> tag per document.

Base Mastery

Unlock nodes by learning base URLs.

Concept 1: The Base Tag

The <base> tag specifies the base URL for all relative URLs in a document. It simplifies link management by setting a default starting point for all relative paths.

System Check

What does the <base> tag explicitly specify?

Community Holo-Net

Share URL Strategies

Created efficient URL management patterns? Share your base URL strategies and techniques with fellow developers.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

What is the HTML Base Tag?

Author

Pascual Vila

Frontend Instructor

The <base> tag is an HTML element that specifies a default base URL for all relative URLs contained within a document. By defining a global starting point, it streamlines the management of links, images, scripts, and stylesheets across your web pages, making your code cleaner and easier to maintain.

How to Use the Base Tag

To implement it correctly, the <base> tag must be situated exclusively within the <head> section of your HTML document. Crucially, an HTML document can contain only one base tag. Using multiple base elements leads to unpredictable browser behavior and invalid HTML.

Mechanism of URL Resolution

When a base URL is defined, browsers use it as the definitive prefix for every relative path they encounter. Consider this scenario:

  • Your base tag defines: https://example.com/assets/
  • You insert an image with a relative path: images/photo.jpg
  • The browser intelligently resolves and requests: https://example.com/assets/images/photo.jpg

Global Target Attribute

Beyond just paths, the target attribute on the <base> tag establishes a global default target for all hyperlinks and forms. Acceptable values include _self, _blank, _parent, and _top. Any individual anchor (<a>) tag can seamlessly override this global rule by defining its own target attribute.

Primary Use Cases & Best Practices

The base tag shines in specific architectural setups:

  • Centralizing asset distribution through Content Delivery Networks (CDNs).
  • Simplifying massive applications with deeply nested routing.
  • Migrating websites across directories without manually rewriting hundreds of relative URLs.

Warning: Because the base tag affects all relative links silently, it can confuse team members unaware of its presence. Document its usage clearly and test routing thoroughly, especially in Single Page Applications (SPAs) where routing libraries might conflict with a global base.

Technical Glossary

<base>
HTML element dictating the baseline URL for all relative URLs in a document. Restricted to the <head> section.
href attribute
The mandatory parameter on <base> that declares the root URL. It requires an absolute, fully-qualified URL.
target attribute
Optional parameter applying a universal browsing context behavior (like opening in new tabs) to all document links.
Relative URL
A partial URL missing the protocol or domain, fundamentally dependent on the <base> declaration to function.