Search code examples
markdown

How do you create a link to a specified section of your readme.md file?


I am practicing readme files and I had a question about linking. Is there a way to link to a specific section of a readme? For example, I want to create a table of contents with links to the specific sections of my readme.md file.

# Title
## Sub Title
Brief description of project.

### Table of Content
* [Section 1](#section1)
* [Section 2](#section2)
* [Section 3](#section3)

# Section 1
some text

# Section 2
some text

# Section 3
some text

From my understanding I thought this would work but the links do not bring me to the sections, when I click them it does nothing.


Solution

  • You add an anchor to the section i.e

    #<a name="section-1"></a> Section 1
    

    then link it using

    [Section 1](#section-1)