diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp
index fc50a6afe..3a08e9bce 100644
--- a/src/Magnum/Platform/EmscriptenApplication.cpp
+++ b/src/Magnum/Platform/EmscriptenApplication.cpp
@@ -402,7 +402,13 @@ void EmscriptenApplication::setWindowTitle(const std::string& title) {
void EmscriptenApplication::setContainerCssClass(const std::string& cssClass) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
- EM_ASM_({document.getElementById('container').className = AsciiToString($0);}, cssClass.data());
+ EM_ASM_({
+ /* Handle also the classic #container for backwards compatibility. We
+ also need to preserve the mn-container otherwise next time we'd have
+ no way to look for it anymore. */
+ (Module['canvas'].closest('.mn-container') ||
+ document.getElementById('container')).className = (['mn-container', AsciiToString($0)]).join(' ');
+ }, cssClass.data());
#pragma GCC diagnostic pop
/* Trigger a potential viewport event -- we don't poll the canvas size like
diff --git a/src/Magnum/Platform/EmscriptenApplication.h b/src/Magnum/Platform/EmscriptenApplication.h
index 6df665714..1216d686e 100644
--- a/src/Magnum/Platform/EmscriptenApplication.h
+++ b/src/Magnum/Platform/EmscriptenApplication.h
@@ -517,12 +517,21 @@ class EmscriptenApplication {
/**
* @brief Set container CSS class
*
- * Assigns given CSS class to the @cb{.html}
@ce.
- * Useful for example to change aspect ratio of the view or stretch it
- * to cover the full page. See @ref platforms-html5-layout for more
- * information about possible values. Note that this replaces any
- * existing class, to set multiple classes separate them with
- * whitespace.
+ * Assigns given CSS class to the @cb{.html}
@ce
+ * enclosing the application @cb{.html}