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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <main>
  <h2> <code>download</code> 属性与 `Data URI` + `JavaScript` 让用户下载自定义HTML</h2>

  <p>在文本框中输入一些HTML,然后使用“Download HTML”链接下载您刚刚创建的内容。然后可以在系统上查看HTML文件。它使用了download属性,以及一个数据URI和一些JavaScript来完成这项工作。</p>
  <textarea id="txt" cols="60" rows="7"><body><p>一些HTML内容</p></body></textarea>
  <p><a href="nothing.html" id="link" download="code.html">作为HTML下载</a></p>

</main>
              
            
!

CSS

              
                body {
  font-family: Arial, sans-serif;
  font-size: 20px;
  padding: 0 20px;
}

main {
  text-align: center;
  margin: 0 auto;
  max-width: 800px;
}

p {
  text-align: left;
  padding: 0 20px;
}

p:last-of-type {
  text-align: center;
}

code {
  color: firebrick;
}
              
            
!

JS

              
                function downloadCode(link, code) {
  link.href = 'data:text/html;charset=utf-8,' + code;
}

document.getElementById('link').addEventListener('click', function () {
  downloadCode(this, txt.value);
}, false);
              
            
!
999px

Console