This exercise uses the `_blank` value to open pages in new tabs. Does the `target` attribute have other values?



This exercise uses the _blank value to open pages in new tabs. Does the target attribute have other values?


Yes, there are 4 different values the target attribute can have: _self, _blank, _parent, or _top. These values specify a browsing context or the environment in which the browser will display a document. To learn about each of these values, check out Mozilla docs!

FAQ: Learn HTML Elements - Common HTML Elements - Opening Links in a New Window

Is it mandatory that the target attribute be written after the href attribute or it doesn’t matter, it functions the same either way?


I’m pretty sure that you don’t have to include the target attribute, it’s just good practice to make determinations about how the browser will open a link you insert. If you don’t specify it, I’m sure browsers have some kind of default link-opening behavior.


It is not mandatory, but like the article stated that you may want the person to come back to your page. Without the target attribute the link will open the new page in your same tab. If the person closes the tab they also close your page. Opening it in a new tab will make sure they come back to your page after they close out the other tab.


What happens when you change the value of the attribute to _self, _parent, or _top? Tried it out in the index.html doc for brown bears but wasn’t able to see a visible difference.


This is a late reply, but to clarify, the only target attribute value that has any effect in a single browser window is _blank, which refers to a new tab or window. These are legacy attributes that apply to frameset, a very uncommon thing in today’s era now that we have CSS. Frames predated CSS.

Also of note, attributes have no order. They can be written in any order, though usually we like to see the id and class attributes out front, and in that order. That’s just for reading, though. The browser makes no distinction of ordering or attributes.