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

              
                
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 0;
  font-family: 'Open Sans', sans-serif;
}

.container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

header {
  width: 100%;
  height: 10rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

.header-content {
  width: 80%;
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 3rem;
  user-select: none;
  width: 5rem;
  height: 5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  transform: rotate(-25deg);
}

.drop-btn {
  padding: 1rem;
  font-size: 1rem;
  background: none;
  outline: none;
}

.dropdown {
  position: relative;
  display: inline-block;
}

.drop-content {
  display: none;
  position: absolute;
  top: 3.3rem;
  min-width: 160px;
  z-index: 1;
}

.drop-content a {
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.drop-content a:hover {
  text-decoration: underline;
}

.dropdown:hover .drop-content {
  display: block;
}

main {
  width: 85%;
  height: 100%;
  padding: 0 2rem 3rem;
  box-sizing: border-box;
}
              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', () => {

  // ============== COLORS AND THEMES =============== //

  const colors = {
    white: '#FFFFFF',
    lightGray: '#F5F3F4',
    gray: '#D3D3D3',
    warmGray: '#B1A7A6',
    tomatoRed: '#E5383B',
    lightRed: '#BA181B',
    red: '#A4161A',
    darkRed: '#660708',
    darkGray: '#161A1D',
    almostBlack: '#0B090A'
  }

  let isLight = true;
  let isDark = false;
  let isRed = false;

  // =============== EXAMPLE ARTICLE INFO =============== //

  let headline = 'Hello World!';

  let subheadline = 'You can update your display preferences.';

  let author = 'This Guy';

  let publishDate = '6:45pm Wed March 17, 2021';

  let copy1 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Aliquet risus feugiat in ante metus dictum at. Velit egestas dui id ornare arcu odio. Bibendum neque egestas congue quisque egestas. Gravida arcu ac tortor dignissim convallis aenean. Risus at ultrices mi tempus imperdiet nulla malesuada. Amet consectetur adipiscing elit duis. Quam pellentesque nec nam aliquam sem et. Pulvinar pellentesque habitant morbi tristique senectus et netus. Aliquam purus sit amet luctus venenatis. Malesuada pellentesque elit eget gravida cum sociis.';

  let copy2 = 'Mattis rhoncus urna neque viverra justo nec ultrices dui. At consectetur lorem donec massa sapien faucibus et molestie ac. Vitae purus faucibus ornare suspendisse sed nisi lacus sed viverra. Lectus magna fringilla urna porttitor. Tristique nulla aliquet enim tortor. Massa massa ultricies mi quis hendrerit dolor magna eget est. Commodo nulla facilisi nullam vehicula. Scelerisque viverra mauris in aliquam sem fringilla ut morbi. Tortor vitae purus faucibus ornare suspendisse sed nisi lacus. Ut porttitor leo a diam sollicitudin tempor id eu. Nulla facilisi nullam vehicula ipsum a arcu cursus vitae. Nulla malesuada pellentesque elit eget gravida cum sociis natoque penatibus. Curabitur gravida arcu ac tortor dignissim convallis. Scelerisque eu ultrices vitae auctor eu augue ut. Nunc mi ipsum faucibus vitae. Vivamus arcu felis bibendum ut. Ultrices vitae auctor eu augue ut lectus arcu.';

  // =============== ELEMENTS =============== //

  const body = document.body;

  const container = document.createElement('div');
  container.className = 'container';

  const header = document.createElement('header');

  const headerContent = document.createElement('div');
  headerContent.className = 'header-content';

  const logo = document.createElement('div');
  logo.className = 'logo';
  logo.textContent = '📚';
  logo.style.color = colors.tomatoRed;
  logo.style.border = `0.2rem solid ${colors.tomatoRed}`;

  const dropdown = document.createElement('div');
  dropdown.className = 'dropdown';

  const dropBtn = document.createElement('button');
  dropBtn.className = 'drop-btn';
  dropBtn.textContent = 'Preferences';

  const dropContent = document.createElement('div');
  dropContent.className = 'drop-content';
  
  const light = document.createElement('a');
  light.textContent = 'Light Mode';
  light.href = '#';
  light.addEventListener('click', () => {
    isLight = true;
    [isDark, isRed] = [false, false];
    renderTheme();
  });
  
  const dark = document.createElement('a');
  dark.textContent = 'Dark Mode';
  dark.href = '#';
  dark.addEventListener('click', () => {
    isDark = true;
    [isLight, isRed] = [false, false];
    renderTheme();
  });

  const red = document.createElement('a');
  red.textContent = 'Red Mode';
  red.href = '#';
  red.addEventListener('click', () => {
    isRed = true;
    [isLight, isDark] = [false, false];
    renderTheme();
  });

  const main = document.createElement('main');

  const h1 = document.createElement('h1');
  h1.textContent = headline;
  h1.style.marginTop = '3rem';

  const h3 = document.createElement('h3');
  h3.textContent = subheadline;

  const details = document.createElement('p');
  details.textContent = `${publishDate} | Written by ${author}`;
  details.style.fontSize = '0.9rem';

  const p1 = document.createElement('p');
  p1.textContent = copy1;
  p1.style.lineHeight = '1.8rem';

  const p2 = document.createElement('p');
  p2.textContent = copy2;
  p2.style.lineHeight = '1.8rem';

  // =============== Functions =============== //

  function applyLight() {
    body.style.backgroundColor = colors.lightGray;
    header.style.backgroundColor = colors.lightGray;
    dropBtn.style.color = colors.darkGray;
    dropBtn.style.border = `0.1rem solid ${colors.darkGray}`;
    dropContent.style.backgroundColor = colors.lightGray;
    dropContent.style.border = `0.1rem solid ${colors.darkGray}`;
    light.style.color = colors.almostBlack;
    dark.style.color = colors.almostBlack;
    red.style.color = colors.almostBlack;
    main.style.backgroundColor = colors.white;
    h1.style.color = colors.darkGray;
    h3.style.color = colors.darkGray;
    details.style.color = colors.warmGray;
    p1.style.color = colors.darkGray;
    p2.style.color = colors.darkGray;
  }

  function applyDark() {
    body.style.backgroundColor = colors.almostBlack;
    header.style.backgroundColor = colors.almostBlack;
    dropBtn.style.color = colors.lightGray;
    dropBtn.style.border = `0.1rem solid ${colors.lightGray}`;
    dropContent.style.backgroundColor = colors.almostBlack;
    dropContent.style.border = `0.1rem solid ${colors.lightGray}`;
    light.style.color = colors.white;
    dark.style.color = colors.white;
    red.style.color = colors.white;
    main.style.backgroundColor = colors.darkGray;
    h1.style.color = colors.gray;
    h3.style.color = colors.gray;
    details.style.color = colors.warmGray;
    p1.style.color = colors.gray;
    p2.style.color = colors.gray;
  }

  function applyRed() {
    body.style.backgroundColor = colors.red;
    header.style.backgroundColor = colors.red;
    dropBtn.style.color = colors.tomatoRed;
    dropBtn.style.border = `0.1rem solid ${colors.tomatoRed}`;
    dropContent.style.backgroundColor = colors.red;
    dropContent.style.border = `0.1rem solid ${colors.tomatoRed}`;
    light.style.color = colors.tomatoRed;
    dark.style.color = colors.tomatoRed;
    red.style.color = colors.tomatoRed;
    main.style.backgroundColor = colors.darkRed;
    h1.style.color = colors.tomatoRed;
    h3.style.color = colors.tomatoRed;
    details.style.color = colors.lightRed;
    p1.style.color = colors.tomatoRed;
    p2.style.color = colors.tomatoRed;
  }

  function renderTheme() {
    if (isLight === true) {
      light.textContent = 'Light Mode ✓';
      applyLight();
    } else {
      light.textContent = 'Light Mode';
    }
    if (isDark === true) {
      dark.textContent = 'Dark Mode ✓';
      applyDark();
    } else {
      dark.textContent = 'Dark Mode';
    }
    if (isRed === true) {
      red.textContent = 'Red Mode ✓';
      applyRed();
    } else {
      red.textContent = 'Red Mode';
    }
  }

  function addContent() {
    body.appendChild(container);
    container.appendChild(header);
    container.appendChild(main);
    header.appendChild(headerContent);
    headerContent.appendChild(logo);
    headerContent.appendChild(dropdown);
    dropdown.appendChild(dropBtn);
    dropdown.appendChild(dropContent);
    dropContent.appendChild(light);
    dropContent.appendChild(dark);
    dropContent.appendChild(red);
    main.appendChild(h1);
    main.appendChild(h3);
    main.appendChild(details);
    main.appendChild(p1);
    main.appendChild(p2);
  }
  
  addContent();
  renderTheme();

});
              
            
!
999px

Console