Interview answer drill

Use this HTML interview question to rehearse a quick answer, common mistake, follow-up, and production pitfall.

What is the purpose of the target attribute in an <a> tag?Frontend interview answer

HighEasyHtml
Interview focus

This HTML interview question tests whether you can explain target _blank do in an anchor tag, connect it to production trade-offs, and handle common follow-up questions.

  • target _blank do in an anchor tag explanation without falling back to memorized docs wording
  • Anchor and Target reasoning, edge cases, and production failure modes
  • How you would answer the most likely HTML interview follow-up
Practice more HTML interview questions
Interview quick answer

The target attribute controls where a link opens. target="_blank" opens a new tab/window; target="_self" is the default. For _blank, add rel="noopener noreferrer" for security. New tabs are a UX and security trade-off, so test keyboard flow and rel attributes.

Full interview answer

Overview

The target attribute specifies where the linked page will open when a user clicks on a hyperlink. It’s part of the <a> (anchor) tag and defines the browsing context such as a new tab, a parent frame, or the current window.

Value

Description

Behavior

_self

Opens the link in the same tab or frame

Default behavior

_blank

Opens the link in a new tab or window

Most commonly used for external links

_parent

Opens in the parent frame of the current one

Used inside nested frames

_top

Opens in the full body of the current window

Breaks out of any frames

framename

Opens the link in a specific named frame

Used in pages with multiple frames

Common values of the target attribute

Example: Default Behavior (Same Tab)

HTML
<a href="https://www.example.com" target="_self">Visit Example</a>
                  

The linked page replaces the current one — this is the default even if you omit the target attribute.

Example: Opening in a New Tab

HTML
<a href="https://www.example.com" target="_blank">Open Example in New Tab</a>
                  

When target="_blank" is used, the linked page opens in a new browser tab or window.

Example: Opening in a Named Frame

HTML
<a href="about.html" target="contentFrame">Open About Page</a>
<iframe name="contentFrame" width="400" height="200"></iframe>
                  

In this example, the link opens inside the iframe with the name contentFrame.

Security Tip

  • When using target="_blank", always include rel="noopener noreferrer" to prevent security risks such as tab hijacking.
  • Example: <a href="..." target="_blank" rel="noopener noreferrer">/>

Practical scenario
Open external docs in a new tab while keeping internal links in the same tab.


Common pitfalls

  • Using target="_blank" without rel="noopener noreferrer", which is a security risk.
  • Overusing new tabs and hurting navigation flow.
  • Forgetting to announce new-tab behavior for accessibility.
Trade-off or test tip
New tabs can preserve context but reduce control for users. Test with keyboard navigation and verify rel attributes are set.

Still so complicated?

Think of target as telling the link where to go — stay here (_self), open a new tab (_blank), or load inside a specific frame (contentFrame).

Summary
  • The target attribute controls where a link opens.
  • _self is the default (same tab).
  • _blank opens a new tab or window.
  • Use rel="noopener noreferrer" with _blank for safety.
  • You can target specific frames by name.
Similar questions
Guides
Preparing for interviews?

Use this as one explanation rep, then continue with the HTML interview questions cluster or a guided prep path.