The target attribute is a small instruction attached to an HTML element. Its job is to where a linked resource or form result opens. It is easier to remember when you can see it in a real piece of markup.
What target is used for
Where a linked resource or form result opens. The attribute appears inside an element’s opening tag. Depending on its definition, it may take a specific string, a number, an enumerated keyword, or be a boolean attribute.
The example below uses it in a link context. Other elements may support it too, or may give the same attribute a different meaning.
Example you can try
<nav aria-label="Helpful pages">
<a href="/guide.html" target="_blank" rel="noopener">Open the guide</a>
</nav>
How the example works
Look for target in the snippet. Here the example shows the value _blank. This is a concrete input the browser can interpret; it is not just text shown to the reader.
target="_blank" creates a new browsing context; consider explaining that behavior to users.
Values and important behavior
Common values are _self, _blank, _parent, and _top; a custom name can target a named frame.
This detail matters most when the page receives user input, navigates to another document, or loads an external resource. In those cases, check the browser behavior and any server-side requirements separately.
Small practice task
Copy the code and change target to another sensible value, or remove it entirely if it is optional. Test the difference in the browser and inspect any submitted value or network request.
Common Beginner Mistakes
- target="_blank" creates a new browsing context; consider explaining that behavior to users.
- Using
targeton an element that does not support it. - Believing that an HTML hint or client-side check replaces real server validation or a security policy.
Key Takeaways
targetis used to where a linked resource or form result opens.- target="_blank" creates a new browsing context; consider explaining that behavior to users.
- Choose valid values and test the result instead of guessing what the browser will do.