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

              
                <a href="#content1">コンテンツ1へ移動</a>
<a href="#content2">コンテンツ2へ移動</a>
<a href="#content3">コンテンツ3へ移動</a>
<a href="#content4">コンテンツ4へ移動</a>
<a href="#content5">コンテンツ5へ移動</a>
<a href="#content6">コンテンツ6へ移動</a>
<h2 id="content1" class="main">コンテンツ1</h2>
<h2 id="content2" class="main">コンテンツ2</h2>
<h2 id="content3" class="main">コンテンツ3</h2>
<h2 id="content4" class="main">コンテンツ4</h2>
<h2 id="content5" class="main">コンテンツ5</h2>
<h2 id="content6" class="main">コンテンツ6</h2>
<a href="#content1">コンテンツ1へ移動</a>
<a href="#content2">コンテンツ2へ移動</a>
<a href="#content3">コンテンツ3へ移動</a>
<a href="#content4">コンテンツ4へ移動</a>
<a href="#content5">コンテンツ5へ移動</a>
<a href="#content6">コンテンツ6へ移動</a>
              
            
!

CSS

              
                	.main {
			height: 300px;
		}
		#content1,#content4  {
			background-color:pink;
		}
		#content2,#content5 {
			background-color:aqua;
		}
		#content3,#content6 {
			background-color:lime;
		}
              
            
!

JS

              
                		window.addEventListener('load', (event) => {

      document.querySelectorAll('a[href^="#"]').forEach(e => e.addEventListener('click', function(e){
        
        //a要素のクリックイベントをキャンセル。
        e.preventDefault();
        
        //a要素が持つhref属性の値を取得。(#content1のように先頭に#が付いた状態で取得される。)
        let target = e.target.getAttribute("href");
        
        //指定した要素までの距離を取得。
        let targetTop = document.querySelector(target).getBoundingClientRect().top  + window.pageYOffset;
        
        let scrollOptions = {
          left: 0,
          top: targetTop,
          behavior: 'smooth'
        }
        
        //指定した要素へスクロールする。
        window.scrollTo(scrollOptions);
      }));
                                                                      
		});
              
            
!
999px

Console