diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index e38e8ddce9..5b6ba2dfbb 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -1534,3 +1534,15 @@ function system_element_info_alter(&$type) {
     $type['page']['#theme_wrappers']['off_canvas_page_wrapper'] = ['#weight' => -1000];
   }
 }
+
+/**
+ * Implements hook_link_alter().
+ */
+function system_link_alter(&$variables) {
+  // If a dialog type is provided add 'use-ajax' class.
+  if (!empty($variables['options']['attributes']['data-dialog-type'])) {
+    if (!isset($variables['options']['attributes']['class']) || array_search('use-ajax', $variables['options']['attributes']['class']) === FALSE) {
+      $variables['options']['attributes']['class'][] = 'use-ajax';
+    }
+  }
+}
diff --git a/core/modules/system/tests/modules/dialog_renderer_test/src/Controller/TestController.php b/core/modules/system/tests/modules/dialog_renderer_test/src/Controller/TestController.php
index 853c620dc2..31a9b8e480 100644
--- a/core/modules/system/tests/modules/dialog_renderer_test/src/Controller/TestController.php
+++ b/core/modules/system/tests/modules/dialog_renderer_test/src/Controller/TestController.php
@@ -44,6 +44,19 @@ public function linksDisplay() {
           ],
         ],
       ],
+      'normal_modal_class_added' => [
+        '#title' => 'Normal Modal Class Added!',
+        '#type' => 'link',
+        '#url' => Url::fromRoute('dialog_renderer_test.modal_content'),
+        '#attributes' => [
+          'data-dialog-type' => 'modal',
+        ],
+        '#attached' => [
+          'library' => [
+            'core/drupal.ajax',
+          ],
+        ],
+      ],
       'wide_modal' => [
         '#title' => 'Wide Modal!',
         '#type' => 'link',
diff --git a/core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php b/core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php
index 7c0aec022c..23e6dbb5ec 100644
--- a/core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php
+++ b/core/modules/system/tests/src/FunctionalJavascript/ModalRendererTest.php
@@ -28,6 +28,12 @@ public function testModalRenderer() {
     $this->assertNotContains('700px', $style);
     $this->assertNotContains('1000px', $style);
     $this->drupalGet('/dialog_renderer-test-links');
+    $this->clickLink('Normal Modal Class Added!');
+    // Neither of the wide modals should have been used.
+    $style = $session_assert->waitForElementVisible('css', '.ui-dialog')->getAttribute('style');
+    $this->assertNotContains('700px', $style);
+    $this->assertNotContains('1000px', $style);
+    $this->drupalGet('/dialog_renderer-test-links');
     $this->clickLink('Wide Modal!');
     $this->assertNotEmpty($session_assert->waitForElementVisible('css', '.ui-dialog[style*="width: 700px;"]'));
     $this->drupalGet('/dialog_renderer-test-links');
