<div id="name">Bob</div>
<template id="nameTemplate">
<div>
Hi! My name is
<span style="color:red;"><content></content></span>
</div>
</template>
<script>
var shadow = document.querySelector('#name').createShadowRoot();
var template = document.querySelector('#nameTemplate');
var clone = document.importNode(template.content, true);
shadow.appendChild(clone);
</script>
Here is the inspect element outcome in Chrome. Note that we are seeing an extra entry for #shadow-root.
.createShadowRoot() is used to create shadow root. The moment it is created, it shadows its host element.
We used HTML5 template to populate shadow root. But we could have also used any valid DOM object. But typically one would use template for this purpose.
The <content></content> in template is replaced by host element content.