diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 65349a3..2aae025 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1927,21 +1927,18 @@ function theme_indentation($variables) {
   return $output;
 }
 
+
 /**
- * Returns HTML to wrap child elements in a container.
+ * Prepares variables for container templates.
  *
- * Used for grouped form items. Can also be used as a #theme_wrapper for any
- * renderable element, to surround it with a <div> and add attributes such as
- * classes or an HTML id.
+ * Default template: container.html.twig.
  *
- * @param $variables
+ * @param array $variables
  *   An associative array containing:
  *   - element: An associative array containing the properties of the element.
  *     Properties used: #id, #attributes, #children.
- *
- * @ingroup themeable
  */
-function theme_container($variables) {
+function template_preprocess_container(&$variables) {
   $element = $variables['element'];
   // Ensure #attributes is set.
   $element += array('#attributes' => array());
@@ -1956,7 +1953,8 @@ function theme_container($variables) {
     $element['#attributes']['class'][] = 'form-wrapper';
   }
 
-  return '<div' . new Attribute($element['#attributes']) . '>' . $element['#children'] . '</div>';
+  $variables['children'] = $element['#children'];
+  $variables['attributes'] = $element['#attributes'];
 }
 
 /**
@@ -2749,6 +2747,7 @@ function drupal_common_theme() {
     ),
     'container' => array(
       'render element' => 'element',
+      'template' => 'container',
     ),
   );
 }
diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/RenderElementTypesTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/RenderElementTypesTest.php
index 9ba4bf4..a618409 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Common/RenderElementTypesTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/RenderElementTypesTest.php
@@ -50,7 +50,7 @@ function testContainer() {
           '#type' => 'container',
           '#markup' => 'foo',
         ),
-        'expected' => '<div>foo</div>',
+        'expected' => '<div>foo</div>' . "\n",
       ),
       // Container with a class.
       array(
@@ -62,7 +62,7 @@ function testContainer() {
             'class' => 'bar',
           ),
         ),
-        'expected' => '<div class="bar">foo</div>',
+        'expected' => '<div class="bar">foo</div>' . "\n",
       ),
       // Container with children.
       array(
@@ -73,7 +73,7 @@ function testContainer() {
             '#markup' => 'foo',
           ),
         ),
-        'expected' => '<div>foo</div>',
+        'expected' => '<div>foo</div>' . "\n",
       ),
     );
 
diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php
index 12d02b0..672b0b0 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php
@@ -90,7 +90,7 @@ function testDrupalRenderBasics() {
           '#theme_wrappers' => array('container'),
           '#attributes' => array('class' => 'baz'),
         ),
-        'expected' => '<div class="baz">foobar</div>',
+        'expected' => '<div class="baz">foobar</div>' . "\n",
       ),
       // Test that #theme_wrappers can disambiguate element attributes shared
       // with rendering methods that build #children by using the alternate
@@ -108,7 +108,7 @@ function testDrupalRenderBasics() {
           '#href' => 'http://drupal.org',
           '#title' => 'bar',
         ),
-        'expected' => '<div class="baz"><a href="http://drupal.org" id="foo">bar</a></div>',
+        'expected' => '<div class="baz"><a href="http://drupal.org" id="foo">bar</a></div>' . "\n",
       ),
       // Test that #theme_wrappers can disambiguate element attributes when the
       // "base" attribute is not set for #theme.
@@ -124,7 +124,7 @@ function testDrupalRenderBasics() {
             ),
           ),
         ),
-        'expected' => '<div class="baz"><a href="http://drupal.org">foo</a></div>',
+        'expected' => '<div class="baz"><a href="http://drupal.org">foo</a></div>' . "\n",
       ),
       // Two 'container' #theme_wrappers, one using the "base" attributes and
       // one using an override.
@@ -139,7 +139,7 @@ function testDrupalRenderBasics() {
             'container',
           ),
         ),
-        'expected' => '<div class="foo"><div class="bar"></div></div>',
+        'expected' => '<div class="foo"><div class="bar"></div>' . "\n" . '</div>' . "\n",
       ),
       // Array syntax theme hook suggestion in #theme_wrappers.
       array(
@@ -148,7 +148,7 @@ function testDrupalRenderBasics() {
           '#theme_wrappers' => array(array('container')),
           '#attributes' => array('class' => 'foo'),
         ),
-        'expected' => '<div class="foo"></div>',
+        'expected' => '<div class="foo"></div>' . "\n",
       ),
 
       // Test handling of #markup as a fallback for #theme hooks.
diff --git a/core/modules/system/templates/container.html.twig b/core/modules/system/templates/container.html.twig
new file mode 100644
index 0000000..933a201
--- /dev/null
+++ b/core/modules/system/templates/container.html.twig
@@ -0,0 +1,15 @@
+{#
+/**
+ * @file
+ * Default theme implementation of a container used to wrap child elements.
+ *
+ * Available variables:
+ * - attributes: HTML attributes for the containing element.
+ * - children: The rendered child elements of the container.
+ *
+ * @see template_preprocess_container()
+ *
+ * @ingroup themeable
+ */
+#}
+<div{{ attributes }}>{{ children }}</div>
