With 2 headings of same name in file can only link to first one

What I’m trying to do

I am trying to link to a H1 heading from in the same document as that heading is in. I have another H3 heading of the same name as the H1 heading, which is above the H1 heading in the file. I cannot create a link to the H1 heading.

Is there any way to do this without renaming one of the headings?

Things I have tried

[[#headingName]]

Specifying the file

[[file#headingName]]

Honestly not sure what else to try.

Reproducible by

Having two headings of the same name in a document (can be different levels, e.g. H1, H3), attempting to link to the bottom one.

Keywords

identical headers
header links
headers same name

Depending on what side of the line you fall on, “according to the HTML5.1 spec, as outlined in the link below, every page should only have one h1 element”, “it’s best practice to use only one h1 element in a document”, or “it’s fine to use multiple h1s now”.

You can, of course, do whatever you’d like in your notes, but linking to a h1 that is below a h3 with the same name doesn’t seem that common.

https://html.spec.whatwg.org/multipage/sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements

These elements have a heading level given by the number in their name. The heading level corresponds to the levels of nested sections. The h1 element is for a top-level section, h2 for a subsection, h3 for a sub-subsection, and so on.

This link is a good read → The Truth About Multiple H1 Tags in the HTML5 Era | Envato Tuts+


You can link to subheadings using [[My note#Heading 1#Heading 2]], but if you want to keep the structure you have now, I would consider linking to blocks instead.

1 Like

Here is some explaining on the block link approach as suggested by @ariehen , as you could add a block link to either heading, preferably the one you can’t link to, allowing it to be linked by that link instead of the heading link. Note however that this do require a little more typing, and you can’t use it for embedding as it is a pure link to that block (aka the heading).

An example:

### A heading

First appearnce as H3

## A heading ^h2

Second appearance as H2

# A heading ^h1
Third appearance as H1

## Somewhere else

[[#^h1|A heading]]

The link at the bottom will send you to the current file’s block id of ^h1, which preferably could be something more readable I guess… :slightly_smiling_face:


On a slightly related note… You’re allowed to stack the heading links using # to get to a header lower down, but you can’t use the same technique to select a more specific header in the autocomplete. Check out this example:

## a

### b

text b

## a

### c

text c

## test area

Autocomplete available for this one: ![[#a#b]]

No autocomplete for this one: ![[#a#c]]

These embeds (and thusly links) will properly connect to their correct nested heading.


Using this knowledge and a header structure such as:

  • heading a
    -heading b
    • heading c
  • heading c
    • heading a

You could then use a higher heading to specify the one you actually want, like in [[#heading c#heading a]] to get to the last appearance of “heading a”. You can’t use auto complete to find that though… And it does require for a somewhat proper heading structure in your document.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.