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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.

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.


                <!-- Usually we can style HTML attributes with pseudo elements, but some elements can't take children, therefore can't take pseudo elements - img is one such element. We can use js to get the attribute from the element and add it to the HTML -->

<div class="container">
  <h1>Show Alt Attribute on Hover</h1>
  <div class="img-wrap">
    <img class="img" src="" alt="So far so good." />

    <img class="img" src="" alt="I run so far." />

    <img class="img" src="" alt="I have ennui." />  

    <img class="img" src="" alt="Peeling yellow wallpaper." /> 


                @import url(;

/* ----- Page Styling ----- */
/* -- Irrelevant to Pen. Scroll down. -- */
    body { height: 100%; width: 100%; background-color: #333; color: grey; font-family: 'Roboto'} 
  .container { 
    max-width: 960px; 
    height: 100%;
    margin: 0 auto; 
    padding: 20px;

  .img-wrap {
    display: flex;
    flex-direction: row;
    justify-content: space-around;

  .img { display: block; }

  h1 {
    text-align: center;
    text-transform: uppercase;
    font-weight: 400;
    letter-spacing: 2px;
    font-size: 24px;

/* ----- Style the elements ----- */

  /* Wrap the image and alt text */
  /* Will be added with js */
    .alt-wrap { 
      display: block;
      position: relative;
      margin: 20px;
      color: whitesmoke;
      border: 1px solid mediumorchid;

  /* The alt text itself */
  /* Will be added with js */
    .alt-wrap p.alt {
      position: absolute;
      opacity: 0; /* hide initially */
      left: 0; right: 0; bottom: 0;
      margin: 0;
      padding: 15px;
      font-size: 14px;
      line-height: 22px;
      background-color: rgba(0,0,0,0.8);
      transition: all 300ms ease;
      transition-delay: 300ms;

  /* Hovering over the wrapper shows its alt p*/
    .alt-wrap:hover > p.alt { 
      opacity: 1; 
      transition-delay: 0s;


                // Wrap every .img in a div
  // 1. For all items with class .img...
  // 2. Wrap them in a div
  $(".img").wrap('<div class="alt-wrap"/>');

// Add alt text after each .img
  // 1. For all items with class .img...
  // 2. Run a function for each of them...
  // 3. To add a p element after it
  // 5. Containing that element's alt text
  $(".img").each(function() {
    $(this).after('<p class="alt">' + $(this).attr('alt') + '</p>');

// CSS shows/hides the alt text on hover