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

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

              
                <section class="no-js">
  <button id="dark-mode-toggle">Toggle Dark Mode</button>
  <button id="light-mode-toggle">Toggle Light Mode</button>

  <h3>Primary</h3>
  <ul class="sg-colors">
    <li><span class="sg-swatch sg-swatch-primary-dark"></span></li>
    <li><span class="sg-swatch sg-swatch-primary"></span></li>
    <li><span class="sg-swatch sg-swatch-primary-light"></span></li>
  </ul>
  <h3>Secondary</h3>
  <ul class="sg-colors">
    <li><span class="sg-swatch sg-swatch-secondary-dark"></span></li>
    <li><span class="sg-swatch sg-swatch-secondary"></span></li>
    <li><span class="sg-swatch sg-swatch-secondary-light"></span></li>
  </ul>
  <h3>Grey</h3>
  <ul class="sg-colors">
    <li><span class="sg-swatch sg-swatch-grey-dark"></span></li>
    <li><span class="sg-swatch sg-swatch-grey"></span></li>
    <li><span class="sg-swatch sg-swatch-grey-light"></span></li>
  </ul>
  <h3>Alerts</h3>
  <ul class="sg-colors">
    <li><span class="sg-swatch sg-swatch-alert"></span></li>
    <li><span class="sg-swatch sg-swatch-info"></span></li>
    <li><span class="sg-swatch sg-swatch-success"></span></li>
    <li><span class="sg-swatch sg-swatch-warning"></span></li>
  </ul>
  <h3>Util</h3>
  <ul class="sg-colors">
    <li><span class="sg-swatch sg-swatch-bg"></span></li>
    <li><span class="sg-swatch sg-swatch-text"></span></li>
  </ul>
  <div class="text">
    <h1>Heading Level 1</h1>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Laboriosam accusamus, fuga illum ut aut voluptas maxime, eaque in dolore temporibus sequi totam earum veritatis odit. Ex nemo suscipit aliquid doloribus! <a href="#">This is a text link</a>.</p>    
    <h2>Heading Level 2</h2>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel similique perferendis molestias quos sint cupiditate dolor, ducimus, odio debitis enim aspernatur, possimus voluptate deserunt harum adipisci nihil nesciunt minus. Pariatur.</p>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel similique perferendis molestias quos sint cupiditate dolor, ducimus, odio debitis enim aspernatur, possimus voluptate deserunt harum adipisci nihil nesciunt minus. Pariatur.</p>
    <h3>Heading Level 3</h3>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel similique perferendis molestias quos sint cupiditate dolor, ducimus, odio debitis enim aspernatur, possimus voluptate deserunt harum adipisci nihil nesciunt minus. Pariatur.</p>
  </div>
</section>
              
            
!

CSS

              
                /* ==========================================================================
   Color Variables
   ========================================================================== */
/* LIGHT */
$c-primary: #380021;
$c-primary-dark: darken($c-primary, 5%);
$c-primary-light: lighten($c-primary, 15%);
$c-secondary: #cc284e;
$c-secondary-dark: darken($c-secondary, 15%);
$c-secondary-light: lighten($c-secondary, 15%);
$c-grey: #7b7274;
$c-grey-dark: darken($c-grey, 20%);
$c-grey-light: lighten($c-grey, 20%);
$c-alert: #ab0000;
$c-info: #000459;
$c-success: #115832;
$c-warning: #6b5f13;
$c-bg: #fff7f9;
$c-text: #1e1719;

/* DARK */
$c-dark-primary: #ff70c3; // ff0095
$c-dark-primary-dark: desaturate(darken($c-dark-primary, 35%), 15%);
$c-dark-primary-light: lighten($c-dark-primary, 10%);
$c-dark-secondary: #fa6285; // dd5474;
$c-dark-secondary-dark: desaturate(darken($c-dark-secondary, 25%), 15%);
$c-dark-secondary-light: lighten($c-dark-secondary, 12%);
$c-dark-grey: #2b2328;
$c-dark-grey-dark: darken($c-dark-grey, 5%);
$c-dark-grey-light: lighten($c-dark-grey, 26%);
$c-dark-alert: #ec768c;
$c-dark-info: #b8baeb;
$c-dark-success: #5be69b;
$c-dark-warning: #d6d332;
$c-dark-bg: #1f0012;
$c-dark-text: #ffd6ee;

