Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <!-- container for the d3 library -->
<div class="world"></div>


                * {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
body {
  min-height: 100vh;
  background: hsl(0, 0%, 97%);
  /* center the in the viewport */
  display: flex;
  justify-content: center;
  align-items: center;
/* size the svg to cover a sizeable portion of the viewport */
.world svg {
  max-width: 1400px;
  width: 90vw;
  height: auto;



                // json file providing a geometry for each country, differentiated by numerical ID
const urlJSON = '';
// tsv file providing general information for the different countries of the world
const urlTSV = '';

// add an svg element in which to plot the world map
const width = 500;
const height = 250;

const world = d3
  .attr('viewBox', `0 0 ${width} ${height}`);

// function adding countries through the d3.geo module
// called once the data from the url(s) is retrieved
// accepting as argument an object describing the features of the different countries
function addCountries(countries) {
  // projection used in the geoPath generator
  const projection = d3
    // use the size of the svg for the boundaries of the projection
    .fitSize([width, height], countries);

  // generator function to draw the countries
  const geoPath = d3

  // generator function to draw the graticule
  const geoGraticule = d3

  // before the path elements describing the countries draw a path element for the graticule
    .attr('d', geoPath(geoGraticule()))
    .attr('stroke', 'currentColor')
    .attr('fill', 'none')
    .attr('opacity', 0.1);

  // for each feature of the countries object add a path element
    .attr('class', 'country')
    .attr('d', geoPath)
    // specify a title describing the name of the country
    .text(({ name }) => name);

// retrieve the data from the json and tsv references
  .all([d3.json(urlJSON), d3.tsv(urlTSV)])
  .then(([json, tsv]) => {
    // convert topojson to json features
    const countries = topojson.feature(json, json.objects.countries);

    // add the name of the countries to the matching feature
    countries.features.forEach((feature) => {
      const { name } = tsv.find(({ iso_n3: id }) => id ===; = name;

    // call the function to draw path elements through the geo module
  .catch(err => console.error(err));