diff --git a/core/includes/form.inc b/core/includes/form.inc
index 1c88201..0a7356f 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -240,7 +240,7 @@ function template_preprocess_fieldset(&$variables) {
  */
 function template_preprocess_details(&$variables) {
   $element = $variables['element'];
-  $variables['attributes'] = $element['#attributes'];
+  $variables['attributes'] = isset($element['#attributes']) ? $element['#attributes'] : new Attribute();
   $variables['summary_attributes'] = new Attribute();
   if (!empty($element['#title'])) {
     $variables['summary_attributes']['role'] = 'button';
diff --git a/core/modules/system/templates/details.html.twig b/core/modules/system/templates/details.html.twig
index 1c0fd79..c23733f 100644
--- a/core/modules/system/templates/details.html.twig
+++ b/core/modules/system/templates/details.html.twig
@@ -4,7 +4,7 @@
  * Default theme implementation for a details element.
  *
  * Available variables
- * - attributes: A list of HTML attributes for the details element.
+ * - attributes: (optional) A list of HTML attributes for the details element.
  * - title: (optional) The title of the element, may not be set.
  * - description: (optional) The description of the element, may not be set.
  * - children: (optional) The children of the element, may not be set.
diff --git a/core/themes/classy/templates/form/details.html.twig b/core/themes/classy/templates/form/details.html.twig
index 9b149d7..e2dd751 100644
--- a/core/themes/classy/templates/form/details.html.twig
+++ b/core/themes/classy/templates/form/details.html.twig
@@ -4,7 +4,7 @@
  * Theme override for a details element.
  *
  * Available variables
- * - attributes: A list of HTML attributes for the details element.
+ * - attributes: (optional) A list of HTML attributes for the details element.
  * - title: (optional) The title of the element, may not be set.
  * - description: (optional) The description of the element, may not be set.
  * - children: (optional) The children of the element, may not be set.
