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

              
                <h1>titre 1</h1>

<p>
  prefers-color-scheme : 
<strong class="pcs-dark">dark</strong>
<strong class="pcs-light">light</strong>
</p>

<p>
  <button class="js--toggle-mode" aria-pressed="false">
    Change mode
  </button>
</p>

<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatum consectetur placeat dolore sequi unde ullam quasi veritatis dignissimos quo eius, sed ad aliquam eveniet voluptas? Saepe eius iure sed laborum.</p>
<div class="invert">
  <p>
    Lorem, ipsum dolor sit amet consectetur adipisicing elit. Ullam, ab accusamus suscipit voluptatem iure mollitia quia placeat voluptas aliquam porro ex aliquid, laborum beatae odio quisquam! Deserunt facilis nulla quam.
  </p>
</div>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatum consectetur placeat dolore sequi unde ullam quasi veritatis dignissimos quo eius, sed ad aliquam eveniet voluptas? Saepe eius iure sed laborum.</p>
<div class="invert">
  <p>
    Lorem, ipsum dolor sit amet consectetur adipisicing elit. Ullam, ab accusamus suscipit voluptatem iure mollitia quia placeat voluptas aliquam porro ex aliquid, laborum beatae odio quisquam! Deserunt facilis nulla quam.
  </p>
  <div class="default">
    <p>
      Lorem, ipsum dolor sit amet consectetur adipisicing elit. Ullam, ab accusamus suscipit voluptatem iure mollitia quia placeat voluptas aliquam porro ex aliquid, laborum beatae odio quisquam! Deserunt facilis nulla quam.
    </p>
  </div>
</div>


<form>
  <input value="Text input" type="text" />
  <input id="checkbox" type="checkbox">
  <label for="checkbox">Checkbox</label>
  <input id="radio" type="radio">
  <label for="radio">Radio</label>
  <textarea>Textarea</textarea>
</form>

<img src="https://placekitten.com/200/300" alt="">


              
            
!

CSS

              
                :root {
  --color1:white;
  --color2:black;
  --color3:#F2F2F2;
  color-scheme: only light; //only pour désactiver le remplacement de couleur du mode nuit de Blink 
}

.dark {
  --color1:#222;
  --color2:#FFF;
  --color3:#555;
  color-scheme: dark;
}

body {
  font-family:system-ui;
  max-width:400px;
  margin: 0 auto;
}


body,
.default {
  background:var(--color1);
  color:var(--color2);
}

.invert{
  background:var(--color3);
  border:5px solid var(--color3);
}

.pcs-dark,
.pcs-light {
  display:none;
}

@media (prefers-color-scheme: light) {
    .pcs-light {display:inline}
}
@media (prefers-color-scheme: dark) {
    .pcs-dark {display:inline}
}
              
            
!

JS

              
                let currentMode = localStorage.getItem('mode');
let root = document.querySelector(':root');
let btn = document.querySelector('.js--toggle-mode');

// récupère le dernier choix de l'utilisateur
if (currentMode == 'dark'){
  
  root.classList.toggle('dark');
  btn.setAttribute('aria-pressed', 'true');
  
} else {
  
  // passe en mode sombre si la préférence utilisateur est a dark
  if (
    window.matchMedia &&
    window.matchMedia("(prefers-color-scheme: dark)").matches
  ) {
    root.classList.toggle("dark");
  }
  
}


// detection de changement de mode navigateur
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
  if(e.matches) {
    root.classList.add("dark");
  } else {
    root.classList.remove("dark");
  }
});



// permet de basculer de mode au clique
document.querySelector("button").addEventListener("click", (e) => {
  event.preventDefault();
  root.classList.toggle("dark");
  if (e.target.getAttribute('aria-pressed') == 'true'){
    e.target.setAttribute('aria-pressed', 'false');
    localStorage.setItem('mode', 'light');
  } else {
    e.target.setAttribute('aria-pressed', 'true');
    localStorage.setItem('mode', 'dark');
  }
});

              
            
!
999px

Console