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

              
                
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>CSS Variables - Theming</title>
    <link rel="stylesheet" href="theme.css" />
  </head>
  <body>
    <header>
      <div class="container">
        <div class="container-inner">
          <a href="#" class="logo">My Blog</a>
          <div class="toggle-button-container">
            <label class="toggle-button-label" for="checkbox">
              <input type="checkbox" class="toggle-button" id="checkbox" />
              <div class="toggle-rounded"></div>
            </label>
          </div>
        </div>
      </div>
    </header>
    <article>
      <div class="container">
        <h1 class="title">Title of article</h1>
        <div class="info">
          <div class="tags">
            <span>#html</span>
            <span>#css</span>
            <span>#js</span>
          </div>
          <span>1st March, 2020</span>
        </div>
        <div class="content">
          <p>
            Lorem ipsum dolor sit amet consectetur adipisicing elit.
            <a href="#">Link to another url</a> Eius, saepe optio! Quas
            repellendus consequuntur fuga at. Consequatur sit deleniti, ullam
            qui facere iure, earum corrupti vitae laboriosam iusto eius magni,
            adipisci culpa recusandae quis tenetur accusantium eum quae harum
            autem inventore architecto perspiciatis maiores? Culpa, officiis
            totam! Rerum alias corporis cupiditate praesentium magni illo, optio
            nobis fugit.
          </p>
          <p>
            Eveniet veniam ipsa similique atque placeat dignissimos
            quos reiciendis. Odit, eveniet provident fugiat voluptatibus esse
            culpa ullam beatae hic maxime suscipit, eum reprehenderit ipsam.
            Illo facilis doloremque ducimus reprehenderit consequuntur
            cupiditate atque harum quaerat autem amet, et rerum sequi eum cumque
            maiores dolores.
          </p>
        </div>
      </div>
    </article>
    <script src="theme.js"></script>
  </body>
</html>

              
            
!

CSS

              
                
:root {
  --primary-color: #0d0b52;
  --secondary-color: #3458b9;
  --font-color: #424242;
  --bg-color: #ffffff;
  --heading-color: #292922;
  --white-color: #ffffff;
}
/* Layout */
* {
  padding: 0;
  border: 0;
  margin: 0;
  box-sizing: border-box;
}
html {
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
body {
  background: var(--bg-color);
  color: var(--font-color);
}
.container {
  width: 100%;
  max-width: 768px;
  margin: auto;
  padding: 0 1rem;
}
.container-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Using custom properties */
a {
  text-decoration: none;
  color: var(--primary-color);
}
p {
  font-size: 1.2rem;
  margin: 1rem 0;
  line-height: 1.5;
}
header {
  padding: 1rem 0;
  border-bottom: 0.5px solid var(--primary-color);
}
.logo {
  color: var(--font-color);
  font-size: 2rem;
  font-weight: 800;
}
.toggle-button-container {
  display: flex;
  align-items: center;
}
.toggle-button-container em {
  margin-left: 10px;
  font-size: 1rem;
}
.toggle-button-label {
  display: inline-block;
  height: 34px;
  position: relative;
  width: 60px;
}
.toggle-button-label .toggle-button {
  display: none;
}
.toggle-rounded {
  background-color: #ccc;
  bottom: 0;
  cursor: pointer;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
  transition: 0.4s;
}
.toggle-rounded:before {
  background-color: #fff;
  bottom: 4px;
  content: '';
  height: 26px;
  left: 4px;
  position: absolute;
  transition: 0.4s;
  width: 26px;
}
input:checked + .toggle-rounded {
  background-color: #9cafeb;
}
input:checked + .toggle-rounded:before {
  transform: translateX(26px);
}
article {
  margin-top: 2rem;
}
.title {
  font-size: 3rem;
  color: var(--font-color);
}
.info {
  display: flex;
  align-items: center;
  margin: 1rem 0;
}
.tags {
  margin-right: 1rem;
}
.tags span {
  background: var(--primary-color);
  color: var(--white-color);
  padding: 0.2rem 0.5rem;
  border-radius: 0.2rem;
} 


@media (prefers-color-scheme: dark) {
  :root {
    --primary-color: #325b97;
    --secondary-color: #9cafeb;
    --font-color: #e1e1ff;
    --bg-color: #000013;
    --heading-color: #818cab;
  }
}
              
            
!

JS

              
                
const toggleButton = document.querySelector('.toggle-button');
toggleButton.addEventListener('change', toggleTheme, false);

const theme = {
  dark: {
    '--primary-color': '#325b97',
    '--secondary-color': '#9cafeb',
    '--font-color': '#e1e1ff',
    '--bg-color': '#000013',
    '--heading-color': '#818cab'
  },
  light: {
    '--primary-color': '#0d0b52',
    '--secondary-color': '#3458b9',
    '--font-color': '#424242',
    '--bg-color': '#ffffff',
    '--heading-color': '#292922'
  }
};

function toggleTheme(e) {
  if (e.target.checked) {
    useTheme('dark');
    localStorage.setItem('theme', 'dark');
  } else {
    useTheme('light');
    localStorage.setItem('theme', 'light');
  }
}

function useTheme(themeChoice) {
  document.documentElement.style.setProperty(
    '--primary-color',
    theme[themeChoice]['--primary-color']
  );
  document.documentElement.style.setProperty(
    '--secondary-color',
    theme[themeChoice]['--secondary-color']
  );
  document.documentElement.style.setProperty(
    '--font-color',
    theme[themeChoice]['--font-color']
  );
  document.documentElement.style.setProperty(
    '--bg-color',
    theme[themeChoice]['--bg-color']
  );
  document.documentElement.style.setProperty(
    '--heading-color',
    theme[themeChoice]['--heading-color']
  );
}

const preferredTheme = localStorage.getItem('theme');
if (preferredTheme === 'dark') {
  useTheme('dark');
  toggleButton.checked = true;
} else {
  useTheme('light');
  toggleButton.checked = false;
}
              
            
!
999px

Console