HTML - Historical or technical reason for target="_blank" with underscore?

Solution 1:

If you were to use target="blank" your link will open in a new tab/window. However, there is a subtle difference. Clicking on the link again will reuse the window that was opened the first time instead of opening a new one.

This is because the target attribute can be used for more than just opening a new window. It has four built-in values but also allows you to specify your own target. If you look at the relevant W3 Schools page it shows the following options:

  • _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 a named frame

Much of this doesn't make sense unless you understand a bit about HTML frames. Using a HTML <frameset> tag allow you to split the browser window up into individual sections (frames) each with their own page. By giving a frame a name and using the target attribute in your links it is possible to control which frame should display the relevant content.

But there are some additional rules for the target attribute that browsers must apply:

  • If the target is a user-specified name then it must begin with a letter (no underscores, numbers etc.)
  • If the target is a user-specified name but no frame/window matches that name then create a new tab/window using that name. This is why target="blank" works the way it does.

Basically there is no reason to change the current convention since _blank is a special case. The original kind of frames may not be used much any more but there are other cases where you can have named objects that the target attribute works with, e.g. iframes which are single frames embedded directly into a page. Changing the standard would break many existing pages without giving any benefit.