Home > Article > Web Front-end > Can CSS Open Links in New Tabs Like \"target=_blank\"?
Using CSS to Add "target=_blank" to External Links
Opening external links in new tabs is a common usability feature. While HTML provides the "target=_blank" attribute to achieve this, you may wonder if there's a similar CSS property.
Is there a CSS alternative to "target=_blank"?
Unfortunately, no, there is not a pure CSS solution to open links in new tabs. CSS does not have the ability to influence link behavior.
HTML Solution
Instead of relying on CSS, you can use the following HTML code in the
tag:<code class="html"><head> <base target="_blank"> </head></code>
This sets all links on the page that do not specify a target attribute to open in a new window or tab.
Overriding "target=_blank" with Links
If you need specific links to override the default, you can use the "target=_blank" attribute on individual links:
<code class="html"><a href="/yourlink.html" target="_blank">test-link</a></code>
This will override the general "target=_blank" setting defined in the
tag for that particular link.The above is the detailed content of Can CSS Open Links in New Tabs Like \"target=_blank\"?. For more information, please follow other related articles on the PHP Chinese website!