diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js
index 09b0a5eb9a565785fb7a8f95f93071a9502d9f48..c5846068b0737334b46549db28529c5570238ac0 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js
+++ b/app/assets/javascripts/lib/utils/common_utils.js
@@ -110,7 +110,7 @@
 
       // scroll to user-generated markdown anchor if we cannot find a match
       if (document.getElementById(hash) === null) {
-        var target = document.getElementById('user-content_' + hash);
+        var target = document.getElementById('user-content-' + hash);
         if (target && target.scrollIntoView) {
           target.scrollIntoView(true);
           window.scrollBy(0, adjustment);
diff --git a/features/steps/shared/markdown.rb b/features/steps/shared/markdown.rb
index d355913a7ce80a5b70c631afb5f963bede3df9fe..a036d9b884fbe685cf13ebac10860c04c4c30539 100644
--- a/features/steps/shared/markdown.rb
+++ b/features/steps/shared/markdown.rb
@@ -2,7 +2,7 @@ module SharedMarkdown
   include Spinach::DSL
 
   def header_should_have_correct_id_and_link(level, text, id, parent = ".wiki")
-    node = find("#{parent} h#{level} a#user-content_#{id}")
+    node = find("#{parent} h#{level} a#user-content-#{id}")
     expect(node[:href]).to eq "##{id}"
 
     # Work around a weird Capybara behavior where calling `parent` on a node
diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb
index 8066995372337e25b3bf20a2296045c5a3883570..8e7084f2543649e9bf7a6e737f068afbeeb23510 100644
--- a/lib/banzai/filter/table_of_contents_filter.rb
+++ b/lib/banzai/filter/table_of_contents_filter.rb
@@ -36,7 +36,7 @@ module Banzai
 
           if header_content = node.children.first
             # namespace detection will be automatically handled via javascript (see issue #22781)
-            namespace = "user-content_"
+            namespace = "user-content-"
             href = "#{id}#{uniq}"
             push_toc(href, text)
             header_content.add_previous_sibling(anchor_tag("#{namespace}#{href}", href))
diff --git a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
index e551a7d0ca5971464e00626a2209d0f1228c388c..70b31f3a880496b17378009f280f84a907998b3b 100644
--- a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
+++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb
@@ -22,7 +22,7 @@ describe Banzai::Filter::TableOfContentsFilter, lib: true do
       html = header(i, "Header #{i}")
       doc = filter(html)
 
-      expect(doc.css("h#{i} a").first.attr('id')).to eq "user-content_header-#{i}"
+      expect(doc.css("h#{i} a").first.attr('id')).to eq "user-content-header-#{i}"
     end
   end
 
@@ -34,7 +34,7 @@ describe Banzai::Filter::TableOfContentsFilter, lib: true do
 
     it 'has a namespaced id' do
       doc = filter(header(1, 'Header'))
-      expect(doc.css('h1 a').first.attr('id')).to eq 'user-content_header'
+      expect(doc.css('h1 a').first.attr('id')).to eq 'user-content-header'
     end
 
     it 'links to the non-namespaced id' do
@@ -67,7 +67,7 @@ describe Banzai::Filter::TableOfContentsFilter, lib: true do
 
       it 'supports Unicode' do
         doc = filter(header(1, '한글'))
-        expect(doc.css('h1 a').first.attr('id')).to eq 'user-content_한글'
+        expect(doc.css('h1 a').first.attr('id')).to eq 'user-content-한글'
         expect(doc.css('h1 a').first.attr('href')).to eq '#한글'
       end
     end
diff --git a/spec/support/matchers/markdown_matchers.rb b/spec/support/matchers/markdown_matchers.rb
index a44bd2601c1ac38486b4d85dc433cc16cdc5bf0e..97b8b342eb22a46bed8383a62213a8880c6269f1 100644
--- a/spec/support/matchers/markdown_matchers.rb
+++ b/spec/support/matchers/markdown_matchers.rb
@@ -38,9 +38,9 @@ module MarkdownMatchers
     set_default_markdown_messages
 
     match do |actual|
-      expect(actual).to have_selector('h1 a#user-content_gitlab-markdown')
-      expect(actual).to have_selector('h2 a#user-content_markdown')
-      expect(actual).to have_selector('h3 a#user-content_autolinkfilter')
+      expect(actual).to have_selector('h1 a#user-content-gitlab-markdown')
+      expect(actual).to have_selector('h2 a#user-content-markdown')
+      expect(actual).to have_selector('h3 a#user-content-autolinkfilter')
     end
   end