:root {
  --c-primary: #{$c-primary};
  --c-primary-dark: #{$c-primary-dark};
  --c-primary-light: #{$c-primary-light};
  --c-secondary: #{$c-secondary};
  --c-secondary-dark: #{$c-secondary-dark};
  --c-secondary-light: #{$c-secondary-light};
  --c-grey: #{$c-grey};
  --c-grey-dark: #{$c-grey-dark};
  --c-grey-light: #{$c-grey-light};
  --c-alert: #{$c-alert};
  --c-info: #{$c-info};
  --c-success: #{$c-success};
  --c-warning: #{$c-warning};
  --c-bg: #{$c-bg};
  --c-text: #{$c-text};
}

/* ==========================================================================
   Demo styling
   ========================================================================== */
.sg-colors {
  margin: 0;
  padding: 0;

  li {
    display: inline-block;
    text-align: center;
  }
}

.sg-swatch {
  box-shadow: 0 2px 5px 2px hsla(0, 0%, 50%, 0.4);
  display: block;
  height: 130px;
  margin: 30px 5px;
  position: relative;
  width: 130px;

  &:after {
    left: 0;
    padding-top: 0.5em;
    position: absolute;
    text-align: center;
    top: 100%;
    width: 100%;
  }

  &:before {
    color: black;
    display: block;
    padding-top: 0.5em;
    position: absolute;
    text-align: center;
    text-shadow: 0 0 4px #fff, 0 0 8px #fff, 0 0 12px #fff, 0 0 12px #fff,
      0 0 12px #fff;
    width: 100%;
  }
}

$sgSwatchList: (
  "primary" $c-primary,
  "primary-dark" $c-primary-dark,
  "primary-light" $c-primary-light,
  "secondary" $c-secondary,
  "secondary-dark" $c-secondary-dark,
  "secondary-light" $c-secondary-light,
  "text" $c-text,
  "grey-dark" $c-grey-dark,
  "grey" $c-grey,
  "grey-light" $c-grey-light,
  "bg" $c-bg,
  "alert" $c-alert,
  "info" $c-info,
  "success" $c-success,
  "warning" $c-warning,
);

@each $s in $sgSwatchList {
  .sg-swatch-#{nth($s, 1)} {
    background-color: nth($s, 2);

    &:after {
      content: ".c-#{nth($s, 1)}";
    }

    &:before {
      content: "#{nth($s, 2)}";
    }
  }
}

html,
body {
  box-sizing: border-box;
}

section {
  background-color: var(--c-bg);
  color: var(--c-text);
  overflow: auto;
  padding: 1rem;
}

a,
a:visited {
  color: var(--c-secondary);

  &:hover,
  &:focus {
    color: var(--c-secondary-dark);
  }
}

button {
  align-items: center;
  background: var(--c-secondary);
  background: linear-gradient(
    to right,
    var(--c-secondary-dark),
    var(--c-secondary-dark) 34%,
    var(--c-secondary) 66%
  );
  background-position: 100%;
  background-size: 300% 100%;
  border: 0;
  border-radius: 4px;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  color: var(--c-bg);
  display: inline-block;
  height: auto;
  line-height: 1.15;
  overflow: hidden;
  padding: 12px 24px;
  position: relative;
  text-align: center;
  text-decoration: none;
  vertical-align: middle;
}

h1,
h2,
h3 {
  color: var(--c-primary-light);
}

/* ==========================================================================
   Dark Mode Modifications (usually in a separate file, inline because of CodePen)
   ========================================================================== */
