Skip to main content

a11y/noTargetBlank

Prevent usage of unsafe target="_blank"

ESLint Equivalent: jsx-no-target-blank

Examples

Invalid

<a href="http://external.link" target="_blank">child</a>

 file.tsx:1:31 lint/a11y/noTargetBlank  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━

  Avoid using target="_blank" without rel="noreferrer".

    <a href="http://external.link" target="_blank">child</a>
                                   ^^^^^^^^^^^^^^^

  Opening external links in new tabs without rel="noreferrer" is a
    security risk. See 
    https://html.spec.whatwg.org/multipage/links.html#link-type-noopener
    for more details.

  Safe fix

    1  - <a·href="http://external.link"·target="_blank">
      1+ <a·href="http://external.link">
    2 2  child
    3 3  </a>


<a href={dynamicLink} target="_blank">child</a>

 file.tsx:1:22 lint/a11y/noTargetBlank  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━

  Avoid using target="_blank" without rel="noreferrer".

    <a href={dynamicLink} target="_blank">child</a>
                          ^^^^^^^^^^^^^^^

  Opening external links in new tabs without rel="noreferrer" is a
    security risk. See 
    https://html.spec.whatwg.org/multipage/links.html#link-type-noopener
    for more details.

  Safe fix

    1  - <a·href={dynamicLink}·target="_blank">
      1+ <a·href={dynamicLink}>
    2 2  child
    3 3  </a>

<a href="http://external.link" target="_blank">child</a>

 file.html:1:31 lint/a11y/noTargetBlank  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

  Avoid using target="_blank" without rel="noreferrer".

    <a href="http://external.link" target="_blank">child</a>
                                   ^^^^^^^^^^^^^^^

  Opening external links in new tabs without rel="noreferrer" is a
    security risk. See 
    https://html.spec.whatwg.org/multipage/links.html#link-type-noopener
    for more details.

  Safe fix

    1  - <a·href="http://external.link"·target="_blank">
      1+ <a·href="http://external.link">
    2 2  child
    3 3  </a>

Valid

<p href="http://external.link" target="_blank">child</p>
<a href="http://external.link" rel="noreferrer" target="_blank">child</a>
<a href="http://external.link" rel="noopener noreferrer" target="_blank">child</a>
<a href="relative/link" rel="noreferrer" target="_blank">child</a>
<a href="/absolute/link" rel="noreferrer" target="_blank">child</a>
<a href={dynamicLink} rel="noreferrer" target="_blank">child</a>
<a href="http://external.link" rel="noopener noreferrer" target="_blank">child</a>
<a href="relative/link" rel="noreferrer" target="_blank">child</a>
<a href="/absolute/link" rel="noreferrer" target="_blank">child</a>