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.

              <button>Hover for a new image</button>
              html, body {
  min-height: 400px;

button {
  background: #ddd;
  border: none;
  font-size: 20px;
  padding: 10px 20px;

.tippy-tooltip.ajax-theme {
  position: absolute;
  width: 200px;
  padding: 0;
  overflow: hidden;

.tippy-tooltip.ajax-theme img {
  display: block;
  max-width: 100%;

We need to "pin" the tooltip absolutely to the bottom or top of the popper element depending on the placement. Note: this overrides the `distance` option. You can change `0` to be whatever you want. 
.tippy-tooltip.ajax-theme[x-placement^='top'] {
  top: auto !important;
  bottom: 0;

.tippy-tooltip.ajax-theme[x-placement^='bottom'] {
  bottom: auto !important;
  top: 0;
              const INITIAL_CONTENT = '<div style="margin:5px 0;">Loading...</div>'

function applyStyles(popper, tooltip) {
  // Because the tooltip has `position: absolute`,
  // it no longer affects the parent popper's layout.
  // We need to explicitly give it a width.
  popper.style.width = '200px'

  // Setup transition styles on the tooltip itself
  tooltip.style.transitionDuration = '0.2s'
  tooltip.style.transitionProperty = 'visibility, opacity, height'

function animateHeight(instance, instanceContent) {
  const { popper } = instance
  const { tooltip, content } = instance.popperChildren
  function onTransitionEnd(event) {
    if (event.target === event.currentTarget) {
      content.style.opacity = '1'
  // Wait until the height transition has finished before
  // fading the content in. Since we have `overflow: hidden`
  // on the tooltip this isn't actually needed, but if you
  // have an arrow element it will be.
  if (!instance._transitionEndListener) {
    instance._transitionEndListener = onTransitionEnd

  tooltip.addEventListener('transitionend', onTransitionEnd)
  // Store the base height of the tooltip when it has the
  // initial Loading... content.
  if (!instance._baseHeight) {
    instance._baseHeight = tooltip.clientHeight

  // Here is where we find out the height of the tooltip
  // when it has the content. We could technically hardcode
  // 200px as the value, but it's useful to know how to do
  // this with dynamic content.
  content.style.opacity = '0'
  // Temporarily set the image as the tooltip's content
  // so we can find out the final height of the tooltip.
  const height = tooltip.clientHeight
  // Apply the height to the parent popper element.
  popper.style.height = height + 'px'
  // Reset the tooltip's height to the base height.
  tooltip.style.height = instance._baseHeight + 'px'
  // Cause reflow so we can start the height transition.
  void tooltip.offsetHeight
  // Start the transition.
  tooltip.style.height = height + 'px'
  // Remove the Loading... content and wait until the
  // transition finishes.

tippy('button', {
  animation: 'fade',
  animateFill: false,
  theme: 'ajax',
  async onShow(instance) {
    if (instance.state.isFetching === true || instance.state.canFetch === false) {

    instance.state.isFetching = true
    instance.state.canFetch = false
    applyStyles(instance.popper, instance.popperChildren.tooltip)
    try {
      const response = await fetch('https://unsplash.it/200/?random')
      const blob = await response.blob()
      const url = URL.createObjectURL(blob)
      // If the tooltip hid before finishing the request, stop further action
      if (!instance.state.isVisible) {
      const img = new Image()
      img.width = 200
      img.height = 200
      img.src = url
      animateHeight(instance, img)
    } catch (error) {
      instance.setContent('An error occurred')
    } finally {
      instance.state.isFetching = false
  onHidden(instance) {
    const { tooltip } = instance.popperChildren
    instance.state.canFetch = true
    tooltip.style.height = null
    tooltip.removeEventListener('transitionend', instance._transitionEndListener)
    instance._transitionEndListener = null

🕑 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.