packages/docs/docs/troubleshooting/background-image.mdx
The following code is discouraged in Remotion:
const src = "abc";
// ---cut---
const myMarkup = (
<div
style={{
backgroundImage: `url(${src})`,
}}
>
<p>Hello World</p>
</div>
);
Remotion has no way of knowing when the image is finished loading because it is impossible to determine so when loading an image through background-image, mask-image, or other CSS properties. This will lead to Remotion not waiting for the image to be loaded during rendering and cause visible flickers.
Use the `` tag instead and place it in an <AbsoluteFill>:
const src = "abc";
// ---cut---
import { AbsoluteFill, Img } from "remotion";
const myMarkup = (
<AbsoluteFill>
<AbsoluteFill>
</AbsoluteFill>
<AbsoluteFill>
<p>Hello World</p>
</AbsoluteFill>
</AbsoluteFill>
);
The next will be placed on top of the image and will not flicker.
If you cannot use an [](/docs/img) tag, for example because you need to use `mask-image()`, render an adjacent tag that renders the same src and place it outside the viewport:
const src = "abc";
// ---cut---
import { Img } from "remotion";
const myMarkup = (
<>
<div
style={{
maskImage: `url(${src})`,
}}
>
<p>Hello World</p>
</div>
</>
);
The hidden `` tag ensures the image will download completely which allows the background-image will fully render.