You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

咨询HTML锚标签target属性合法取值的W3C官方参考页面

HTML target Attribute: Valid Values & Official Specs

Great question—this is a common point of confusion when working with link targeting in HTML! Let’s break this down clearly:

W3C-Defined Valid Values (Official Spec)

The official HTML specification from W3C only recognizes two categories of valid target values:

  • Special keyword values (these start with an underscore):
    • _self: Opens the link in the same browsing context (window/tab) as the current one (default behavior)
    • _blank: Opens the link in a new, unnamed browsing context
    • _parent: Opens the link in the parent browsing context of the current one (useful if working with frames)
    • _top: Opens the link in the top-level browsing context (breaks out of all frames)
  • Custom browsing context names: Any string that doesn’t start with an underscore. This lets you target a specific named window/tab—if the named context doesn’t exist, the browser creates it; if it does exist, the link loads into that existing context.

What About new window/new page?

Values like target="new window" or target="new page" aren’t defined in the W3C spec—but most modern browsers will still process them. Here’s why:
Browsers treat these as custom browsing context names (since they don’t start with an underscore). So when you use target="new window", the browser creates a window named new window (yes, spaces are allowed in custom names, though not recommended). If you use the same value again later, it’ll reuse that existing window instead of opening a new one.

The catch? These aren’t part of the official standard. There’s no W3C reference page that documents them as valid values because they’re not spec-compliant—they’re just a browser-compatible quirk.

Why You Should Stick to Spec-Compliant Values

While non-standard values might work today, they come with risks:

  • Browser behavior could change in future updates (since they’re not required to support these)
  • Custom names with spaces can cause unexpected issues in older browsers
  • They’re less readable for other developers, who might expect standard values or clear custom names

If you want a new window every time, use _blank. If you want to reuse a specific window, pick a clear, space-free custom name like product-details-window.

内容的提问来源于stack exchange,提问作者vr3w3c9

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:33:03