cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <a href="#sectiona">Go to Section A</a> <a href="#sectionb">Go to Section B</a>

<p>Smooth Scrolling HTML Bookmark Links using ES6 JavaScript and the updated version of <code>element.scrollIntoView()</code> method.</p>

<p>The browser's URL is updated each time with a new hash.</p>

<div style="height:400px"></div>

<div id="sectiona">This is section A</div>

<div style="height:100px"></div>

<div id="sectionb">This is section B</div>
            
          
!
            
              a{
  font-size: 120%;
  margin-right: 100px;
}

#sectiona, #sectionb{
  font-size: 140%;
  font-weight: bold;
  text-align: center;
  padding: 20px;
  background: pink;
  width: 50%;
  height: 150px;
}

#sectionb{
  background: purple;
  color: white;
}
            
          
!
            
              let anchorlinks = document.querySelectorAll('a[href^="#"]')

for (let item of anchorlinks) { // relitere 
    item.addEventListener('click', (e)=> {
		let hashval = item.getAttribute('href')
		let target = document.querySelector(hashval)
		target.scrollIntoView({
			behavior: 'smooth'
		})
		history.pushState(null, null, hashval)
		e.preventDefault()
	})
}

            
          
!
999px
Loading ..................

Console