Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

HTML

              
                <div class="content">
  <h1>Vincent van Gogh</h1>
  <p>Vincent van Gogh, in full Vincent Willem van Gogh, (born March 30, 1853, <a href="#" data-hover-content="<div class='hover-content'>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/344846/500px-P1040705_copyGemeentehuis_Zundert.jpg' />
    <p>Zundert is a municipality and town in the south of the Netherlands, in the province of North Brabant.</p>
    </div>">Zundert, Netherlands</a> — died July 29, 1890, Auvers-sur-Oise, near <a href="#" data-hover-content="<div class='hover-content'>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/344846/eyfel-kulesi-paris.jpg' />
    <p>Paris is the capital and most populous city of France.</p>
    </div>">Paris, France</a>), Dutch painter, generally considered the greatest after <a href="#" data-hover-content="<div class='hover-content'>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/344846/Rembrandt.jpg' />
    <p>Rembrandt Harmenszoon van Rijn (July 15, 1606 – October 4, 1669) was a Dutch draughtsman, painter and printmaker.</p>
    </div>">Rembrandt van Rijn</a>, and one of the greatest of the <a href="#" data-hover-content="<div class='hover-content'>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/344846/Vincent-van-Gogh-The-Starry-Night-1889-2.jpg' />
    <p>Post-Impressionism is an art movement that developed in the 1890s.</p>
    </div>">Post-Impressionists.</a> The striking colour, emphatic brushwork, and contoured forms of his work powerfully influenced the current of <a href="#" data-hover-content="<div class='hover-content'>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/344846/Screen%20Shot%202019-04-20%20at%2012.04.29.png' />
    <p>Expressionism is a modernist movement, initially in poetry and painting, originating in Germany at the beginning of the 20th century.</p>
    </div>">Expressionism</a> in modern art. Van Gogh’s art became astoundingly popular after his death, especially in the late 20th century,
    when his work sold for record-breaking sums at auctions around the world and was featured in blockbuster touring exhibitions. In part because of his extensive published letters, van Gogh has also been mythologized in the popular imagination as the
    quintessential tortured artist.</p>
</div>
<span class="info">Please hover a link</span>

              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  background-color: #f5f5f5;
  font-family: 'Karla', sans-serif;
}

.content {
  max-width: 550px;
  padding: 40px;
  margin: 40px auto;
}

.content > h1 {
  margin: 0 0 20px 0;
  font-family: 'Cookie', monospace;
  font-size: 60px;
}

.content > p {
  line-height: 1.7;
  margin: 0;
}

.content > p > a {
  color: black;
  font-weight: 700;
}

.content > p > a:hover {
  background-color: #ffe0b2;
}

.hover-content {
  padding: 10px;
  box-shadow: 0 2px 20px rgba(0,0,0,0.2);
  box-sizing: border-box;
  background-color: #fff;
  width: 240px;
}

[data-hover-wrapper] {
  transition: opacity .3s, transform .3s;
}

.hover-content > img {
  max-width: 100%;
  margin-bottom: 10px;
}

.hover-content > p {
  font-size: 14px;
  margin: 0;
  line-height: 1.4;
}

.info {
  position: fixed;
  bottom: 0;
  right: 0;
  background-color: #000;
  padding: 10px 20px;
  color: #fff;
  font-size: 13px;
}
              
            
!

JS

              
                const links = document.getElementsByTagName("a");

[...links].forEach(link => {
  link.addEventListener("mouseover", handleMouseOver);
  link.addEventListener("mousemove", handleMouseMove);
  link.addEventListener("mouseleave", handleMouseLeave);
});

function handlePosition(e) {
  const ID = e.target.getAttribute("data-hover-id");
  const wrapper = document.getElementById(ID);
  let top = "";
  if (
    !(e.target.getBoundingClientRect().top + wrapper.offsetHeight > innerHeight)
  ) {
    top = `${e.clientY + e.target.offsetHeight}px`;
  } else {
    top = `${e.clientY - (wrapper.offsetHeight + e.target.offsetHeight)}px`;
  }

  return `position: fixed; left: ${e.clientX -
    wrapper.offsetWidth / 2}px; top:${top}`;
}

function handleMouseOver(e) {
  const hoverContent = e.target.getAttribute("data-hover-content");
  const ID = Math.random()
    .toString(36)
    .substr(2, 9);
  const wrapper = document.createElement("DIV");
  e.target.setAttribute("data-hover-id", ID);
  wrapper.setAttribute("data-hover-wrapper", "");
  wrapper.setAttribute("id", ID);
  wrapper.setAttribute("style", "opacity: 0; transform: scale(.8)");
  wrapper.innerHTML = hoverContent;
  document.body.append(wrapper);
  wrapper.setAttribute("style", handlePosition(e));
  
  // You can remove this line when you are using. I had added for the demo.
  if (document.querySelector('.info')) document.querySelector('.info').remove();
  
}

function handleMouseLeave(e) {
  const ID = e.target.getAttribute("data-hover-id");
  document.getElementById(ID).style.opacity = 0;
  document.getElementById(ID).style.transform = "scale(.8)";
  setTimeout(() => {
    document.getElementById(ID).remove();
  }, 150);
}

function handleMouseMove(e) {
  const ID = e.target.getAttribute("data-hover-id");
  const wrapper = document.getElementById(ID);
  wrapper.setAttribute("style", handlePosition(e));
}

window.addEventListener('scroll', () => {
  const wrapper = document.querySelector('[data-hover-wrapper]');
  if (wrapper) wrapper.remove();
});

              
            
!
999px

Console