# Bad value “” for attribute “target” on element “a”: Browsing context name must be at least one character long.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-for-attribute-target-on-element-a-browsing-context-name-must-be-at-least-one-character-long
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `target` attribute specifies where a linked document should be opened. When the validator encounters `target=""`, it reports an error because the HTML specification requires browsing context names to be at least one character long. An empty string is not a valid browsing context name and has no defined behavior, which means browsers may handle it inconsistently.

This issue commonly arises when a `target` value is dynamically generated by a CMS, template engine, or JavaScript and the value ends up being empty. It can also happen when a developer adds the attribute with the intent to fill it in later but forgets to do so.

Setting `target` to an empty string is problematic for several reasons:

- **Standards compliance:** The WHATWG HTML specification explicitly requires valid browsing context names to be non-empty strings. An empty value violates this rule.
- **Unpredictable behavior:** Browsers may interpret an empty `target` differently — some may treat it like `_self`, others may behave unexpectedly. This makes your site harder to test and maintain.
- **Accessibility concerns:** Screen readers and assistive technologies may announce the `target` attribute or use it to inform users about link behavior. An empty value provides no meaningful information.

To fix this, choose one of the following approaches:

1. **Remove the attribute** if you want the default behavior (opening in the same browsing context, equivalent to `_self`).
2. **Set a valid keyword** like `_blank`, `_self`, `_parent`, or `_top`.
3. **Set a custom name** if you want multiple links to share the same browsing context (e.g., `target="externalWindow"`).

## Examples

### ❌ Invalid: empty `target` attribute

```html
<a href="https://example.com" target="">Visit Example</a>
```

This triggers the validation error because the `target` value is an empty string.

### ✅ Fixed: remove `target` entirely

If you want the link to open in the current browsing context (the default), simply remove the attribute:

```html
<a href="https://example.com">Visit Example</a>
```

### ✅ Fixed: use `_blank` to open in a new tab

```html
<a href="https://example.com" target="_blank" rel="noopener">Visit Example</a>
```

Note the addition of `rel="noopener"` — this is a security best practice when using `target="_blank"`, as it prevents the opened page from accessing the `window.opener` property.

### ✅ Fixed: use `_self` explicitly

If you want to be explicit about opening in the same context:

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

### ✅ Fixed: use a custom browsing context name

You can use a custom name so that multiple links reuse the same tab or window:

```html
<a href="https://example.com" target="externalWindow">Example</a>
<a href="https://example.org" target="externalWindow">Example Org</a>
```

Both links will open in the same browsing context named `externalWindow`. If it doesn't exist yet, the browser creates it; subsequent clicks reuse it.

### Dynamic templates

If your `target` value comes from a template or CMS, make sure the attribute is conditionally rendered rather than output with an empty value. For example, in a templating language:

```html
<!-- Instead of always outputting target -->
<a href="https://example.com" target="">Visit</a>

<!-- Only include target when a value exists -->
<a href="https://example.com" target="_blank" rel="noopener">Visit</a>
```

In your template logic, conditionally omit the `target` attribute entirely when no value is provided, rather than rendering it as an empty string.
