I’m trying to update the CSS of an element that exists inside an iframe on a Shopify page, and I’m hitting some limitations.
Context:
-
The iframe is injected by a Shopify app / third-party script.
-
The iframe has a class but no ID.
-
The element inside the iframe I want to style does not have a unique ID.
-
The iframe content loads dynamically after the page has loaded.
-
I do not have direct access to the iframe’s source HTML.
-
The iframe appears to be same-origin, but I’m not fully certain.
What I’ve tried so far:
-
Targeting the iframe via its class using theme CSS (doesn’t affect inner content).
-
JavaScript to wait for the iframe to load, then attempt to query elements inside it.
-
MutationObserver to detect changes in iframe content.
-
Attribute selectors and
:nth-child()as fallbacks for elements without IDs.
Main questions:
-
Since the iframe has a class but no ID, what is the recommended way to reliably target it in Shopify?
-
If the iframe is same-origin, what is the best JavaScript approach to access and style elements inside it?
-
If it’s cross-origin, are there Shopify-safe alternatives (app settings, CSS variables, injected styles, or overrides)?
-
What are the best practices for handling dynamically loaded iframe content in Shopify themes without breaking on updates?
I’m aiming for a maintainable solution, not a brittle workaround that could fail after app or theme updates.
Any advice or examples from Shopify experts would be greatly appreciated.
Thanks in advance ![]()