Skip to content

Instantly share code, notes, and snippets.

@borekb
Last active May 21, 2024 21:41
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.)

@rickstaa
Copy link

rickstaa commented Oct 13, 2022

For future reference, the # text doesn't need to be there.

- [A title](#a-title)

## A title <a href="#a-title" id="a-title"/>

Worked for me.

@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!

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