Tania Rascia

Skip Navigation
Smooth Scroll to ID with jQuery

Smooth Scroll to ID with jQuery

 /  20 responses

Here’s a quick snippet of jQuery code I use often when I need to smoothly scroll to an ID. Just change the 500 to whatever speed (in milliseconds) you want the page to scroll at.

View Demo

$('a[href*="#"]').on('click', function (e) {

	$('html, body').animate({
		scrollTop: $($(this).attr('href')).offset().top
	}, 500, 'linear');


Hi, my name is Tania Rascia. I've turned down every offer for advertisements or sponsored posts on this website. I write free resources that have helped thousands of people successfully transition into a web development career.

My committment is to no bullshit, no sponsored posts, no ads, and no paywalls. If you enjoy my content, please consider supporting what I do.

Support my work


New articles on web development every two weeks.

Write a response

Your email address will not be published.

All code will be displayed literally.