diff --git a/src/html.c b/src/html.c
index 7836f0052..529e0ea31 100644
--- a/src/html.c
+++ b/src/html.c
@@ -68,7 +68,9 @@ static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *
cmark_strbuf_puts(html, "as.literal.data, node->as.literal.len);
- cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to reference ");
+ cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"");
+ cmark_strbuf_puts(html, m);
+ cmark_strbuf_puts(html, "\" aria-label=\"Back to reference ");
cmark_strbuf_puts(html, m);
cmark_strbuf_puts(html, "\">↩");
@@ -82,7 +84,11 @@ static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *
houdini_escape_href(html, node->as.literal.data, node->as.literal.len);
cmark_strbuf_puts(html, "-");
cmark_strbuf_puts(html, n);
- cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to reference ");
+ cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"");
+ cmark_strbuf_puts(html, m);
+ cmark_strbuf_puts(html, "-");
+ cmark_strbuf_puts(html, n);
+ cmark_strbuf_puts(html, "\" aria-label=\"Back to reference ");
cmark_strbuf_puts(html, m);
cmark_strbuf_puts(html, "-");
cmark_strbuf_puts(html, n);
diff --git a/test/extensions.txt b/test/extensions.txt
index 580242ffc..fe98fe548 100644
--- a/test/extensions.txt
+++ b/test/extensions.txt
@@ -737,7 +737,7 @@ Hi!
@@ -773,7 +773,7 @@ This footnote is referenced[^a-footnote] multiple times, in lots of different pl
@@ -790,7 +790,7 @@ Hello[^">]
diff --git a/test/regression.txt b/test/regression.txt
index 55a1c71a5..1334a674a 100644
--- a/test/regression.txt
+++ b/test/regression.txt
@@ -194,7 +194,7 @@ A footnote in a paragraph[^1]
@@ -284,10 +284,10 @@ This is some text. It has a citation.[^citation]
@@ -306,10 +306,10 @@ This is some text. It has two footnotes references, side-by-side without any spa
@@ -331,10 +331,10 @@ It has another footnote that contains many different characters (the autolinker