Skip to content

Instantly share code, notes, and snippets.

@borekb
Last active February 26, 2025 20:16
Show Gist options
  • Save borekb/f83e48479aceaafa43108e021600f7e3 to your computer and use it in GitHub Desktop.
Save borekb/f83e48479aceaafa43108e021600f7e3 to your computer and use it in GitHub Desktop.
How to link to headings in GitHub issues and pull requests

How to link to headings in GitHub issues and pull requests

If you have an issue comment / PR description on GitHub, it doesn't automatically get anchors / IDs that you could link to:

Screenshot 2019-07-11 at 13

What I like to do is to add a visible # character like this:

Screenshot 2019-07-11 at 13 42 21

It renders like this:

Screenshot 2019-07-11 at 13 32 03

Copy/paste-friendly Markdown snippet:

# Some heading <a href="#user-content-some-heading" id="some-heading">#</a>

Don't forget to add the user-content- prefix to href – that's how GitHub transforms custom IDs.


Alternatively, if you don't want the visible # character, you could also do this:

Screenshot 2019-07-11 at 13 45 29

It renders like this:

Screenshot 2019-07-11 at 13 46 32

The same URL as before can be used to link to this heading, e.g.:

https://github.com/borekb/example/issues/123#user-content-second-section

(You can use browser dev tools' Inspect element to find out the anchor.)

@Whoeza
Copy link

Whoeza commented Jan 31, 2023

Kudos!

@chazkiker2
Copy link

This is the best thing I've ever come across! Thanks, all! 🚀

@mbcann01
Copy link

Thank you!

@guettli
Copy link

guettli commented Aug 2, 2024

Why is that needed at all? For many markdown to html converters this works out of the box (just use # Foo and then ...#foo works fine).

@pjmartorell
Copy link

pjmartorell commented Dec 21, 2024

In this StackOverflow answer is stated that the best (or most browser-compatible) approach is using name instead of id:

  • Take me to [Header1](#pookiie)
  • ### <a name="pookie"></a>Header1

Reasoning (from this answer):

Use a name. Using an id isn't necessary in HTML 5 and will create global variables in your JavaScript

See the HTML 5 specification, 5.9.8 Navigating to a fragment identifier - both id and name are used.

It's important to know that most browsers still turn IDs into global variables. Here's a quick test. Using a name avoids creating globals and any conflicts that may result.

Example using a name:

Take me to [pookie](#pookie)

And the destination anchor:

### <a name="pookie"></a>Some heading

@andyfeller
Copy link

In this StackOverflow answer is stated that the best (or most browser-compatible) approach is using name instead of id:

  • Take me to [Header1](#pookiie)
  • ### <a name="pookie"></a>Header1

Reasoning (from this answer):

Use a name. Using an id isn't necessary in HTML 5 and will create global variables in your JavaScript
See the HTML 5 specification, 5.9.8 Navigating to a fragment identifier - both id and name are used.
It's important to know that most browsers still turn IDs into global variables. Here's a quick test. Using a name avoids creating globals and any conflicts that may result.
Example using a name:

Take me to [pookie](#pookie)

And the destination anchor:

### <a name="pookie"></a>Some heading

@pjmartorell : That's interesting, however I'm unsure that is really a concern within GitHub issue versus building your own website. $0.02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment