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

              
                <main>
  <button popovertarget="my-tooltip">
    <p aria-hidden="true">?</p>
    <p class="sr-only">Open Tooltip</p>
  </button>

  <div id="my-tooltip" popover="manual">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed malesuada lacus est, at dapibus risus bibendum sit amet. Mauris dolor urna, vehicula et porta finibus, convallis eget dui. Donec nibh neque, iaculis nec odio eu, vestibulum aliquet leo. Donec id lorem lectus. Mauris porta arcu id dolor sagittis, a placerat mi suscipit. </div>

  <section id="options">
    <fieldset>
      <legend> Anchor Position </legend>
      <label> <input type="radio" id="left" name="anchor-position">left</label>
      <label> <input type="radio" id="right" name="anchor-position">right</label>
      <label> <input type="radio" id="top" name="anchor-position">top</label>
      <label> <input type="radio" id="bottom" name="anchor-position">bottom</label>
      <label> <input type="radio" id="center" name="anchor-position" checked>center</label>
    </fieldset>
    <label><input type="checkbox" id="open-on-hover">Open tooltip on hover</label>
  </section>
</main>
              
            
!

CSS

              
                button {
  anchor-name: --anchor-btn;

  font-size: 1rem;
  border-radius: 2rem;
  height: 2rem;
  width: 2rem;
  display: grid;
  border: 2px solid black;
  place-content: center;
}

[popover] {
  --tether-offset: 1px;
  --tether-size: 8px;

  position-anchor: --anchor-btn;
  position: absolute;
  position-area: top;
  position-try: --bottom, --left, --right;

  margin: 0 0 var(--tether-size) 0;
  clip-path: inset(var(--tether-offset)) margin-box;

  /* need this to see the tether */
  overflow: visible;

  max-width: 300px;

  background: black;
  color: white;
  border: none;
  padding: 1rem;
  border-radius: 1rem;

  &::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: calc(-1 * var(--tether-size)) calc(50% - var(--tether-size));
    background: inherit;
    clip-path: polygon(
      0 var(--tether-size),
      50% 0,
      100% var(--tether-size),
      100% calc(100% - var(--tether-size)),
      50% 100%,
      0 calc(100% - var(--tether-size))
    );
  }

  &::after {
    content: "";
    position: absolute;
    z-index: -1;
    inset: calc(50% - var(--tether-size)) calc(-1 * var(--tether-size));
    background: inherit;
    clip-path: polygon(
      0 var(--tether-size),
      var(--tether-size) 0,
      calc(100% - var(--tether-size)) 0,
      100% 50%,
      calc(100% - var(--tether-size)) 100%,
      var(--tether-size) 100%
    );
  }
}

@position-try --bottom {
  position-area: bottom;
  margin: 0.5rem 0 0 0;
}
@position-try --left {
  position-area: left;
  margin: 0 0.5rem 0 0;
}
@position-try --right {
  position-area: right;
  margin: 0 0 0 0.5rem;
}

.sr-only {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

html,
body,
main {
  height: 100%;
  margin: 0;
}

main {
  display: flex;
  align-items: center;
  justify-content: center;

  &:has(input#left:checked) {
    align-items: center;
    justify-content: start;
  }
  &:has(input#right:checked) {
    align-items: center;
    justify-content: end;
  }
  &:has(input#top:checked) {
    align-items: start;
    justify-content: center;
  }
  &:has(input#bottom:checked) {
    align-items: end;
    justify-content: center;
  }
}

#options {
  position: fixed;
  bottom: 2rem;
  left: 2rem;
}

              
            
!

JS

              
                // this JS is optional, just enables showing the popover on mouse hover

const popover = document.querySelector("[popover]");
const hoverCheckbox = document.querySelector("#open-on-hover");

// show popover on mouseenter
document.querySelector("button").addEventListener("mouseenter", () => {
  if (hoverCheckbox.checked) {
    popover.showPopover();
  }
});

// hide popover on mouseleave
document.querySelector("button").addEventListener("mouseleave", () => {
  if (hoverCheckbox.checked) {
    popover.hidePopover();
  }
});

              
            
!
999px

Console