CSS Outline vs Border - differences, advantages, and disadvantages

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024

Комментарии • 176

  • @raqibabdullah775
    @raqibabdullah775 3 года назад +87

    Thanks a lot Kevin! We want animation with outline pls.

  • @ro3843
    @ro3843 3 года назад +2

    If youre a full time/aspiring front end or full stack developer, this channel is a "must". It constantly helps refresh and expand your knowledge base.

  • @artemx100
    @artemx100 3 года назад +17

    Unsure if you think it wasn't worth mentioning or don't know it's a thing but in fact Firefox has a non-standard CSS property to control the outline radius. `-moz-outline-radius`

    • @KevinPowell
      @KevinPowell  3 года назад +5

      Oh nice, thanks for sharing that!

    • @ne9835
      @ne9835 3 года назад

      Cool.

  • @MM_Sheehan
    @MM_Sheehan 2 года назад +1

    You can round the corners of outlines, if the element has round corners:
    div.round_corners {
    background-color: navy;
    border: 2px solid yellow;
    outline: 5px solid navy;
    border-radius: 25%;
    margin: 5rem;
    padding: 2rem;
    height: 50px;
    width: 50px;
    }
    BTW, you explain everything well.

    • @akrembc7951
      @akrembc7951 2 года назад

      that's what I was about to say .. I test it on divs and buttons and it works perfectly fine .. maybe its a new css feature?

  • @uncleelder4922
    @uncleelder4922 2 года назад

    This video solved a fundamental issue I was having with resizable grids using CSS Grid. The 'border' property was causing the grid contents to become misaligned. When I switch to using 'outline', problem solved! THANKS!!

  • @dealloc
    @dealloc 3 года назад +3

    Keep in mind that outline is also used for focus state, which means that if you use outline as an aesthethic for interactive elements, you will loose the accessibility it offers. You can get around this by defining your own focus styles to accommodate this.
    Also you can use box-shadow as an alternative. They can do anything outlines can do but also allows you to add as many shadows as you'd like to a single element. Both outside and inside (inset), with different levels of blur, offset and spread and they can be animated (although be cautious with performance!)
    You can chain shadows by separating each shadow with a comma. Although it will require you to duplicate your box shadows if you'd like to have different variants based on states (e.g. hover, focus, active, etc.) and can be a bit hairy sometimes, but with tools like CSS Variables, and preprocessors like Sass/PostCSS, this can be made quite trivial.

  • @inuke4fun832
    @inuke4fun832 3 года назад +2

    this channel is the single and only reason I have come to enjoy css. I used to hate it but these videos have shown me once you get in the rhythm of writing css there is alot more to love

    • @KevinPowell
      @KevinPowell  3 года назад +1

      That makes me so happy 🥳

  • @naifalrabeei
    @naifalrabeei 3 года назад +11

    3rd comment yay 🤣
    I started learning html and css this month and your channel is a gold mine.

    • @KevinPowell
      @KevinPowell  3 года назад +3

      Awesome, glad that you're enjoying my content and I hope your having fun making some sites!

    • @shaikhabdulazim6908
      @shaikhabdulazim6908 3 года назад

      You saved your hell lot of time buddy

  • @devincox7985
    @devincox7985 3 года назад +3

    I paused midway through because I had to try this out. Matching an outline color to a background color allows for some fascinatingly art deco button shapes! Now I want to go code up a site just so I can abuse the heck outta this effect. ;)
    And heck yes we want a video detailing animation possibilities. :)

  • @sormpheng7752
    @sormpheng7752 2 года назад

    Never get tired of watching KP’s tutorial videos 😁💝

  • @fersahahmet9597
    @fersahahmet9597 3 года назад +2

    Very nice, good looking, charismatic glasses. Also i wanna hear about animated outline

  • @peteryates308
    @peteryates308 3 года назад +1

    Ah, I thought I was really familiar with outline but never knew about offsets. Thanks!

  • @BalachandranSumathiB
    @BalachandranSumathiB 3 года назад

    Never knew this much about outline. Thank you so much for the inspiration.

  • @elm4884
    @elm4884 3 года назад

    It helps a lot to watch one of his videos per day. Sometimes if something doesn't stick the first time, I'll rewatch it the next day. There's a whole plethora of good, relevant info.

  • @jackw.3978
    @jackw.3978 3 года назад +2

    Best channel ever, pls never stop..

  • @coramarcu3741
    @coramarcu3741 3 года назад +1

    Yes please, I'm ready for animated outlines! Thank you for your consistently helpful content! 💖

  • @javieroa8214
    @javieroa8214 3 года назад +1

    this is one of the best channels to learn. Everything is perfect, image, sound, way of explanation, everything 👌🏻

  • @jumaelahmed9995
    @jumaelahmed9995 3 года назад +2

    Thank you very much sir! today learned something new. And yes, we want to see how we can animate with outline offset.

  • @JaisinghaniSagar
    @JaisinghaniSagar 3 года назад +1

    Hey Kevin,
    I Always love your videos... They are super easy to understand...
    Teach me anything 😀
    Animated outlines..yes.. yes.. yes😀

  • @podiac
    @podiac Месяц назад

    You have such a beautiful energy for your approach. ❤

  • @zeko89
    @zeko89 2 года назад

    Hi, rookie here :D I've been looking for the "outline offset" solution for a million years!! uff...thank you so much!

  • @bruhmoment3731
    @bruhmoment3731 2 года назад

    Best CSS teacher on RUclips!

  • @resty1672
    @resty1672 3 года назад

    I really love the benefit for saving time from writting psudo element ,wonderful tutorial!

  • @codesader5720
    @codesader5720 3 года назад

    Great content as always Kevin. Proud to be your student any day.

  • @concretefields
    @concretefields 3 года назад +1

    Very cool! And yes, we would love to see what can be done with animations and outline

  • @Pankaj-Verma-
    @Pankaj-Verma- 3 года назад

    Thank you for covering this topic.

  • @CharlesSmall
    @CharlesSmall 3 года назад +1

    You bare the best,thanks Kevin

  • @jonmayer
    @jonmayer 3 года назад

    OMG I've never known this was added. This is brilliant when adding borders causes all sorts of layout issues. Sweet.

  • @iammichello
    @iammichello 3 года назад +1

    Great Video Kevin..thanks slot🙌
    And yes I want to see a video on animated outlines.
    Fun fact..some weeks back I was searching the internet to see whether I can add an outline radius 😂😂

  • @anhhung770
    @anhhung770 3 года назад

    You are a great tutor, Thanks a lot Kevin.

  • @julianrodriguez9832
    @julianrodriguez9832 2 года назад

    your content have always and I think will always help me, thanks.

  • @sunstrike8943
    @sunstrike8943 3 года назад +1

    Highly recommend

  • @tymothylim6550
    @tymothylim6550 3 года назад

    Thank you very much for this video! It was very educational for me and helps a lot :)

  • @boudyhesham5875
    @boudyhesham5875 3 года назад

    love you kevin, good luck with future videos !

  • @hellboyfbyao3
    @hellboyfbyao3 Год назад

    Hi, thank you recording this precious video. The only thing I'd like to ask is I tried to use border-radius with outline before I watched this video and it is working perfectly. It is still not my first choice as we are not able to edit each single sides of the outline.

  • @DamianonTube
    @DamianonTube 3 года назад

    Great explanations Kevin, wooow thank you so much!

  • @prudvikumarreddykommareddy4805
    @prudvikumarreddykommareddy4805 3 года назад

    Thanks, Kevin for your research and stuff and yes we want an animated outline video

  • @lrdsqrl2507
    @lrdsqrl2507 3 года назад

    I can't wait to see how you animate outlines!

  • @jeremydudet
    @jeremydudet 3 года назад

    Yeah! outline animation seems like a great video idea :)

  • @sprtlife6261
    @sprtlife6261 2 года назад

    Thanks for this, Kevin!

  • @chhavimanichoubey9437
    @chhavimanichoubey9437 3 года назад

    kevin is my daily driver teacher ill say and yes love animations and stuff

  • @zmlee88
    @zmlee88 3 года назад

    This is an amazing video. Thanks Kevin!

  • @bleulola
    @bleulola 3 года назад

    Thank you so much Kevin and happy new year!!! Yes, we would like the outline animation please

  • @coderkind
    @coderkind 3 года назад

    Animation outlines video would be great. Another great video by the way; thank you.

  • @seggamsuman
    @seggamsuman 3 года назад

    Thank you sir. I am seeing your video from very long time. I hope your doing like this new videos.

  • @RahulSharma-ox6se
    @RahulSharma-ox6se 3 года назад

    Loved it!! Thanks a lot, Kevin. Would love to see a follow-up video on animations with outlines.

  • @andrewcourtney3480
    @andrewcourtney3480 3 года назад

    Thanks as always Kevin! Would be great to see your outline animation example. Keep the great content coming!

  • @bulent2435
    @bulent2435 3 года назад

    I've started using inset box-shadow instead of border unless I don't want to control the sides individually. So I can create some nice transitions of thickness and blur on hover, active, etc.

    • @KevinPowell
      @KevinPowell  3 года назад

      Be really careful animating shadows, it can have a huge hit on performance. Shadow animations can really easily lead to some janky animations. It's a nice trick, just keep an eye out on that, and don't forget a lot of people are on slow machines and budget devices where it'll stand out more.

    • @bulent2435
      @bulent2435 3 года назад

      @@KevinPowell Thanks for the tip. I'll definitely avoid using excessively.

  •  3 года назад

    Do you know that because of you and your trick with the image I'm going to save a lot of line of code on my css project ? You're the best!!

  • @AdityaSaroj007
    @AdityaSaroj007 3 года назад

    We need that outline animation video ASAP. This was really good 🔥

  • @HeyImAK
    @HeyImAK 3 года назад

    Thank you so much for creating these videos, Kevin! I use to juse guess my way around css. Now I still guess but am sometimes correct.

  • @alinawaz4034
    @alinawaz4034 3 года назад +2

    we want animation with offsets 😎 this cool stuff.

  • @TheElkster
    @TheElkster 3 года назад

    Great video as usual and has got me wanting to give it more of a try! I always use the outline + all when troubleshooting unexpected horizontal scroll from watching your previous video a while back. Definitely would like to see you do some cool animation on this topic! 🤗

  • @coolcha
    @coolcha 3 года назад

    Awesome video - subscribed. Would love to see the outline animations video.

  • @rafadydkiemmacha7543
    @rafadydkiemmacha7543 3 года назад

    I had no idea outline-offset existed, thanks!

  • @RizkyGusna
    @RizkyGusna 3 года назад

    Great timing, I really don't know what to use in my project

  • @kevinphandy2
    @kevinphandy2 3 года назад

    Just made my life easier on a project. (read: as usual) Thanks!

  • @s.b.chandler110
    @s.b.chandler110 3 года назад +1

    I'm surprised this didn't come out and say that outline is reserved as an accessible focus indicator and just isn't in the design toolbox. You can do cool things with it but almost everyone uses outline as a focus indicator.

  • @AmandaLucaseu
    @AmandaLucaseu 3 года назад

    Great video Kevin - would love to see outline animations 👍🏻

  • @prakashd2912
    @prakashd2912 3 года назад

    Definitely, we want to see how we can play with outline animations 🥳

  • @nikhildhakal3727
    @nikhildhakal3727 3 года назад

    Really useful. Thanks

  • @bigfoot131
    @bigfoot131 3 года назад

    Kevin is the CSS 👑

  • @adityatiwari9103
    @adityatiwari9103 3 года назад

    Great again as always

  • @maor44
    @maor44 3 года назад

    Thanks for that!

  • @CanadianPenny
    @CanadianPenny 2 года назад

    What's I'd like is an inset property for borders or outlines, so that you can overlap the edges of an element and easily create a fade or blurring effect

  • @mohan9285
    @mohan9285 3 года назад

    Awesome Topic and the explanation, Kevin :)
    I would like to see the animation of outline-offset property too.

  • @onestepwebdev
    @onestepwebdev 3 года назад

    Thanks Kev, another great tut. Please go ahead make the animated outline tut.

  • @eddi3ms
    @eddi3ms 3 года назад

    Great video, so helpful😁

  • @priyapandian6379
    @priyapandian6379 3 года назад

    Awesome. Learned something 👍

  • @males.nikola
    @males.nikola 3 года назад

    You are the best! Also, I wanna hear about animated outline :)

  • @JediPhantom
    @JediPhantom 3 года назад

    This is really useful..thanks

  • @JayJames
    @JayJames 3 года назад

    Great video (as always) 👍

  • @cuffeemia2108
    @cuffeemia2108 3 года назад +5

    Jes, outline with animation . Por favor.

  • @ClarkeDesign
    @ClarkeDesign 3 года назад +1

    I've been using this on images for a while to add a litttle inline effect.
    .img-outline {
    outline: 1px solid rgba(255, 255, 255, .7);
    outline-offset: -4px;
    }

  • @Drendronix
    @Drendronix 3 года назад

    thx Kevin, very cool

  • @DylanduPreez
    @DylanduPreez 3 года назад

    Great video as always, would love to see animating with offsets.

  • @petropzqi
    @petropzqi 3 года назад +2

    Backdrop filter and color invert coming next?

  • @SlimBloodworth
    @SlimBloodworth 2 года назад

    Yes! Outline animations, pleeeeease!

  • @BenRangel
    @BenRangel 3 года назад

    Regarding round corners on focus outlines: I think it’s often a usability benefit when focus states are not too pretty, it’s good that they stand out and look sort of similar everywhere, they should stand out and not blend in. I love having all outlines being squares.
    Ps: and yes I love outline-offset: 2px as it clearly separates the outline from the element bg color

    • @KevinPowell
      @KevinPowell  3 года назад +1

      It's annoying that chrome's new default has them though, lol. But yes, they need to stand out for focus, and it's not about being pretty, it's about being functional!

  • @RyudoFanel
    @RyudoFanel 3 года назад +6

    So, you can have a negative outline offset and a border radius, which gives off the illusion of an outline with radius. Not perfect, but oh well.

  • @WhiteOwl12
    @WhiteOwl12 3 года назад

    Hey if you make two and give them a 2px border solid black. You remove margin -- where they touch you will get a double thick border. And border collapse does not work. How do you get only 1 border instead of the thickness of two?

  • @GUN2kify
    @GUN2kify 3 года назад +1

    i always use _* {outline: 1px dotted red; }_ to see how the elements are linked together /block each other.

  • @pbenikovszky1
    @pbenikovszky1 3 года назад

    lovely stuff Kevin ;)

  • @alvinray9080
    @alvinray9080 3 года назад

    OMG - never knew!

  • @jericovalino4976
    @jericovalino4976 3 года назад

    Yup!.. I'm early! Thanks for this another great explanation!

  • @AayanamAnirudh
    @AayanamAnirudh 3 года назад +1

    Shiiit!!! I never knew something called as outline in CSS..

  • @aram5642
    @aram5642 Год назад

    There is one more difference between border and outline which shows off when you want to style something like `fieldset:has(:invalid)` in a fancy way. Fieldset's border is not the same area as fieldset element.

  • @sashatv138
    @sashatv138 3 года назад

    Hi Kevin, I'd love to see your video with animatable outline! Please!

  • @JamesCoyle95
    @JamesCoyle95 3 года назад

    I'm pretty sure I read a draft spec at some point which showed intent to make outline follow border radius. I can't remember who on Twitter tweeted about it though.

  • @DhavalAhir10
    @DhavalAhir10 3 года назад

    Omg,
    An outline is so useful, i only used outline for seeing actual width and inner content of element 😂😂

  • @SnowGinger101
    @SnowGinger101 3 года назад

    Had a slight hope that outline would work better with clip paths, alas i leave codepen disappointed!
    Great vid tho!

  • @JimKernix
    @JimKernix 3 года назад

    Would love to see an animated version of outline

  • @voidmind
    @voidmind 3 года назад

    Even if you can't have multiple outlines on an element, I suppose you could put a child DIV with no padding or margin that is there to add another outline. Since there is no effect on layout, there is theoretically no limit to how many outlines you can create.

    • @KevinPowell
      @KevinPowell  3 года назад +1

      Be easier to layer box-shadows on instead :)

  • @ibxnnn376
    @ibxnnn376 2 года назад

    i don't suppose you could do a video on nested divs... would be great if you could help understand when and why it'd be good to use them

  • @RavMucha
    @RavMucha 3 года назад

    Yes, please.

  • @wendyhoile7659
    @wendyhoile7659 3 года назад

    Any animation tips would be brilliant

  • @einsteinjokoh6853
    @einsteinjokoh6853 Год назад

    thanks

  • @SirChogyal
    @SirChogyal 3 года назад

    When do we use outline?

  • @josipbjezancevic5697
    @josipbjezancevic5697 Год назад +1

    @KevinPowell as of Aug 2023. it seems that outline follows border-radius. Am I wrong, or all major browsers have updated this behavior? Again, thanks for everything!

    • @KevinPowell
      @KevinPowell  Год назад +1

      Safari doesn't... It did, but then reverted it for some reason. I'm guessing it's going to change back soon though

    • @statuschannel8572
      @statuschannel8572 5 месяцев назад

      @@KevinPowell i can confirm that border-radius is working for outline on Safari now :)

  • @donmorris4506
    @donmorris4506 3 года назад

    Kevin, your videos are so useful to me. Question - is there a way to support your efforts with onetime donations here and there? I took a look at Patreon but I don’t want to give a fixed amount each month.

    • @KevinPowell
      @KevinPowell  3 года назад

      I don't have anything set up at the moment. Could be something to look into :)
      Glad you like my content enough to want to support me a little! And I get that monthly contributions aren't for everyone. Until I get my act together, don't worry about it :D