Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <h1>Toasts</h1>
<div class="toast__actions">
  <button class="toast__trigger">Info Toast</button>
  <button class="toast__trigger">Warning Toast</button>
  <button class="toast__trigger">Success Toast</button>
</div>

<section class="toast__container">

  <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
    <div class="toast__icon">
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
        <path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path>
      </svg>
    </div>
    <div class="toast__content">
      <h2>Information</h2>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Labore cumque nesciunt quod, eius error officiis aut excepturi repellat asperiores cum, neque eveniet voluptatum. Quae necessitatibus velit dolore quidem facere repellat!</p>
    </div>
  </div>

  <div class="toast toast--warning" role="alert" aria-live="assertive" aria-atomic="true">
    <div class="toast__icon">
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="exclamation-circle" class="svg-inline--fa fa-exclamation-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
        <path fill="currentColor" d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"></path>
      </svg>
    </div>
    <div class="toast__content">
      <h2>Danger!</h2>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Labore cumque nesciunt quod, eius error officiis aut excepturi repellat asperiores cum, neque eveniet voluptatum. Quae necessitatibus velit dolore quidem facere repellat!</p>
    </div>
  </div>

  <div class="toast toast--success" role="alert" aria-live="assertive" aria-atomic="true">
    <div class="toast__icon">

      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="check-circle" class="svg-inline--fa fa-check-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
        <path fill="currentColor" d="M504 256c0 136.967-111.033 248-248 248S8 392.967 8 256 119.033 8 256 8s248 111.033 248 248zM227.314 387.314l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.249-16.379-6.249-22.628 0L216 308.118l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.249 16.379 6.249 22.628.001z"></path>
      </svg>
    </div>
    <div class="toast__content">
      <h2>All Clear</h2>
      <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Labore cumque nesciunt quod, eius error officiis aut excepturi repellat asperiores cum, neque eveniet voluptatum. Quae necessitatibus velit dolore quidem facere repellat!</p>
    </div>
  </div>

</section>
              
            
!

CSS

              
                body {
  font-size: 18px;
  line-height: 1.5;
  background: #eee;
  color: #333;
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-flow: column;
  align-items: center;
  justify-content: center;
}

$toastBackground: (
  "default": #ffffff,
  "warning": #bf360c,
  "success": #43a047
);

$small: 320px;
$medium: 640px;
$large: 768px;
$extra-large: 1024px;

$breakpoints: (
  "sm": "min-width:" + $small,
  "md": "min-width:" + $medium,
  "lg": "min-width:" + $large,
  "xl": "min-width:" + $extra-large
);

h1 {
  box-sizing: border-box;
  width: 100%;
  max-width: $large;
  margin: 0 auto;
  text-align: center;
  text-transform: uppercase;
  text-decoration: underline;
}

.toast {
  cursor: pointer;
  box-sizing: border-box;
  display: none;
  width: 100%;
  max-width: $medium;
  font-size: 0.825em;
  border-top-right-radius: 5px;
  border-top-left-radius: 5px;
  background: map-get($toastBackground, "default");
  box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.02),
    0 6.7px 5.3px rgba(0, 0, 0, 0.028), 0 12.5px 10px rgba(0, 0, 0, 0.035),
    0 22.3px 17.9px rgba(0, 0, 0, 0.042), 0 41.8px 33.4px rgba(0, 0, 0, 0.05),
    0 100px 80px rgba(0, 0, 0, 0.07);
  transition: 0.2s ease-in;
  @media (map-get($breakpoints, "md")) {
    border-radius: 5px;
    margin-bottom: 0.5em;
  }
  &--active {
    display: flex;
    animation: slidein--bottom 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55)
      forwards;
  }
  &--warning {
    background: map-get($toastBackground, "warning");
    color: white;
  }
  &--success {
    background: map-get($toastBackground, "success");
    color: white;
  }
  &__actions {
    width: 100%;
    max-width: $large;
    margin: 0 auto;
    display: flex;
    flex-flow: column;
    @media (map-get($breakpoints, "md")) {
      flex-flow: row;
    }
  }
  &__trigger {
    cursor: pointer;
    box-sizing: border-box;
    flex: 1;
    padding: 1em;
    margin: 1em;
    border: 0;
    background: tomato;
    border-radius: 5px;
    color: white;
    text-transform: uppercase;
    font-weight: bold;
    transition: 0.2s ease;
    &:hover {
      background: darken(tomato, 10%);
    }
  }
  &__container {
    box-sizing: border-box;
    padding: 0em 1em;
    position: fixed;
    width: 100%;
    max-width: $medium;
    margin: 0 auto;
    display: flex;
    flex-flow: column;
    bottom: 0;
    left: 0;
    right: 0;
    align-items: center;
    justify-content: center;
    @media (map-get($breakpoints, "md")) {
      padding: 0 1em;
    }
    @media (map-get($breakpoints, "xl")) {
      left: initial;
      right: 0;
    }
  }
  &__icon {
    height: 60px;
    width: 60px;
    box-sizing: border-box;
    padding: 1em;
    display: none;
    align-items: center;
    justify-content: center;
    svg {
      height: 100%;
    }
    @media (map-get($breakpoints, "md")) {
      display: flex;
    }
  }
  &__icon ~ &__content {
    padding: 1em;
    @media (map-get($breakpoints, "md")) {
      padding: 1em 1em 1em 0;
    }
  }
  &__content {
    box-sizing: border-box;
    padding: 1em;
    h2 {
      margin: 0 0 0.25em 0;
      padding: 0;
      font-size: 1.2em;
    }
    p {
      margin: 0;
      padding: 0;
      font-size: 1em;
    }
  }
}

@keyframes slidein--bottom {
  0% {
    opacity: 0;
    transform: translateY(100%);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

              
            
!

JS

              
                const toasts = document.querySelectorAll(".toast");
const toastTriggers = document.querySelectorAll(".toast__trigger");

toastTriggers.forEach((trigger, index) => {
  let toastTimeout;

  trigger.addEventListener("click", () => {
    toasts[index].classList.add("toast--active");
    toastTimeout = setTimeout(() => {
      toasts[index].classList.remove("toast--active");
    }, 3500);
  });

  toasts[index].addEventListener("click", () => {
    toasts[index].classList.remove("toast--active");
    clearTimeout(toastTimeout);
  });
});

              
            
!
999px

Console