Create an animated, circular progress bar

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 พ.ย. 2024

ความคิดเห็น • 124

  • @nitsanbh
    @nitsanbh 8 หลายเดือนก่อน +24

    There’s the tag which is specifically designed to only show if JS is disabled

    • @mrgamerzyt3945
      @mrgamerzyt3945 8 หลายเดือนก่อน +2

      I feel so dumb when watching Kevin's videos and comments.

    • @sivashankarivijay2279
      @sivashankarivijay2279 7 หลายเดือนก่อน +1

      ​@@mrgamerzyt3945 Lmao, chill, you're not

  • @QuantumCanvas07
    @QuantumCanvas07 8 หลายเดือนก่อน +30

    I'm new to this channel and to the web dev as well and now I can see why he's called a CSS God.
    Keep it up Kevin!

    • @granthaley6110
      @granthaley6110 7 หลายเดือนก่อน +2

      Kevin is a great youtuber to watch when learning front-end. However I would not recommend watching a video as advanced as this during the beginning of your journey.

    • @wakanitchu
      @wakanitchu 7 หลายเดือนก่อน

      @@granthaley6110 what would you recommend then ?(assuming we have some basis)

  • @odagora
    @odagora 7 หลายเดือนก่อน +2

    That's great, Kevin! A few months ago, I was working on a Pomodoro Timer with a circular progress bar that progressively changed its color to simulate the 'good,' 'warning,' and 'alert' states as the countdown reached 100%. Initially, I struggled with the ring animation at the beginning and end of the countdown, but I saw how you solved it in this video, and it's amazing. Thank you for sharing such useful videos!

  • @michaelhaddad2190
    @michaelhaddad2190 8 หลายเดือนก่อน +105

    It took me years to realize Kevin says “my front end friends”, and not “my friend and friends”

    • @dankierson
      @dankierson 8 หลายเดือนก่อน +11

      And I only know it because of you 😅

    • @schnurzpiepe5816
      @schnurzpiepe5816 8 หลายเดือนก่อน +3

      Such as me. Thanks mate 😂

    • @tocj
      @tocj 8 หลายเดือนก่อน +2

      Bro you just saved me years

    • @LuisBlancoAustin
      @LuisBlancoAustin 8 หลายเดือนก่อน +7

      LOL! I was always wondering why he would say, "Friend and Friends."

    • @everybot-it
      @everybot-it 8 หลายเดือนก่อน +1

      oh!!!!!!

  • @austineban4811
    @austineban4811 4 หลายเดือนก่อน

    I just want to comment that I have seen only three of your tutorials and I really love the way you teach. It is obvious that he is grounded in what he is teaching

  • @unl0ck998
    @unl0ck998 8 หลายเดือนก่อน +10

    +30 min single css trick, you know its a banger.

  • @seitbekir
    @seitbekir 7 หลายเดือนก่อน

    In 2017 I had a task to make an animated partial circular chart. And I've been using SVG as an only option. I'm glad to see that just in 7 years browsers begun to get close to the solution.

  • @VasilyPavlik
    @VasilyPavlik 6 หลายเดือนก่อน +1

    Two weeks ago I struggled with the same task. And all my steps were very similar to yours. But finally I switched to SVG :)
    SVG is drawn much nicer on small sizes due to good scaling with antialiasing and stroke-linecap=round. Borders on small sizes looks ugly.
    But it was a very good experience. Nice to see that approach here :) Thank you

  • @repenning1
    @repenning1 7 หลายเดือนก่อน +1

    Very cool. One limitation, however, is that the cut out in the middle will not work on transparent backgrounds, such as diffuse glass, as it covers them up. To make this work you can combine background: with mask: like this "mask: radial-gradient(circle, transparent 60%, black 60%);" This will blow also the number in the middle away but you can wrap up the progress bar with another containing div and stick an absolutely positioned sibling div to get the number back.

  • @Adesignl
    @Adesignl 7 หลายเดือนก่อน

    This is probably one of my favorite videos you have done in a while.

  • @clevermissfox
    @clevermissfox 8 หลายเดือนก่อน +4

    A video on what is valid in the “content” property might be fun. I know you can use an svg but I always forget how. And I didn’t realize you would be able to add % after the attr()!

  • @estheraidenojie6995
    @estheraidenojie6995 5 หลายเดือนก่อน

    You're the boss man
    Broke it down to my level smoothly

  • @yoshmarklund
    @yoshmarklund 8 หลายเดือนก่อน +1

    I was just looking at making circular progress bars yesterday, what a coincidence :D

  • @kevinwaag9976
    @kevinwaag9976 7 หลายเดือนก่อน +1

    impressive skills! I love that content attr() "%"! with the display grid. Very clever

  • @danielcrompton7818
    @danielcrompton7818 8 หลายเดือนก่อน

    Hey Kevin! I love these CSS videos and the style of them. It’s always so interesting seeing your approach to things and how you tackle them using obscure CSS tricks that live at your fingertips!!! Would you ever consider building a full front end web dev course? That would be great to see too!

  • @empedocle
    @empedocle 8 หลายเดือนก่อน

    As always great video Kevin, it is always nice and deeply inspiring to watch you while coding some css! Warm greetings from Italy

  • @nicholaschu203
    @nicholaschu203 8 หลายเดือนก่อน

    This is awesome. You just have me a playful idea to animate a custom countdown timer that ends with a SVG status. Time to code 😁

  • @RobBulmahn
    @RobBulmahn 8 หลายเดือนก่อน +1

    8:25 I'd handle determining whether JS has loaded by simply using JS to clear out or hide the placeholder span. That way, it shows up by default, but gets removed if everything is working correctly, and it's pretty straightforward to target just the span, which could have its own class/ID.

  • @QwDragon
    @QwDragon 8 หลายเดือนก่อน +1

    Great! More accessability tricks, please!
    PS: I would've use svg or clip-path.
    PPS: You could've keep conic gradient as final background and animate color to green.
    Also I would've place checkmark inside of the progressbar, so its appearenca can be animated too.

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน

      Yeah, I thought about animating the check in, but got lazy 😂

  • @pokefreak2112
    @pokefreak2112 8 หลายเดือนก่อน +1

    Thanks Kevin! Always something new to learn about CSS from these videos.
    Question: do you know of any way to add a "border radius" to the circular progress bar with CSS or would you need to resort to SVG?

    • @pokefreak2112
      @pokefreak2112 8 หลายเดือนก่อน

      Actually I just thought of something: you could add a round (pseudo) element that acts as your line cap and move it around using the trig functions 😄
      But I'd still love to hear of any other ways to achieve this

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน

      Not completely sure what you mean? Instead of a circle, to be more of a rounded square? I'd do it the same way I think. If you update the codepen I linked in the description so the border-radius is, say, 20px, it works. The only issue is the inner one should be smaller than the outer one, but you could get that to work with a calc() and an extra custom property, something like border-radius: calc(var(--border-radius) - var(--border-size)) // the border might have to be divided by 2, not sure :D

    • @pokefreak2112
      @pokefreak2112 8 หลายเดือนก่อน

      @@KevinPowell I mean keeping it a circle but having the actual inner progress indicator have a round cap instead or a sharp edge.
      like stroke-linecap="round" in svg

  • @pascalpp
    @pascalpp 7 หลายเดือนก่อน

    Recently discovered this bit of magic: grid-template-columns: repeat(auto-fill, minmax(35ch, 1fr));
    No breakpoints required!

  • @pashko-k6h
    @pashko-k6h 8 หลายเดือนก่อน

    I'm a simple man, I see a new vid from Kevin, I give it a like before I start watching

  • @cintron3d
    @cintron3d 8 หลายเดือนก่อน

    conic-gradient for the progress bar - nice. I actually would really like to learn the svg method as that has a lot more possible applications.

  • @marklnz
    @marklnz 8 หลายเดือนก่อน +1

    Nice. I'm gonna go try to make this actually work without JavaScript now :)

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน +1

      I had a version with checkboxes that worked with :has(), but it was a bit messy :D

    • @marklnz
      @marklnz 8 หลายเดือนก่อน

      @@KevinPowell I was thinking more of using Web Assembly...is that cheating maybe? 🤷‍♀

    • @marklnz
      @marklnz 8 หลายเดือนก่อน

      Built a version of it using Blazor WebAssembly. The actual progress indicator has one line of code in it - a property declaration - the rest is pure HTML + CSS. I used SVG for the circle in the end, as it seemed to be less code, and I'm less familiar with SVG. End result isn't 100% right graphically (I haven't colored the background green on completion, for example) but it's pretty good. Was a fun little exercise!

  • @rankarat
    @rankarat 8 หลายเดือนก่อน

    The correct way is to go with svg with display grid and 2 circles inside it stack on each other. super easy to animate too.

  • @vilijanac
    @vilijanac 8 หลายเดือนก่อน +1

    Very good, it is complex. And 'aria-valuenow' as attribute for some reason isn't 'aria-value-now'.

  • @robertholtz
    @robertholtz 4 หลายเดือนก่อน +1

    Never heard anyone else pronounce "Javascript" like that. JEAH-VAW? (First syllable rhymes with "Yeah.") I've always heard it JAW-VAW. Is that a Canadian thing? You also jump back and forth between the Canadian pronunciation of the word "progress" which, for Americans is "prog-gress" and for Canadians seems to be "pro-gress" (as in professional gress? lol). I tried not to let this distract me but here I am.

  • @Dorgrident
    @Dorgrident 8 หลายเดือนก่อน +3

    add selectors for your js to the elements. a class prefixed with js- for example, or a data attribute. never js on classes used for styling.

    • @dealloc
      @dealloc 8 หลายเดือนก่อน

      for interactions, absolutely. but for applying styling, animations and transitions it's OK to change the classList based on the state, and even select it. Though, you're probably better off using the Web Animation API :)

    • @Dorgrident
      @Dorgrident 8 หลายเดือนก่อน

      Someone will come and remove that class "hide-on-mobile" and does not expect that there is a whole js library behind this class. In my eyes its very bad practice to combine a styling class with a js functionality.@@dealloc

  • @NashBrooklyn
    @NashBrooklyn 8 หลายเดือนก่อน +1

    that is nice and has been done and done by many - but the trickier one is in reverse though -

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน +1

      What do you mean by in reverse? 🤔

    • @NashBrooklyn
      @NashBrooklyn 8 หลายเดือนก่อน +1

      @@KevinPowell - a countdown

  • @nomadshiba
    @nomadshiba 8 หลายเดือนก่อน

    2:35 little bit of all:unset always helps

  • @luketurner314
    @luketurner314 8 หลายเดือนก่อน

    0:31 in my head is Matt Gray saying, "at the beginning of that paragraph I thought you were talking about piccalilli"

  • @Nedrafehi
    @Nedrafehi 8 หลายเดือนก่อน +1

    Instead of hard-coding the fill colour in the SVG, you could instead use `currentColor`

  • @vincentjacquet2927
    @vincentjacquet2927 8 หลายเดือนก่อน

    Nice and I really appreciate you showing how to use the aria attributes, but I wondering why you are not using a custom element instead of a div here. The code is pretty straightforward: you setup the attributes in the constructor, you observe attribute aria-valuenow to set --progress whenever its value changes and attaching the shadow dom will hide the content.
    You can then decide, if you want to, where to put the styles: in the global CSS or in a style element within the custom element?

  • @madhav3444
    @madhav3444 7 หลายเดือนก่อน

    That was good, could you also create a Knob component

  • @sergiobeemer6012
    @sergiobeemer6012 7 หลายเดือนก่อน

    Kevin again a great video. Thank you so much.
    I do have a question: How can we use this if the real background was an image. Can we make the center background (covering the gradient) transparent in any way and still have it work? With clips or something?

  • @jfftck
    @jfftck 8 หลายเดือนก่อน

    This video could be expanded on to use custom elements, this would make the whole progress bar into a new component and it would be reusable.

  • @brankoh
    @brankoh 7 หลายเดือนก่อน

    What about using an eventListener for "animationEnd" to switch the 100% for a check mark? Great video as always!

  • @not_amanullah
    @not_amanullah 7 หลายเดือนก่อน

    This is helpful ❤

  • @LePhenixGD
    @LePhenixGD 8 หลายเดือนก่อน

    2:15 I created a full CSS reset style for all annoying to style HTML elements in a CodePen, if you want I could give you the link to the pen

  • @not_amanullah
    @not_amanullah 7 หลายเดือนก่อน

    Thanks ❤

  • @holgerflick
    @holgerflick 7 หลายเดือนก่อน

    Thank you for all your great videos. I have one remark. When watching your videos on Apple TV or streaming them to another device, the "in video" links do not appear. Please list all links in the comments and do not rely on the in-video links. Thank you.

  • @bryant8484
    @bryant8484 7 หลายเดือนก่อน

    Pretty cool

  • @beinyourguard
    @beinyourguard 8 หลายเดือนก่อน

    Kevin, what is the difference between using classes and attributes as css selectors, and why do you prefer using attributes?

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน +1

      No difference. I like using attributes especially when it enforces accessibility, like it does here

    • @beinyourguard
      @beinyourguard 8 หลายเดือนก่อน

      ​@@KevinPowell thanks!

  • @deadlyecho
    @deadlyecho 8 หลายเดือนก่อน +2

    If a client of mine doesn't use JS, I will tell him to Fuck off 😂😂

  • @pauliusliberis8723
    @pauliusliberis8723 8 หลายเดือนก่อน

    Well… I think it’s a bit buggy with animation, as you are changing value to new value while progress bar reaches it after 500ms only. So it is kind of working but with latency of animation duration 😅
    Another question is why you were able to add “%” to content property in css, but it wasn’t possible to do the same thing with conic-gradient property?
    Everything else is perfect 🤩

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน

      Yeah, the animation is slightly behind, but I don't think that's a big deal 😊. No way of anticipating where it'll be, so I'm happy with that for a simple visualization.
      As for the custom property, I had to use @property so I could animate the custom property, otherwise it worked fine, unless I misunderstood what you were pointing put

  • @hanesmitter1469
    @hanesmitter1469 8 หลายเดือนก่อน

    I was waiting to see how he will animate that bar(without using SVG)
    I thought I'd see him struggle and boom 💥 💥.... he just used conic gradient😂

  • @pawejakubowski829
    @pawejakubowski829 7 หลายเดือนก่อน

    Am I right that it applies only when we have perfect circle? When we change aspect-ratio of both and set border-radius for 5px it will broke? Is there any other solution instead of iconic gradient in that situation?

  • @sitedel
    @sitedel 7 หลายเดือนก่อน

    I don't understand why you didn't use SVG to make all the graphics instead of CSS.
    With SVG you could move the end of a line around a path, put a circle of a rectangle on this end to act like a volume rotative button cursor and improve readability of the transition between the black round line and the grey round path.
    You could even use SVG animation elements to be triggered on not started (0% of the CSS animation)/starting (1%)/ending (99%)/completed(100%) states.
    This way all animation logic is embedded in the SVG file, so you can easily switch to a file with different or no idle animation if the media query "prefer-reduced-motion" is set.

  • @SoapMcCormick
    @SoapMcCormick 8 หลายเดือนก่อน

    Could you please make a video about zoom transitions? While scrolling.. for example you see the backside of a Camera and while scrolling it Zooms through the Viewfinder and shows the Picture (took with certain camera)

  • @deatho0ne587
    @deatho0ne587 8 หลายเดือนก่อน

    Quiz use something like SSG with Astro + HTMX and 0 JS is needed. Each pick sends off a call for an update to the Progress thing.
    Uploading a file with a progress bar at best is guess and at worst is fake, so fake it while not using JS anyways.

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน +1

      If you're using htmx you're using JS though... maybe not writing it yourself, but it's happening behind the hood. I could have skipped the bit where I looked at how I was faking it I guess, and it's why I skipped over the loading part, but figured some people would want to see the general idea of what's happening there. Also, if I used Astro and HTMX, I'd lose 50+% of my audience, who are often beginners.

    • @deatho0ne587
      @deatho0ne587 8 หลายเดือนก่อน

      I do fully understand and it is good for the general concept, due to most of the important bits are CSS.

    • @marcoceriani1069
      @marcoceriani1069 8 หลายเดือนก่อน

      @@KevinPowellI discovered this just this week: you can write a page with and periodically reload the entire page, without javscript. You can use it to update the progress bar with a value provided by the backend. But apart from proving that it is possible, why would anyone do it on a real website?

  • @uiaugust97
    @uiaugust97 8 หลายเดือนก่อน

    Can you make it work with scroll? A circular scroll indicator that turns to a back to the top button on hover

  • @D7460N
    @D7460N 8 หลายเดือนก่อน

    Does CSS nesting scope the rule to its nested context?

  • @StellarWeb008
    @StellarWeb008 8 หลายเดือนก่อน

    Kevin one day I was really stuck in styling 4 options of a MCQ quiz. They were expected to line up in 2 by 2 grid by default & they would stack vertically if the content couldn't fit in the given width. I wanted to do it css only. But I tried & tried & couldn't even do it with javascript. I just quit the idea & let them stay 2 by 2 always. What could be a solution to this?

  • @AleksanderFimreite
    @AleksanderFimreite 8 หลายเดือนก่อน

    Reply to 22:27... Just going to throw a wildcard suggestion in here.
    You later discover that the value does not work because it need's a percent character.
    Can you add it using the same trick there with the attr(aria-valuenow) "%"
    Or does it not accept this syntax?

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน +1

      Really wish we could do that, but for now, attr() can only be used as content and nothing else. It's supposed to be expanded on, but hasn't been yet afaik

  • @lronmate
    @lronmate 7 หลายเดือนก่อน

    You didn't put a link to mdn of the list of houdini syntax options!

  • @albertoalonso4211
    @albertoalonso4211 7 หลายเดือนก่อน

    🐐

  • @diegognoatto8706
    @diegognoatto8706 8 หลายเดือนก่อน

    one of the first things in programing AI would dominate first is CSS, boy i coudnt be more wrong, its horrendous in been helpfull with css. it can help you to creata a whole apliaction in javascript before it can debug why my blue text is red. i guess u got more fat to burn with a mainly css channel for sometime. nice tips as aways

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน

      Yeah, CSS is way to context dependant for AI. JS has the advantage where you want to isolate things as much as possible, and there isn't the visual interaction within layouts. I don't think AI is going to be taking over any langauges anytime soon either though. That last 1-2% that it might need to get there is the hardest part and will take a long time.

  • @legostud
    @legostud 8 หลายเดือนก่อน

    If JS is not enabled, then you’d need to rely on server side code to adjust the markup.

  • @rafa6536
    @rafa6536 8 หลายเดือนก่อน

    How to make PRE to have max 100% parent width? When a line in PRE is long it stretches whole site with horizontal scroll. I want PRE to have horizontal scrollbar and not whole site. It works when containter containing PRE have fixed width, but it can't, have to adjust and can't be fixed. Thanks for video, as always awesome :)

    • @rafa6536
      @rafa6536 8 หลายเดือนก่อน

      It's something connected to grid... When I removed grid, so my PRE is not in container which is grid element everything is working fine, no body overflowing and horizontal scrollbar is on PRE like it should. But it have to work in grid layout, and how make it work I have no idea :P

    • @rafa6536
      @rafa6536 8 หลายเดือนก่อน

      Found it, CSS Tricks: "Preventing a Grid Blowout". It's "min-width: 0 problem". Didn't know about that :) changing minmax(auto, 1320px) to minmax(0, 1320px) solved the problem :)

  • @merzaad
    @merzaad 8 หลายเดือนก่อน

    cooooooooooooool

  • @ROL4ND-CSS
    @ROL4ND-CSS 8 หลายเดือนก่อน

    Also love your take @KevinPowell

  • @Alex-Shohet
    @Alex-Shohet 8 หลายเดือนก่อน

    but how to make the center circle transparent, not white?

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน +1

      I'd use an SVG instead then, and just have it follow the stroke, with no fill on it

  • @yanikkendler
    @yanikkendler 8 หลายเดือนก่อน

    i dislike that you didnt animate the Background color at the end :c

  • @RichardCalder67
    @RichardCalder67 8 หลายเดือนก่อน +24

    The question "what if the user doesn't have javascript enabled" is a pointless thing to ask in 2024. The majority of things people interact with on the web use JS. Social media won't work without it. It is actually hard to turn off now. I don't get why people ask this now. It is a bit like designing cities around horse and buggies at this point.

    • @Killyspudful
      @Killyspudful 8 หลายเดือนก่อน +5

      If you've ever been in an area with poor wifi or other signal issues (e.g. on a plane, in a building with a metal frame, or many places abroad), it's absolutely possible for a page's JS not to load. There might also be problems with server timeouts and many other network errors that can occur. It's probably not vital that this progress widget works in all circumstances, but there are plenty of instances where a dev needs to consider these worse-case scenarios. They're more common than you might think.

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน +12

      There are people who enable JS on a site-by-site basis. It might not be a lot of people, but they are out there. Now, if you're creating something where the entire functionality relies on JS, then yeah, you don't need to worry at all. If I have a mostly static site that has a few extras, then there's no reason not to progessively enhance it

    • @SimonLYW
      @SimonLYW 8 หลายเดือนก่อน +3

      @@KevinPowellthere are also platforms, like Zoho, where JS just isn’t an option for building front ends.

    • @jotajaviergonzalezgarcia7504
      @jotajaviergonzalezgarcia7504 8 หลายเดือนก่อน +1

      I dont have it enabled by default

    • @RedVelocityTV
      @RedVelocityTV 8 หลายเดือนก่อน +1

      IKR! might as well build a site for Internet explorer 😂

  • @yasser2768
    @yasser2768 8 หลายเดือนก่อน +1

    First

  • @dominotrix
    @dominotrix 8 หลายเดือนก่อน

    Would be cool to have a TLDR version at the start for people who doesn't have 35 mins to spend.

    • @KevinPowell
      @KevinPowell  8 หลายเดือนก่อน

      Finished code is in the description for that 😊

  • @animator8024
    @animator8024 7 หลายเดือนก่อน

    Please speak mese adam befahmim chi migi American ha ham nemifahman