diff --git a/bin/unit_tests/assets/html/eepp-ui-background-atlas-pd2.webp b/bin/unit_tests/assets/html/eepp-ui-background-atlas-pd2.webp
index 86cad9369..a34bc3f61 100644
Binary files a/bin/unit_tests/assets/html/eepp-ui-background-atlas-pd2.webp and b/bin/unit_tests/assets/html/eepp-ui-background-atlas-pd2.webp differ
diff --git a/bin/unit_tests/assets/html/eepp-ui-background-atlas.webp b/bin/unit_tests/assets/html/eepp-ui-background-atlas.webp
index 9df703067..82ae7a50c 100644
Binary files a/bin/unit_tests/assets/html/eepp-ui-background-atlas.webp and b/bin/unit_tests/assets/html/eepp-ui-background-atlas.webp differ
diff --git a/src/eepp/ui/uinodedrawable.cpp b/src/eepp/ui/uinodedrawable.cpp
index 050e71046..fc56d1963 100644
--- a/src/eepp/ui/uinodedrawable.cpp
+++ b/src/eepp/ui/uinodedrawable.cpp
@@ -710,6 +710,15 @@ Sizef UINodeDrawable::LayerDrawable::calcDrawableSize( const std::string& drawab
size = mSize;
} else {
size = mDrawable->getPixelsSize();
+ // For Html mode, mOffset (from calcPosition) is in CSS‑physical pixels
+ // (scaled by PixelDensity via convertLength -> dpToPx), but
+ // getPixelsSize() returns raw image pixels. Scale the intrinsic
+ // size so both values use the same coordinate system, otherwise
+ // the visible sprite‑atlas region drifts when PixelDensity != 1.
+ if ( mContainer->getBackgroundMode() == BackgroundMode::Html ) {
+ size = Sizef( size.x * PixelDensity::getPixelDensity(),
+ size.y * PixelDensity::getPixelDensity() );
+ }
}
} else if ( drawableSizeEq == "expand" ) {
size = mSize;
diff --git a/src/tests/unit_tests/uihtml_tests.cpp b/src/tests/unit_tests/uihtml_tests.cpp
index 03874f85e..45ee02fd3 100644
--- a/src/tests/unit_tests/uihtml_tests.cpp
+++ b/src/tests/unit_tests/uihtml_tests.cpp
@@ -1320,7 +1320,7 @@ UTEST( UIHTML, ContactFormLayout ) {
UTEST( UIBackground, imageAtlasPositioning ) {
auto win = Engine::instance()->createWindow(
- WindowSettings( 960, 256, "Background Atlas Test", WindowStyle::Default,
+ WindowSettings( 1024, 653, "Background Atlas Test", WindowStyle::Default,
WindowBackend::Default, 32, {}, 1, false, true ),
ContextSettings( false, 0, 0, GLv_default, true, false ) );
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
@@ -1365,7 +1365,7 @@ UTEST( UIBackground, imageAtlasPositioning ) {
UTEST( UIBackground, imageAtlasPositioningPixelDensity2 ) {
auto win = Engine::instance()->createWindow(
- WindowSettings( 960, 256, "Background Atlas Test PD2", WindowStyle::Default,
+ WindowSettings( 1024, 653, "Background Atlas Test PD2", WindowStyle::Default,
WindowBackend::Default, 32, {}, 1, false, true ),
ContextSettings( false, 0, 0, GLv_default, true, false ) );
EE::Graphics::PixelDensity::setPixelDensity( 2.0f );