Pen Settings



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


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


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.


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.


                <div id="app" class="app">
  <h1 class="title">Hello, World</h1>
  <p class="subtitle">当前主题:<span id="theme-current">亮色</span></p>
  <button class="theme-switch light" data-theme="light">亮色</button>
  <button class="theme-switch dark" data-theme="dark">暗色</button>


                // 所有主题样式
$bg-color: (
  light: #fff,
  dark: #091a28

$title-color: (
  light: #363636,
  dark: #fff

$subtitle-color: (
  light: #4a4a4a,
  dark: cyan

@mixin themify($key, $valueMap) {
  // theme list
  $themes: light, dark;
  @each $theme in $themes {
    [data-theme=#{$theme}] & {
      #{$key}: map-get($valueMap, $theme);

.app {
  @include themify('background-color', $bg-color);

.title {
  @include themify('color', $title-color);

.subtitle {
  @include themify('color', $subtitle-color);

// light主题色
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;

button {
  color: #4fc08d;

button {
  background: none;
  border: solid 1px;
  border-radius: 2em;
  font: inherit;
  padding: 0.75em 2em;

.theme-switch {
  cursor: pointer;


                const btns = document.querySelectorAll('.theme-switch');
const body = document.body;
const currentThemeNode = document.getElementById('theme-current');

const addEvent = (btn) => {
  btn.addEventListener('click', e => {
    const theme =;
    body.setAttribute('data-theme', theme);
    if(theme === 'light') {
      currentThemeNode.textContent = '亮色';
    } else if (theme === 'dark') {
      currentThemeNode.textContent = '暗色';

btns.forEach(btn => {