Search code examples
githubmarkdown

How to Link to a Specific Section in Another Markdown File in Github


I have a question regarding linking to specific sections across different Markdown files within my project.

I am managing a project with multiple Markdown documents and want to create direct links from one file to another file's specific section (anchor). For example, I wish to link from document1.md to #section2 within document2.md, but the following syntax does not work as expected:

#section2 within document2.md

## <span id="ELB_concept">content</span>

document1.md

<a href="path to #section2 within document2">content</a>

When I click the link, it opens document2.md, but does not scroll to #section2. How can I resolve this issue to make it work? Any advice or solutions are highly welcome.


Solution

  • Pls use the file path and section like this: path/to/document2.md#section2

    In document1.md:

    [Link to Section 2 in document2.md](path/to/document2.md#section2)
    

    In document2.md, where you want #section2:

    ## Section 2
    This is the content of Section 2.
    

    When you click the link in document1.md, it opens and scrolls down to the related section.