diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module
index 85a2ff94dd..e7b7a65bf6 100644
--- a/core/modules/responsive_image/responsive_image.module
+++ b/core/modules/responsive_image/responsive_image.module
@@ -223,6 +223,12 @@ function template_preprocess_responsive_image(&$variables) {
$variables['img_element']['#title'] = $variables['attributes']['title'];
unset($variables['attributes']['title']);
}
+ if (isset($variables['img_element']['#width'])) {
+ $variables['attributes']['width'] = $variables['img_element']['#width'];
+ }
+ if (isset($variables['img_element']['#height'])) {
+ $variables['attributes']['height'] = $variables['img_element']['#height'];
+ }
$variables['img_element']['#attributes'] = $variables['attributes'];
}
}
diff --git a/core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php
index f1d23267e5..c43da54a83 100644
--- a/core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php
+++ b/core/modules/responsive_image/tests/src/Functional/ResponsiveImageFieldDisplayTest.php
@@ -494,7 +494,7 @@ public function testResponsiveImageFieldFormattersMultipleSources(): void {
$image_uri = File::load($node->{$field_name}->target_id)->getFileUri();
$medium_transform_url = $this->fileUrlGenerator->transformRelative($medium_style->buildUrl($image_uri));
$large_transform_url = $this->fileUrlGenerator->transformRelative($large_style->buildUrl($image_uri));
- $this->assertSession()->responseMatches('//');
+ $this->assertSession()->responseMatches('//');
$this->responsiveImgStyle
// Test the output of an empty media query.
@@ -506,7 +506,7 @@ public function testResponsiveImageFieldFormattersMultipleSources(): void {
// Assert the picture tag has source tags that include dimensions.
$this->drupalGet('node/' . $nid);
- $this->assertSession()->responseMatches('/