CSS Animations
Posted in
2713
1:36 am, April 28, 2022
Smooth Scrolling with just CSS
Did you know that you can add smooth scrolling to your page with one line of css?
So what is the magic line?
scroll-behavior: smooth;
Yep thats all you have to add.
Lets add a demo of scroll-behavior: smooth;
How does this work?
You can apply this to your whole page using the following css:
html {
scroll-behavior: smooth;
}
to test the scrolling, we can add some anchors and then some fixed height elements to force the scrolling, so rather than the page jumping to the next element it should scroll to the next element.
CSS Smooth Scroll Preview
Smooth Scrolling with just CSS Demo
View Demo Full Screen View Demo New Tab
Smooth Scrolling with just CSS Code
HTML
<nav class="fixed-nav">
<a href="#pd1" class="jump-link">1</a>
<a href="#pd2" class="jump-link">2</a>
<a href="#pd3" class="jump-link">3</a>
<a href="#pd4" class="jump-link">4</a>
</nav>
<div class="pd pd1 center" id="pd1">Padding Div 1</div>
<div class="pd pd2 center" id="pd2">Padding Div 2</div>
<div class="pd pd3 center" id="pd3">Padding Div 3</div>
<div class="pd pd4 center" id="pd4">Padding Div 4</div>
CSS
html {
scroll-behavior: smooth;
}
.fixed-nav {
position:fixed;
top:0px;
left:auto;
}
a.jump-link {
display:inline-block;
padding:10px;
border-radius:5px;
}
.center {
display: flex;
align-items: center;
justify-content: center;
}
.pd {
height:300px;
width:100%;
}
.pd1 {
background:pink;
color:FFF;
}
.pd2 {
background:blue;
color:FFF;
}
.pd3 {
background:teal;
color:FFF;
}
.pd4 {
background:orange;
color:FFF;
}
Add Comment
Other Items in CSS Animations
Smooth Scrolling with just CSS
Radial Glow under cursor on box hover over effect
Pure CSS 3D Flipping Book with Animations
button animations hover and fill animation
button on focus swing animation
Animated Button Border when Active
Single Element CSS Spinners
CSS Shake - Shake up your elements
Check Wave Click a Checkbox and Watch the Animation
CSS Typing Effect using just CSS
Related Search Terms
Other Categories in Code
404 pages animation animations background effects boxes buttons css css & javascript css animation css animations css backgrounds css cursors css framework css frameworks css modal css positions css reset css shadows css slider css text effects css text formatting css tips css tools css z-index content slider cookie alerts design html css sections html canvas html sections icons image zoom interactive images lightbox link effects loading animation modals mouse effects navigation notifications parallax profiles quick css seo sections text ui web developer checklists animations backgrounds bootstrap buttons css css animated css animations css framework css grid footers forms html image effects images javascript scroll effects sections show your work svg text animation timeline
css animations
HTML Canvas
javascript