Skip to content


Open all links in an HTML document in a new tab

One of the lesser used HTML elements, in my experience, is the <base> element. The purpose of this element is to specify a base URL for all relative URLs in a document. This means that if you have a bunch of links in your document, you can use the <base> element to specify that all of those links should have a base href or target attribute, or both.

Leveraging this element, we can set the target attribute to _blank to make all links in the document open in a new tab. Simply adding a line to the <head> of your HTML document will do the trick.

<!DOCTYPE html>
    <base target="_blank">
    <a href="">Example</a>
⚠️ Warning

There are some security risks involved with opening links in a new tab. Be sure to read the tip on safeguarding target="_blank" links to learn how to protect your users from malicious websites.

More like this

Start typing a keyphrase to see matching snippets.