Create a "Scroll To Top" Button with HTML, CSS & JavaScript | Web Design Tutorial For Beginners

Поділитися
Вставка
  • Опубліковано 4 жов 2024
  • In this video we're going to create a "Scroll To Top" button using plain HTML, CSS and JavaScript - this is super easy to do and it is completely optional to use a library to achieve this.
    While not necessary, I'm using Google Material Icons in this video along with jQuery for greater cross-browser support.
    Google Material Icon Set:
    material.io/to...
    google.github....
    Support me on Patreon:
    / dcode - with enough funding I plan to develop a website of some sort with a new developer experience!
    For your reference, check this out:
    developer.mozi...
    Follow me on Twitter @dcode!
    If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
    #css #javascript #dcode

КОМЕНТАРІ • 94

  • @bellatobe
    @bellatobe 5 років тому +6

    What a brilliant video, I'm a real novice to JS and you explained this so easily. Thank you for your video, I was able to add a nice scroll button to my website with a gradient background color for a bit of a 3d effect. Thanks again, I'm a new subscriber!

  • @tiagodepizzol238
    @tiagodepizzol238 2 роки тому

    Thanks! I'm from Brazil and you saved my life!

  • @suyashkumar0312
    @suyashkumar0312 3 роки тому +2

    Your keyboard has the most satisfying sound to me

  • @cani8846
    @cani8846 5 років тому +7

    wow, i didnt know that u can make such effect so easily!

  • @uodige1
    @uodige1 10 місяців тому

    thank you for your tutorial, it was very easy to follow and added this icon the website.

  • @bimsarashrestha7341
    @bimsarashrestha7341 4 роки тому +3

    Lovely. Very helpful. Thanks for the tutorial, man.

  • @malekgtx3549
    @malekgtx3549 5 років тому +2

    La verdad es que dispones de un muy buen contenido me estoy viciando viendo tus vídeos y aprendiendo y expandiendo mis conocimientos sigue así tienes talento para esto Gracias y un saludo

  • @yusufrazakhan2443
    @yusufrazakhan2443 2 роки тому

    very simply explained

  • @observatoriodestartups2607
    @observatoriodestartups2607 3 роки тому +1

    Hey Bro, really nice video. You are dynamic and have a such good approach.

  • @behindthescene2727
    @behindthescene2727 3 роки тому

    will try it

  • @koushi_ku
    @koushi_ku 4 роки тому

    thank's bro I learnt something new in video....

  • @hemantpatel1413
    @hemantpatel1413 5 років тому +1

    Nice man ,thanks for sharing keep it up bro.

  • @thiomark7616
    @thiomark7616 4 роки тому +5

    i watched million youtube videos even went to stackoverflow... and all they had to do was show me this

  • @mahvaree
    @mahvaree 2 роки тому

    Thank you dear master

  • @Supermason3000
    @Supermason3000 3 роки тому

    This helped me out a whole lot definitely and very very easily followed. Awesome work.

  • @石楷圻
    @石楷圻 2 роки тому

    Thx for your traching!!!

  • @cjm3997
    @cjm3997 4 роки тому +3

    is it possible to have it not visible the whole time until you scroll down a little?

    • @maxdestil7812
      @maxdestil7812 2 роки тому

      ua-cam.com/video/gphMli74Chk/v-deo.html

  • @TheGhfji
    @TheGhfji 4 роки тому +1

    Thank you soooo much this was perfect!

  • @dhananjayjhala
    @dhananjayjhala 2 роки тому +2

    The button is there even when we are already on the top of the page, Can you tell how to make the button appear only after we scroll down a bit and when we are already on the top of the page to make it disappear?, Also loved the video!

    • @maxdestil7812
      @maxdestil7812 2 роки тому

      ua-cam.com/video/gphMli74Chk/v-deo.html

  • @СашаТюменцев-ш9ь
    @СашаТюменцев-ш9ь 2 роки тому

    thank you so much!

  • @asadullah7372
    @asadullah7372 3 роки тому

    Thank you, this was helpful

  • @petenjs3500
    @petenjs3500 4 роки тому +1

    Awesome thank you so much bro!

  • @itachi-senpaii
    @itachi-senpaii 3 роки тому

    thank u so much .. you're a star .. a bright one .. :)

  • @Zatar-yf8qd
    @Zatar-yf8qd 4 роки тому

    thank you my friend very much ❤❤❤❤

  • @maighandi
    @maighandi 4 роки тому

    Thank you very much!
    Extremely usefull!

  • @elvergalarga121
    @elvergalarga121 4 роки тому

    your awesome dude, thanks!!

  • @ЖумагалиевАлишер-с5м

    No wonder I subscribed to you. Thanks for the video, bro:)😁

  • @dankierson
    @dankierson 6 місяців тому

    Okay but desn't need JS for what it does. An anchor tag with _href="#"_ would do it.
    What if you wanted to make the button disappear at the top screenfull ? Need JS then and event listener for scroll position.

  • @alexkhalamsky3715
    @alexkhalamsky3715 5 років тому +1

    I ve got only one question: how would you embed this functionality to every single page of your website?
    You definitely wouldnt want to copy-paste this code on every page separately.
    Thanks
    By the way,great tutorial,as usual !
    Im a big fan

    • @dcode-software
      @dcode-software  5 років тому +1

      Thanks mate! You can simply include the HTML on every page but keep it in a single file using your server-side language. For example, you can use PHP require_once() to do so.

    • @alexkhalamsky3715
      @alexkhalamsky3715 5 років тому

      Cool!
      Thanks,pal

  • @MeganTownsendPetVoldemort
    @MeganTownsendPetVoldemort 10 місяців тому

    I know the video is 4 years old, but how can I have the button not cross over the footer once the user is at the bottom of the page? Cheers

  • @muhamadhaseeb1774
    @muhamadhaseeb1774 3 роки тому

    You can use the first method and also get the animation, that method is compatible with Internet Explorer and is easiest to implement. You just need to add this 🔽 to your main CSS document on the top. And don't forget to add the javascript code that
    DCODE used for the first methode. It works like a charm!
    html{
    scroll-behavior: smooth;
    }
    *add this to main.css or style.css

  • @MaxMeinz
    @MaxMeinz 4 роки тому

    This is amazing, thank you!

  • @bbf0ab08cb44becfec
    @bbf0ab08cb44becfec 4 роки тому +1

    I noticed that your keyboard is mechanical, and as a keyboard fan I was just curious of which keyboard you use?

    • @dcode-software
      @dcode-software  4 роки тому +1

      Cooler Master MasterKeys Pro S RGB MX Blue

  • @mohamadhoseinmahrooghi1401
    @mohamadhoseinmahrooghi1401 3 роки тому

    perfect thank you a lot

  • @itboostaustralia8498
    @itboostaustralia8498 4 роки тому

    great job, thank you

  • @lailaabdulrahman9138
    @lailaabdulrahman9138 Рік тому

    Thanks alot

  • @Filmreel1
    @Filmreel1 3 роки тому

    Is there any way to make it so when your at the top you can't see it but when you scroll a bit it appears?

    • @maxdestil7812
      @maxdestil7812 2 роки тому

      ua-cam.com/video/gphMli74Chk/v-deo.html

  • @samuellanga
    @samuellanga 3 роки тому

    thank you!

  • @rabisenpai1207
    @rabisenpai1207 3 роки тому +1

    ty so much!

  • @bikramchettri9405
    @bikramchettri9405 5 років тому +1

    Great Content

  • @infinitygameplay1593
    @infinitygameplay1593 3 роки тому

    Me previously: this is going to be so hard... Let's watch this UA-cam video.
    Me after the video: HOW I THIS SO EASY NOW???

  • @mohammedelghazal6077
    @mohammedelghazal6077 3 роки тому

    thanks bro

  • @mavisfromdeaj340
    @mavisfromdeaj340 2 роки тому

    Is it possible to only show the icon when user has scrolled down, that is, the page is more than 0px from the top of the page?

    • @maxdestil7812
      @maxdestil7812 2 роки тому

      ua-cam.com/video/gphMli74Chk/v-deo.html

  • @vencalysek7847
    @vencalysek7847 5 років тому

    Hi I'm just starting with html and css so if my question is weird. But what is difference between this icon function done by JS and #anchor link? Thank you for answer :)

  • @jaydipparmar8027
    @jaydipparmar8027 Рік тому

    Nice

  • @ilovancristian
    @ilovancristian 2 роки тому

    useful

  • @donny533
    @donny533 4 роки тому

    awesome!!!

  • @Haseeb_Gaming
    @Haseeb_Gaming 2 роки тому

    you dont tell us how to hide this button if someone already at top, I mean just want to show this button only when your scroll you page down.

    • @maxdestil7812
      @maxdestil7812 2 роки тому

      ua-cam.com/video/gphMli74Chk/v-deo.html

  • @juansebastiansuarezguerrer4502
    @juansebastiansuarezguerrer4502 2 роки тому

    Alguna forma para que corrra diferente...osea la capacidad de corrrer menos es que me corre muy rapido.

  • @APO725
    @APO725 4 роки тому

    Thanks!!

  • @ecxscariot335
    @ecxscariot335 2 роки тому

    good tutorial. but I can be the only one who had their retinas burned off when he went on the browser right?

  • @johanbn83
    @johanbn83 4 роки тому

    Thanks ! Great. What is the font used in your Visual Studio code settings please ?

  • @ChompingCabbage
    @ChompingCabbage 3 роки тому

    amazing:D

  • @sounak2009
    @sounak2009 5 років тому

    hey man.. thanks for this tutorial. you are doing a great job. i just subscribed to your channel. can you do a video on on scroll animations? like @keyframes acting up when the window is scrolled.. thanks

    • @dcode-software
      @dcode-software  5 років тому

      Hey thanks for subscribing! Do you mind going in further detail?

    • @sounak2009
      @sounak2009 5 років тому

      @@dcode-software hey man. i was wondering if you could do a video on animations when scrolled. like say the grid area is like "header 100vh and then main 150vh"0. when the document is scrolle and reaches the main section the contents of the main section fades in.. or something similar. Sorry i am not that articulate :p

  • @vw6702
    @vw6702 4 роки тому

    Do I have to include JS in the head with a as I do with .css? (p.s.: it's the first time I use JS)

    • @dcode-software
      @dcode-software  4 роки тому

      No, you need to include it using a "script" tag just before the end of the "body".

    • @vw6702
      @vw6702 4 роки тому

      @@dcode-software yes I know, but it does not work, it's just in Grey color

    • @rachitkumarpandey
      @rachitkumarpandey 4 роки тому

      If ur code is in a sperate file u can define

  • @LonelyJester
    @LonelyJester 5 років тому

    hey what is that addon you have for the different viewports?

  • @salmanfaris1441
    @salmanfaris1441 2 роки тому

    how to scroll down to the bottom

  • @ohiwantyoutobelieve
    @ohiwantyoutobelieve 3 роки тому

    it doesnt work for me...

  • @antoinebrun3461
    @antoinebrun3461 5 років тому

    Nice video but do you know if i can use my own scroll top button done on AI and not the one from google ?

    • @dcode-software
      @dcode-software  5 років тому +1

      Yeah sure, if you're talking about the icon then yes

    • @antoinebrun3461
      @antoinebrun3461 5 років тому

      @@dcode-software Thanks for you answer ! Sorry to take your time but i'm kind of like a beginer in HTML CSS stuff so
      basically if i want to replace the icon by my png icon do i have to write something like this in the HTML :
      ...
      ?

    • @dcode-software
      @dcode-software  5 років тому

      Similar to that but do this instead:

    • @dcode-software
      @dcode-software  5 років тому

      Also make sure that you set the image width to 100% to ensure it does not expand over the width of the button.

    • @antoinebrun3461
      @antoinebrun3461 5 років тому

      ​@@dcode-software
      it worked but it seems that the function html button create a background to my png as if it was a jpg. And when I click on my pgn the color change affects this background and not the shape of the png icon.
      Maybe this background is the width of the button ? it only appear when i mouse click on the button or when
      he passes over images (PS: i put css : background: none; )
      Coding is hard xd

  • @zyadthejocker
    @zyadthejocker 3 роки тому

    for me it's under the content

  • @nozarm10000
    @nozarm10000 7 місяців тому +1

    This is one of the most confusing videos I've ever seen. Makes it far more complicated than it has to be...completely explained backwards.