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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div class="question">
  <p>Match the following</p>
  <p>(Click an item on the LHS to select, then click an item on RHS to select the option)</p>
  <div class="stems">
      <li id="s1">Rabbit</li>
      <li id="s2">Peacock</li>
      <li id="s3">Turtle</li>
  <div class="options">
    <ol start="a">
      <li id="o1">Reptile</li>
      <li id="o2">Mammal</li>
      <li id="o3">Bird</li>
.options {
  li {
    list-style: none;
    padding: 0.5rem 1.5rem;
    margin: 1rem;
    &:hover {
      padding: 0.4rem 1.5rem 0.6rem;

.options {
  width: 40%;
  margin-right: 10%;
  float: left;

.stems li,
.options li {
  background: #e5e5e5;
  cursor: pointer;
  &.matched:hover {
    background: #aaccaa;
  &.selected:hover {
    background: #a9ffa9;
    font-weight: bold;
    box-shadow: 1px 2px 1px #666;
  &:hover {
    background: #a9cca9;

.line {
  width: 100%;
  height: 2px;
  background-color: #e5e5e5;
  z-index: -10;
  &.highlighted {
    background-color: green;
    box-shadow: 1px 2px 1px #666;
    height: 3px;
    z-index: 99;
    .point {
      border-left: 16px solid green;
  .point {
    width: 0;
    height: 0;
    margin: -6px -3px 0 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 16px solid #e5e5e5;
    float: right;

              (function($) {
  function lineDistance(x, y, x0, y0) {
    return Math.sqrt((x -= x0) * x + (y -= y0) * y);

  function line_exists(stem) {
    var $exists = false;
    $(".line").each(function() {
      if (
        $(this).data("stem") === stem.attr("id")
      ) {
        $exists = true;
    return $exists;

  function drawLine(stem, option) {
    var pointA = stem.offset();
    pointA.left = pointA.left + stem.outerWidth(); = + stem.outerHeight() / 2;
    var pointB = option.offset(); = + option.outerHeight() / 2;
    var angle =
      Math.atan2( -, pointB.left - pointA.left) *
      180 /
    var distance = lineDistance(

    var line = $('<div class="line highlighted"/>');
    line.append($('<div class="point"/>'))
    line.attr("data-stem", stem.attr("id"));
    line.attr("data-option", option.attr("id"));
    line.css("transform", "rotate(" + angle + "deg)");

    // Set Width
    line.css("width", distance + "px");

    // Set Position
    line.css("position", "absolute");

    if ( > {
      $(line).offset({ top:, left: pointA.left });
    } else {
      $(line).offset({ top:, left: pointA.left });

  $(".stems li").on("click", function() {
    stem = $(this);

    $(".stems li")

    $(".options li").removeClass("selected");

    if (stem.hasClass("selected")) {
      var stem_lines = $('.line[data-stem="' + stem.attr("id") + '"]');

      stem_lines.each(function() {
        var $option = $(this).data("option");
        $('.options li[id="' + $option + '"]').addClass("selected");
    } else {
      $('.line[data-stem="' + stem.attr("id") + '"]').removeClass(

  $(".options li").on("click", function() {
    if ($(".options").hasClass("ready")) {
      $(".options li").removeClass("selected");
      var stem = $(".stems li.selected");
      var option = $(this);
          '.line[data-stem="' +
            stem.attr("id") +
      drawLine(stem, option);
       var stem_lines = $('.line[data-stem="' + stem.attr("id") + '"]');
      } else{

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.