Skip to content

Instantly share code, notes, and snippets.

@borekb
Last active April 2, 2024 19:56
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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.)

@telamonian
Copy link

Just tried this, doesn't seem to work. Do you have a fully functioning live example?

@borekb
Copy link
Author

borekb commented Apr 22, 2020

@telamonian
Copy link

thanks @borekb! Your live examples do seem to be working for me. Hmm, wonder what I was doing wrong before

@sanjivsahayamrea
Copy link

Thanks for documenting this! :)

@cjsjyh
Copy link

cjsjyh commented May 11, 2021

to new comers that encounter issues,

# Some heading <a href="#user-content-some-heading" id="some-heading">#</a>
  1. Make sure you add #user-content- to href as @borekb.
  2. Make sure id matches the remaining href, in this case some-heading

Otherwise, it won't work

@pjmartorell
Copy link

pjmartorell commented Jul 1, 2021

@cjsjyh I tried it and it's working without prefixing the anchor with #user-content-

@jrencz
Copy link

jrencz commented Jul 29, 2022

For the record - something changed in he way GH renders and now it does now work without user-content prefix being added manually, yet the id is still being prefixed

btw @borekb - thanks for this gist

@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