diff --git a/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php b/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
index bb3031e6e90b700e1011ddb681b063ab0047f400..d70f2ce0743cb13b9f4f52b43609fde209dd1523 100644
--- a/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
+++ b/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php
@@ -181,7 +181,7 @@ public static function setLinkActiveClass($html_markup, $current_path, $is_front
 
       // Get the HTML: this will be the opening part of a single tag, e.g.:
       // <a href="/" data-drupal-link-system-path="&lt;front&gt;">
-      $tag = substr($html_markup, $pos_tag_start, $pos_tag_end - $pos_tag_start + 1);
+      $tag = substr($html_markup, $pos_tag_start ?? 0, $pos_tag_end - $pos_tag_start + 1);
 
       // Parse it into a DOMDocument so we can reliably read and modify
       // attributes.