What
The target attribute in HTML allows you to specify where a linked document will open when clicked on. This gives you more control over the user experience and can be used for various purposes.
The basic options are:
- _blank Opens the linked document in a new window or tab
- _self Opens the linked document in the same frame as it was clicked (this is default)
- _parent Opens the linked document in the parent frame
- _top Opens the linked document in the full body of the window
- framename Opens the linked document in the named iframe
Why
- Screen readers get a better understanding of what will happen if they use the link. Will the link open in this window or go to another window or tab.
- Improved user experience: Defining link targets can prevent users from losing their place on the current page if they click on an external link.
- Enhanced navigation: You can guide users to specific locations within your website or platform depending on their needs.
How
An example of the how the code would work. In this example _blank the link will open in another window.
Here is a link from this website to another website called MindfulVision
<a href="https://mindfulvision.org" rel="noopener noreferrer" target="_blank" title="link to mindful visions website opening in another window">MindfulVision</a>
The target attribute is after the href declaration