diff --git a/core/includes/form.inc b/core/includes/form.inc
index cc4bcdb..79e425f 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -2914,6 +2914,11 @@ function template_preprocess_form_element(&$variables) {
   if (!isset($element['#title'])) {
     $element['#title_display'] = 'none';
   }
+  // If #title_dislay is not some of the visible options, add a CSS class.
+  if ($element['#title_display'] != 'before' && $element['#title_display'] != 'after') {
+    $variables['attributes']['class'][] = 'form-no-label';
+  }
+
   $variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL;
   $variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL;
 
diff --git a/core/modules/system/src/Tests/Form/ElementsLabelsTest.php b/core/modules/system/src/Tests/Form/ElementsLabelsTest.php
index b002635..12b7d00 100644
--- a/core/modules/system/src/Tests/Form/ElementsLabelsTest.php
+++ b/core/modules/system/src/Tests/Form/ElementsLabelsTest.php
@@ -77,6 +77,9 @@ function testFormLabels() {
     $elements = $this->xpath('//label[@for="edit-form-textfield-test-title-no-show"]');
     $this->assertFalse(isset($elements[0]), 'No label tag when title set not to display.');
 
+    $elements = $this->xpath('//div[contains(@class, "form-item-form-textfield-test-title-invisible") and contains(@class, "form-no-label")]');
+    $this->assertTrue(isset($elements[0]), 'Field class is form-no-label when there is no label.');
+
     // Check #field_prefix and #field_suffix placement.
     $elements = $this->xpath('//span[@class="field-prefix"]/following-sibling::div[@id="edit-form-radios-test"]');
     $this->assertTrue(isset($elements[0]), 'Properly placed the #field_prefix element after the label and before the field.');
