We can create an HTML hidden template using the following method that we can add anywhere in the page. After creating a template we can now use it, modify it, and append/prepend it’s html anywhere in the page.
<script id="imageTemplate" type="text/template">
<div class="image-container">
<img src="https://i0.wp.com/webdevpuneet.com/wp-content/uploads/2022/03/Webdevpuneet-1.png?w=400&ssl=1">
</div>
</script>
DEMO
See the Pen HTML templates by Puneet Sharma (@webdevpuneet) on CodePen.