Home > Article > Web Front-end > Can You Open Links in New Tabs Using Only CSS?
Target="_blank" in CSS: Is It Possible?
External links embedded in a website's menu often require opening in new tabs to provide a seamless user experience. While the target=_blank attribute in HTML effectively achieves this, is there an equivalent solution using CSS properties or other techniques?
Answer:
Unfortunately, pure CSS lacks the capability to specify the target="_blank" attribute. However, HTML offers an alternative solution:
Using
Within the
tag of your HTML document, include the following code:<head> <base target="_blank"> </head>
This sets the default target for all links in the page to "_blank," opening them in a new window.
Overriding with Individual Link Targets
Specific links can override the default target. To do so, use the target attribute within each link:
<a href="/yourlink.html" target="_blank">test-link</a>
This will open the specified link in a new window, even if the
The above is the detailed content of Can You Open Links in New Tabs Using Only CSS?. For more information, please follow other related articles on the PHP Chinese website!