# SVG constructed from D3 + HTML template not displaying correctly

**URL:** <https://talk.observablehq.com/t/svg-constructed-from-d3-html-template-not-displaying-correctly/1061>\
**Category:** Help\
**Created:** [August 7, 2018, 3:14pm UTC](https://talk.observablehq.com/t/svg-constructed-from-d3-html-template-not-displaying-correctly/1061 "2018-08-07T15:14:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mauricef](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mauricef/32/883_2.png) [@mauricef](https://talk.observablehq.com/u/mauricef)\
**Post date:** [August 7, 2018, 3:14pm UTC](https://talk.observablehq.com/t/svg-constructed-from-d3-html-template-not-displaying-correctly/1061/1 "2018-08-07T15:14:52Z")

</div>

Example here [https://beta.observablehq.com/d/97c7a125f9159357](https://beta.observablehq.com/d/97c7a125f9159357)

I would expect the following to display a red circle but it does not. When I inspect the cell output in the element inspector, it shows the correct SVG.

```
{
  const svg = d3.select(DOM.svg(100, 100))
  const svgNode = svg.node()
  svgNode.append(html`<circle cx=50 cy=50 r=50 fill="red"/>`)
  return svgNode
}
```

---

<div class="post-metadata">

**Author:** ![severo](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/severo/32/786_2.png) [@severo](https://talk.observablehq.com/u/severo)\
**Post date:** [August 7, 2018, 3:23pm UTC](https://talk.observablehq.com/t/svg-constructed-from-d3-html-template-not-displaying-correctly/1061/3 "2018-08-07T15:23:37Z")

</div>

Try

```auto
{
  const svg = d3.select(DOM.svg(100, 100))
  svg.html(`<circle cx=50 cy=50 r=50 fill="red"/>`)
  return svg.node()
}

```

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [August 7, 2018, 3:56pm UTC](https://talk.observablehq.com/t/svg-constructed-from-d3-html-template-not-displaying-correctly/1061/4 "2018-08-07T15:56:56Z")

</div>

The problem is that the [`html` tagged template literal](https://github.com/observablehq/notebook-stdlib/blob/master/README.md#html) doesn’t know you are trying to create an svg:circle, and so creates an xhtml:circle element (an [HTMLUnknownElement](https://developer.mozilla.org/docs/Web/API/HTMLUnknownElement)), the same way it would if you tried to create a circle element outside of an SVG in literal HTML:

```auto
<body>
  <circle cx=50 cy=50 r=50 fill=red></circle>
</body>

```

You want the equivalent of this:

```auto
<body>
  <svg width=100 height=100>
    <circle cx=50 cy=50 r=50 fill=red></circle>
  </svg>
</body>

```

So, use the [`svg` tagged template literal](https://github.com/observablehq/notebook-stdlib/blob/master/README.md#svg) instead:

```auto
{
  const svgSelection = d3.select(DOM.svg(100, 100))
  const svgNode = svgSelection.node()
  svgNode.append(svg`<circle cx=50 cy=50 r=50 fill=red>`)
  return svgNode
}

```

---

<div class="post-metadata">

**Author:** ![mauricef](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mauricef/32/883_2.png) [@mauricef](https://talk.observablehq.com/u/mauricef)\
**Post date:** [August 7, 2018, 4:47pm UTC](https://talk.observablehq.com/t/svg-constructed-from-d3-html-template-not-displaying-correctly/1061/5 "2018-08-07T16:47:23Z")

</div>

Ahh! Thank you Mike, that worked, I was unaware of the difference, I see that now it creates an `SVGCircleElement` instead of a `HTMLUnknownElement`, thank you for rapid help!
