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> <html> <head> <base target="_blank"> </head> <body> <a href="https://www.example.com">Example</a> </body> </html>