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="container">
  <div class="button-and-tooltip-wrapper">
    <button class="primary-button" aria-describedby="save-desc">Save</button>
    <div role="tooltip" id="save-desc">
      <span class="tooltipItself">
        <!-- If the tooltip duplicates content that is already available on the page, remove it.
https://primer.style/design/components/tooltip#2-dont-duplicate-content
    <span>Save</span>
 -->
        <span class="visually-hidden"> shortcut </span>
        <kbd><kbd>Ctrl</kbd> <kbd>Alt</kbd> <kbd>S</kbd></kbd>
      </span>
    </div>
  </div>

  <div class="button-and-tooltip-wrapper">
    <button class="secondary-button" aria-describedby="cancel-desc">Cancel</button>
    <div role="tooltip" id="cancel-desc">
      <span class="tooltipItself">
        <!-- If the tooltip duplicates content that is already available on the page, remove it.
https://primer.style/design/components/tooltip#2-dont-duplicate-content
    <span>Cancel</span>
 -->
        <!--         <span class="visually-hidden"> shortcut </span>  -->
        <kbd><kbd>Ctrl</kbd> <kbd>Esc</kbd></kbd>
      </span>
    </div>
  </div>
</div>
<div style="margin: 3em;">
  <p>The first button has a tooltip with shortcut keys and visually hidden text to concisely identify the following content as a shortcut.</p>
  <p>The second button also has a tooltip with shortcut keys, but the visually hidden text is commented out.</p>
  <p>To hear the difference, start your screen reader of choice.</p>
  <p>To display the visually hidden text, edit the CSS to <strong>comment out the first</strong> <code>.visually-hidden</code> class.</p>
</div>
              
            
!

CSS

              
                :root {
  font-family: system-ui, Arial, sans-serif;
  --color-grey-00: #000000;
  --color-grey-13: #212121;
  --color-grey-24: #3d3d3d;
  --color-grey-33: #545454;
  --color-grey-44: #6f6f6f;
  --color-grey-96: #f5f5f5;
  --color-grey-100: #ffffff;
}

.container {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 3em;
}

.primary-button,
.secondary-button {
  color: var(--color-grey-100, #ffffff);
  background-color: #e01a22;
  padding: 8px 16px;
  border-radius: 32px;
  border: none;
  cursor: pointer;
}
.primary-button:hover {
  background-color: #b9091d;
}
.secondary-button {
  color: var(--color-grey-13, #212121);
  background-color: var(--color-grey-100, #ffffff);
}
.secondary-button:hover {
  background-color: var(--color-grey-96, #f5f5f5);
}
:focus {
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #2670ee;
  outline: none;
}

/* positioning tooltip */
.button-and-tooltip-wrapper {
  position: relative;
}
[role="tooltip"] {
  position: absolute;
  bottom: 100%;
  padding-bottom: 6px;
  display: block; /* overridden by interaction styles below */
}
/* interaction styles for tooltip on button focus and hover */
[role="tooltip"] {
  display: none;
}
.button-and-tooltip-wrapper:hover [role="tooltip"],
button:focus + [role="tooltip"] {
  /* Using :hover on the wrapper is a way to achieve Hoverable in SC 1.4.13 Content on Hover or Focus (Level AA) https://www.w3.org/WAI/WCAG22/Understanding/content-on-hover-or-focus.html */
  display: block;
}
.button-and-tooltip-wrapper:hover button:not(:focus) + [role="tooltip"] {
  /* When the button is hovered, not keyboard focused, no box-shadow is visible so we can bring the tooltip nearer to the button */
  padding-bottom: 2px;
}

.tooltipItself {
  display: flex;
  align-items: center;
  gap: var(--spacing-2, 16px);
  padding: var(--spacing-half, 4px);
  font-size: 0.8em;
  color: var(--color-grey-100, #ffffff);
  background-color: var(--color-grey-24, #3d3d3d);
  border-radius: 4px;
}
.tooltipItself span {
  white-space: nowrap;
}
.tooltipItself > kbd {
  display: inline-flex;
  gap: var(--spacing-half, 4px);
  align-items: baseline;
}
kbd > kbd {
  color: #fff;
  background-color: var(--color-grey-44, #6f6f6f);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: system-ui, Arial, sans-serif;
}

/* */
.visually-hidden {
  clip-path: inset(100%);
  clip: rect(1px, 1px, 1px, 1px);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}
/* */
/* Comment out .visually-hidden above for times when you want to display what is normally visually-hidden */
.visually-hidden {
  color: #efd594;
  outline: 1px dashed goldenrod;
  padding: var(--spacing-half, 4px);
  margin: 0 4px;
  height: 1em;
  border-radius: 2px;
}

              
            
!

JS

              
                
              
            
!
999px

Console