 core/modules/filter/css/filter.caption.css              |   15 +++++++++++++++
 .../lib/Drupal/filter/Plugin/Filter/FilterCaption.php   |   14 +++++++++-----
 .../filter/lib/Drupal/filter/Tests/FilterUnitTest.php   |    6 +++---
 core/modules/filter/templates/filter-caption.html.twig  |    6 ++----
 4 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/core/modules/filter/css/filter.caption.css b/core/modules/filter/css/filter.caption.css
index 0b3d8e5..4793e67 100644
--- a/core/modules/filter/css/filter.caption.css
+++ b/core/modules/filter/css/filter.caption.css
@@ -56,3 +56,18 @@
   margin-right: auto;
   text-align: center;
 }
+
+/**
+ * Image alignment (when not using a caption).
+ */
+img[data-align="left"] {
+  float: left;
+}
+img[data-align="right"] {
+  float: right;
+}
+img[data-align="center"] {
+  display: block;
+  margin-left: auto;
+  margin-right: auto;
+}
diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterCaption.php b/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterCaption.php
index c19d0be..0311ed4 100644
--- a/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterCaption.php
+++ b/core/modules/filter/lib/Drupal/filter/Plugin/Filter/FilterCaption.php
@@ -39,30 +39,34 @@ public function process($text, $langcode, $cache, $cache_id) {
         // Retrieve, then remove the data-caption and data-align attributes.
         if ($node->hasAttribute('data-caption')) {
           $caption = String::checkPlain($node->getAttribute('data-caption'));
-          $node->removeAttribute('data-caption');
           // Sanitize caption: decode HTML encoding, limit allowed HTML tags.
           $caption = String::decodeEntities($caption);
           $caption = Xss::filter($caption);
           // The caption must be non-empty.
           if (Unicode::strlen($caption) === 0) {
+            $node->removeAttribute('data-caption');
             $caption = NULL;
           }
         }
         if ($node->hasAttribute('data-align')) {
           $align = $node->getAttribute('data-align');
-          $node->removeAttribute('data-align');
           // Only allow 3 values: 'left', 'center' and 'right'.
           if (!in_array($align, array('left', 'center', 'right'))) {
             $align = NULL;
+            $node->removeAttribute('data-align');
           }
         }
 
-        // If neither attribute has a value after validation, then don't
-        // transform the HTML.
-        if ($caption === NULL && $align === NULL) {
+        // Don't transform the HTML if there isn't a caption after validation.
+        if ($caption === NULL) {
           continue;
         }
 
+        // We're going to caption this node, therefor we don't need the data-
+        // attributes anymore.
+        $node->removeAttribute('data-caption');
+        $node->removeAttribute('data-align');
+
         // Given the updated node, caption and alignment: re-render it with a
         // caption.
         $filter_caption = array(
diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterUnitTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterUnitTest.php
index 64b9722..1345c3d 100644
--- a/core/modules/filter/lib/Drupal/filter/Tests/FilterUnitTest.php
+++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterUnitTest.php
@@ -93,13 +93,13 @@ function testCaptionFilter() {
 
     // Only data-align attribute: all 3 allowed values.
     $input = '<img src="llama.jpg" data-align="left" />';
-    $expected = '<figure class="caption caption-img caption-left"><img src="llama.jpg" /></figure>';
+    $expected = $input;
     $this->assertIdentical($expected, $test($input));
     $input = '<img src="llama.jpg" data-align="center" />';
-    $expected = '<figure class="caption caption-img caption-center"><img src="llama.jpg" /></figure>';
+    $expected = $input;
     $this->assertIdentical($expected, $test($input));
     $input = '<img src="llama.jpg" data-align="right" />';
-    $expected = '<figure class="caption caption-img caption-right"><img src="llama.jpg" /></figure>';
+    $expected = $input;
     $this->assertIdentical($expected, $test($input));
 
     // Only data-align attribute: a disallowed value.
diff --git a/core/modules/filter/templates/filter-caption.html.twig b/core/modules/filter/templates/filter-caption.html.twig
index 532fb37..2f9d331 100644
--- a/core/modules/filter/templates/filter-caption.html.twig
+++ b/core/modules/filter/templates/filter-caption.html.twig
@@ -5,14 +5,12 @@
  * Available variables
  * - string node: The complete HTML tag whose contents are being captioned.
  * - string tag: The name of the HTML tag whose contents are being captioned.
- * - string|NULL caption: (optional) The caption text, or NULL.
+ * - string caption: The caption text.
  * - string|NULL align: (optional) The alignment: 'left', 'center', 'right' or
  *   NULL.
  */
 #}
 <figure class="caption caption-{{ tag }} {%- if align %} caption-{{ align }} {%- endif %}">
 {{ node }}
-{% if caption %}
-  <figcaption>{{ caption }}</figcaption>
-{% endif %}
+<figcaption>{{ caption }}</figcaption>
 </figure>