@mixin dark-mode {
  --c-primary: #{$c-dark-primary};
  --c-primary-dark: #{$c-dark-primary-dark};
  --c-primary-light: #{$c-dark-primary-light};
  --c-secondary: #{$c-dark-secondary};
  --c-secondary-dark: #{$c-dark-secondary-dark};
  --c-secondary-light: #{$c-dark-secondary-light};
  --c-grey: #{$c-dark-grey};
  --c-grey-dark: #{$c-dark-grey-dark};
  --c-grey-light: #{$c-dark-grey-light};
  --c-alert: #{$c-dark-alert};
  --c-info: #{$c-dark-info};
  --c-success: #{$c-dark-success};
  --c-warning: #{$c-dark-warning};
  --c-bg: #{$c-dark-bg};
  --c-text: #{$c-dark-text};

  $sgSwatchListDark: (
    "primary" $c-dark-primary,
    "primary-dark" $c-dark-primary-dark,
    "primary-light" $c-dark-primary-light,
    "secondary" $c-dark-secondary,
    "secondary-dark" $c-dark-secondary-dark,
    "secondary-light" $c-dark-secondary-light,
    "text" $c-dark-text,
    "grey-dark" $c-dark-grey-dark,
    "grey" $c-dark-grey,
    "grey-light" $c-dark-grey-light,
    "bg" $c-dark-bg,
    "alert" $c-dark-alert,
    "info" $c-dark-info,
    "success" $c-dark-success,
    "warning" $c-dark-warning,
  );

  @each $s in $sgSwatchListDark {
    .sg-swatch-#{nth($s, 1)} {
      background-color: nth($s, 2);

      &:after {
        content: ".c-#{nth($s, 1)}";
      }

      &:before {
        content: "#{nth($s, 2)}";
      }
    }
  }

}

/* ==========================================================================
   Applying colors based on `prefers-color-scheme` first, then user selection in `data-color-scheme`
   ========================================================================== */
@media (prefers-color-scheme: dark) {
  section.no-js {
    @include dark-mode;
  }
}

[data-color-scheme="dark"] {
    @include dark-mode;
}



              
            
!

JS

              
                let BeInclusive = {};

BeInclusive.Utils = {
  /**
   * Set the current color scheme to the provided `currentTheme`, overriding the default
   * 
   * @param {string} currentTheme 
   */
  colorSchemeSet: function(currentTheme) {
    let containerElement = document.getElementsByTagName("section")[0];
    if (currentTheme == "dark") {
      containerElement.dataset.colorScheme = "dark";
    } else {
      containerElement.dataset.colorScheme = "light";
    }

    localStorage.setItem("theme", currentTheme);

    return currentTheme;
  },
  /**
   * Triggers the color scheme setting when the OS `prefers-color-scheme` value changes
   * 
   * @param {Event} e 
   */
  colorSchemeTrigger: function(e) {
    let prefersDarkScheme = e;

    if (prefersDarkScheme.matches) {
      return this.colorSchemeSet("dark");
    } else {
      return this.colorSchemeSet("light");
    }
  },
  /**
   * Initializes the color schene settings based on localStorage, defaults to 
   * `prefers-color-scheme` if no localStorage value is set.
   */
  colorSchemeInit: function() {
    window
      .matchMedia("(prefers-color-scheme: dark)")
      .addEventListener("change", e => this.colorSchemeTrigger(e));

    let currentTheme = localStorage.getItem("theme");

    if (["dark", "light"].indexOf(currentTheme) == -1) {
      return this.colorSchemeTrigger(
        window.matchMedia("(prefers-color-scheme: dark)")
      );
    } else {
      if (currentTheme == "dark") {
        return this.colorSchemeSet("dark");
      } else {
        return this.colorSchemeSet("light");
      }
    }
  },
};

// (This should be <body> or <html>, changed to section here so it can run in CodePen)
let containerElement = document.getElementsByTagName("section")[0];
let toggleDark = document.getElementById('dark-mode-toggle');
let toggleLight = document.getElementById('light-mode-toggle');

containerElement.classList.remove("no-js");
toggleDark.addEventListener("click", e => BeInclusive.Utils.colorSchemeSet('dark'));
toggleLight.addEventListener("click", e => BeInclusive.Utils.colorSchemeSet('light'));
BeInclusive.Utils.colorSchemeInit();

              
            
!
999px

Console