Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reading SVG files with D3js

d3.text() is the 1st key to include a SVG file on the DOM using D3js, the 2nd one is d3.selection().html(). After you inject the SVG you can manipulate the SVG using common D3js technics.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
<script src=""></script>
var width = 960,
height = 500;
d3.text('boom.svg', (textsvg) => {
.attr('width', `${width}px`)
.attr('height', `${height}px`);
These Pop Art Elements is licensed under Creative Commons Attribution 3.0 Unported License -
Under this license, you are free to copy and redistribute the material in any medium or format, remix, transform and build upon the material for any purpose, even commercially. In exchange, you must give appropriate credit to Vecteezy (
For more free resources, visit
- Monika Ratan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment