OneCompiler

Unable to open link in new tab HTML

I have an a tag in my code, when the user clicks it, I want to open it in a new tab. But it is opening in the same tab. How can I achieve that?

My code:

<a href="https://google.com">Open Google</a>

1 Answer

5 years ago by

By default, a tag opens new links on the same tab. To override that we need target attribute.

<a href="https://google.com" target="_blank" rel="noreferrer noopener">
   Click me
</a>
5 years ago by Divya