srcset and sizes attributes - [ images on the web | part one ]

Sdílet
Vložit
  • čas přidán 3. 08. 2024
  • Using srcset allows us to load in different versions of the same image based on the size of the viewport, or the pixel density of the user's device. This is really helpful as it's one relatively easy way to go about reducing bandwidth for users on lower end devices while ensuring that users on high-end devices get nice, crisp images.
    One cool thing with this is, it's all done with html, but the downside of it is that it can bulk up your markup a little bit, and we all like having clean markup. The other strange thing is, if you use the sizes attribute, you are actually going to be including media queries in your html... which is kind of strange. But it makes sense that this is all done in the markup and not the CSS with how the spec works, it just creates this weird thing where the markup actually partially relies on the CSS, which is not something we normally ever have to worry about.
    Link to my code: codepen.io/kevinpowell/pen/Mz...
    This video involved quite a bit of research on my part, below are the resources I used if you'd like to do more reading on the subject:
    ericportis.com/posts/2014/src...
    css-tricks.com/responsive-ima...
    developers.google.com/web/ilt...
    developer.apple.com/design/hu...
    medium.freecodecamp.org/a-gui...
    ---
    I have a newsletter! www.kevinpowell.co/newsletter
    New to Sass, or want to step up your game with it? I've got a course just for you: www.kevinpowell.co/learn-sass
    ---
    My Code Editor: VS Code - code.visualstudio.com/
    How my browser refreshes when I save: • How to automatically r...
    ---
    Support me on Patreon: / kevinpowell
    I'm on some other places on the internet too!
    If you'd like a behind the scenes and previews of what's coming up on my CZcams channel, make sure to follow me on Instagram and Twitter.
    Instagram: / kevinpowell.co
    Twitter: / kevinjpowell
    Codepen: codepen.io/kevinpowell/
    Github: github.com/kevin-powell

Komentáře • 256

  • @scottonanski4173
    @scottonanski4173 Před 7 měsíci +2

    Dang, Kevin.
    I have to say that whenever I'm struggling to understand a layout concept, you're videos are always so refreshing. You're a gifted teacher. Simple, to the point, and practical.

  • @cchana
    @cchana Před rokem +7

    The video on srcset I wish I watched at least 2 years ago! As ever, really well explained and great demo. In some sense, I feel like the solution is over complicated at the CSS level but this was more than enough to help get my head around it. Thanks, Kevin!

  • @juliocodes
    @juliocodes Před 5 lety +6

    Great job as usual, Kevin. The way you explain things is very clear which makes it easier to understand!

  • @williamzhou3438
    @williamzhou3438 Před 5 lety +12

    Thank you. I was reading and practicing about this topic but still not understanding it clearly until I watched your video. Now I'm confident enough to apply it on my own project. I really appreciate your explanation, and look forward to seeing more of your videos.

  • @hiwayshoes
    @hiwayshoes Před 5 lety +4

    Thank you so much for your help with images, Kevin! Your tutorials are always the best!

  • @JamesQQuick
    @JamesQQuick Před rokem

    Came back to this video for the second time a few years after the first time. Always great stuff :)

    • @KevinPowell
      @KevinPowell  Před rokem

      Nice! I've come back to it myself a couple of times to remember parts of it 😅

  • @sciencehub5197
    @sciencehub5197 Před 5 lety +12

    You're amazing. I just finished my website project last week by following your advice. I wish this video was out two weeks ago haha

  • @yuliethemstedt8619
    @yuliethemstedt8619 Před 8 měsíci +1

    Hey Kevin, this was sooooo helpful. I'm currently building an image-heavy website ... and I never fully took the time to understand all the parameters available in srcset ... this was an excellent workshop and just took half an hour. Thank you so much!

  • @RussDnB
    @RussDnB Před 4 lety +3

    Every time I think I've learned what I need to know, I find something new, lol
    Been working on a site for just over a month now, and stumbled across this today. Thanks for this video Kevin!

  • @greenworld7085
    @greenworld7085 Před 3 lety +1

    I was stuck for hours to figure out "clearing the cache " before I came 2 this video.
    But I found it in your video. U saved the day. thanks a lot...

    • @PaulMcCannWebBuilder
      @PaulMcCannWebBuilder Před 3 lety

      Also, when dev tools are open in Chrome, you can long click (click and hold) on the reload icon in the browser's toolbar and you get the option to 'empty cache and hard reload'.

  • @jimdart8219
    @jimdart8219 Před 5 lety +2

    Awesome. You have no idea how badly I need this on a project right now. Thanks a million Kevin.

    • @jivanmainali1742
      @jivanmainali1742 Před 4 lety +1

      But how do you put those width into img srcset when imgae is being loaded from backend

  • @shrookwageh5976
    @shrookwageh5976 Před 5 lety +1

    you always surprise me with your content. it's concise and informative. Great work.

  • @ivanpavlovnorth
    @ivanpavlovnorth Před 4 lety +1

    Super! I found that this tutorial is only one with an explanation of "CSS Pixels" among huge numbers of CSS tutorials!

    • @KevinPowell
      @KevinPowell  Před 4 lety +2

      It's something most people don't realize. I need to do a video only on that subject I think.

  • @user-vj8km6dm2l
    @user-vj8km6dm2l Před 8 měsíci +1

    What an explanatory video, loved the math formula tip you showed based on device widths. Thanks a lot for this amazing takeaway about srcset

  • @YvonneVibe
    @YvonneVibe Před 5 lety +1

    so enjoyable when watching your every video! thoughtful and clear

  • @joeldcanfield_spinhead

    Excellent and thorough explanation. Now that I'm working toward fully responsive sites, I'll be using srcset to serve different images for phone, tablet, and desktop (more or less.) I'd never heard of srcset before a week ago and as I'm refreshing my web knowhow this is high on my radar.

  • @lisap5615
    @lisap5615 Před 8 měsíci

    Thank you once again for amazingly helpful information! I think this is a very important thing to know to allow your images to be responsive and flexible for various devices.

  • @jibkas
    @jibkas Před 5 lety +30

    There should be another option in polls " Doesn't matter". Because for me it doesn't matter Code pen or VS Code. I'm more interested in topic. Great tutorial BTW.

    • @KevinPowell
      @KevinPowell  Před 5 lety +6

      I thought about it, but I figured I'd force people to make a decision :P - Glad you enjoyed the video!

  • @kostiantynkarzhanov9216
    @kostiantynkarzhanov9216 Před rokem +1

    Awesome and very well explained tutorial! Kevin, thank you so much! 💛

  • @KET0NES
    @KET0NES Před rokem

    thanks, love this!
    trying to get into more detail of loading and optimisation and it's hard to find good content on fundamentals like this.
    fun seeing an old video compared to your new stuff too.

  • @The1stKing
    @The1stKing Před 4 lety

    Oh man, i loved the video! Thank you so much for making it. God bless you sir.

  • @Behnam_M1998
    @Behnam_M1998 Před 4 měsíci

    this tutorial was just awesome! thanks kevin, you just saved my day🌹

  • @level9teamplayer
    @level9teamplayer Před rokem

    Ty. This was confusing at first buy you made it pretty simple and easier to understand.

  • @ViktoriaLukyanchuk
    @ViktoriaLukyanchuk Před 2 lety

    I finally understood this concept of size!

  • @esraaabdelaziz485
    @esraaabdelaziz485 Před 5 lety

    thank you so much for that video this really made it easy for me to use srcset attribute and understand it very well

  • @krtecek-who-tries
    @krtecek-who-tries Před rokem +1

    Thank you! I was struggling to understand why one and the same image is loaded no matter which screen size I set in Chrome Dev Tools responsive emulator, and your video was really helpful :)

  • @andrejmarffy3368
    @andrejmarffy3368 Před 3 lety +1

    Thanks Kevin! Very well explained. Great help for me.

  • @TokyoNerd
    @TokyoNerd Před 5 měsíci

    Another very helpful video. These videos always help me to learn a new way to improve my website!

  • @xiiEJRAM
    @xiiEJRAM Před 4 lety +1

    I have learned a lot of things from you , I really appreciate what you do for us bingers in stuff like this 🖤

    • @zanekase8099
      @zanekase8099 Před 2 lety

      sorry to be so offtopic but does anyone know a way to log back into an instagram account?
      I somehow forgot the login password. I love any assistance you can offer me!

    • @ameerjack1329
      @ameerjack1329 Před 2 lety

      @Zane Kase instablaster =)

    • @zanekase8099
      @zanekase8099 Před 2 lety

      @Ameer Jack i really appreciate your reply. I got to the site through google and I'm trying it out now.
      Seems to take quite some time so I will get back to you later when my account password hopefully is recovered.

    • @zanekase8099
      @zanekase8099 Před 2 lety

      @Ameer Jack it did the trick and I now got access to my account again. Im so happy!
      Thanks so much you really help me out !

    • @ameerjack1329
      @ameerjack1329 Před 2 lety

      @Zane Kase Happy to help :)

  • @igorradovic037
    @igorradovic037 Před 5 lety

    This is very good and useful tutorial and it explains advanced techniques. Thank you Kevin keep on going.

  • @kaine2694
    @kaine2694 Před 5 lety

    Thank you soooo much for doing this awesome videos! I do lern more from you than from enywere else on the internet. Great quality, great mic, nice you. Greetings from Austria and Thanks alot! keep going!

    • @KevinPowell
      @KevinPowell  Před 5 lety +1

      Thanks so much for the kind words Julian, and I'm so glad that you like and learn from my videos :D

  • @RichardShire
    @RichardShire Před 4 lety

    Great video Kevin, really helpful info, thank you!

  • @alimfuzzy
    @alimfuzzy Před 5 lety

    This is a good coincidence. I just started the Udacity nano degree and this is in the first module and did not understand sizes. You explain it much better than they do.

    • @KevinPowell
      @KevinPowell  Před 5 lety +1

      I'm glad I could help out Andrew! I hope the rest of the course meets your expectations, I've heard good things about Udacity and have thought about doing a few of their courses in the past.

  • @TheDexter89
    @TheDexter89 Před 5 lety +1

    I see this source set in wordpress but I don't know the concept behind it. Today I understand it and use it for my HTML website
    Thanx Kevin

  • @denisdeleon2271
    @denisdeleon2271 Před 2 lety

    Thank you. Good explanation of srcset and what the browser is doing.

  • @squirrelwise
    @squirrelwise Před 5 lety +2

    Thanks Kevin. You have produced some quality videos this last month or so. I really appreciate it.

  • @alenamekhnina-marcalle5234

    Thank you so much for this video! Helped me a lot!

  • @eip408
    @eip408 Před 2 lety

    Awesome, I believe that this are indeed needed. Thanks🙌🏼

  • @andersonhall08
    @andersonhall08 Před 5 lety

    Great video, as usual. Seems like I did a free course on Udacity that dealt with this, but your explanation has helped it stick better for me. Thanks!

  • @Marceloamado1998
    @Marceloamado1998 Před 3 měsíci

    Very clear explanation. Thank you man

  • @gianniskoulouris4831
    @gianniskoulouris4831 Před 5 lety

    Very well explained..Well done!

  • @lakeacres9750
    @lakeacres9750 Před 5 lety

    Very well explained! Thanks!

  • @MartinBelcher
    @MartinBelcher Před 5 lety

    It's great, I am going to use it heavily

  • @KyleMerl
    @KyleMerl Před 5 lety

    wow... This is the video that I didn't know I needed. I used media queries and, if I remember correctly, the visibility property to achieve that same effect. using srcset seems so much easier!

    • @JBuchmann
      @JBuchmann Před 5 lety +3

      I think doing it with media queries and css visibility isn't really helping with lowering bandwith. You're still downloading all the image versions. With srcset you literally are downloading only the single best sized image depending on the browser width, resolution, etc.

    • @KyleMerl
      @KyleMerl Před 5 lety

      I agree. I'm going to have to use this going forward.

    • @KevinPowell
      @KevinPowell  Před 5 lety +1

      Yup, as John mentioned, this will load in all the images. You'd be better off just loading in one big image in that case I believe. You'll probably really like the picture element once I get there next week :)

  • @gaborszekely8387
    @gaborszekely8387 Před 5 lety +2

    YES!!! You came through on kitten, as promised. I now have no choice but to Patreon this channel.

    • @KevinPowell
      @KevinPowell  Před 5 lety

      Haha, I'll make sure to keep them up :)

  • @AlessandroManente
    @AlessandroManente Před rokem

    thanks a lot for the channel, awesome video, and i'm definitely going to use srcset for my personal page!

  • @aram5642
    @aram5642 Před 4 lety +2

    What a fantastic tutorial! Like a missing manual!

  • @leonardmbibi8013
    @leonardmbibi8013 Před rokem

    First,Thanks for the video. Secondly, I did not get good results: without the media query, my browser never changed img as I resized. Thirdly, with the media query in place, transitions occurred way earlier than expected. Finally, I ended up using the element for my project.

  • @CatholicaTV
    @CatholicaTV Před 3 lety

    A fantastic tutorial, thanks!

  • @marinoschrysanthou2175

    Perfectly explained!

  • @SiddharthSharma15
    @SiddharthSharma15 Před rokem

    Thank you so much, extremely clear.

  • @ahsanhabibasha6906
    @ahsanhabibasha6906 Před rokem

    It was really helpful to me and thanks a lot for this.

  • @ThePein124
    @ThePein124 Před 5 lety

    very clear explanation thank you

  • @alexraventos9561
    @alexraventos9561 Před 5 lety

    Thank you very much from a teacher in Barcelona, Catalunya

  • @hashaama
    @hashaama Před 5 lety

    your every video is amazing keep it coming sir!!

  • @ryanamberger
    @ryanamberger Před 5 lety +1

    Notepad++ is cool too. That's how I learned Web Dev. Really helpful how it gives popups when typing to give examples of what you can use, especially on the CSS page. Still learning every day and that certainly helps. Just so many declarations to remember.
    Sadly, after all the learning on my own and taking an extra web dev class last semester, I'm still struggling to get hamburger buttons working. Ive been struggling with responsive design and adaptive content.

    • @KevinPowell
      @KevinPowell  Před 5 lety +1

      Takes a long time to start putting everything together, and making things responsive just adds a deeper layer on top of that. Just keep practicing and it starts to get easier :)

    • @cerealrakist7360
      @cerealrakist7360 Před 3 lety

      I had to learn on notepad++ and type everything out Before I could use an editor with all those bells and whistles. Then I realized a little to late, that ++ offered Bells and whistles too ! Lol .. I look back and see the importance of knowing how to make everything happen with no extensions or expansions or suggestions, etc ... I like notepad ++, I’m no hater by any means but VS has my heart.

  • @tanikobas6991
    @tanikobas6991 Před 3 lety

    Great explanation! Thank you so much for spending your time. Nice guy! :)

  • @jamesauble8091
    @jamesauble8091 Před 2 lety +2

    At 9:56 you suggest to use the lowest quality image, but devs may bear in mind that this isn't always the best option. In many situations you might actually want to provide the best quality image at the sacrifice of bandwidth to the end user. The reason for this would be that just because the end-user is using an old browser, this doesn't necessarily mean they're on a poor connection. Granted, there may be a correlation, but this should be taken case-by-case.

  • @Rosk404
    @Rosk404 Před 5 lety

    Kevin, you are awesome! I love your videos!

  • @threeone6012
    @threeone6012 Před 5 měsíci

    Kevin lost weight since this.
    Good job!

  • @DamianDemasi
    @DamianDemasi Před 3 lety

    Thank you! I finally understood this!

  • @1337ghomri
    @1337ghomri Před 8 měsíci

    Nice video! Finally understand it

  • @erock3737
    @erock3737 Před 3 lety

    Great video - thank you.

  • @rvoitiv
    @rvoitiv Před 11 měsíci

    This is great content, thank you

  • @liushahuang5754
    @liushahuang5754 Před 4 lety

    very well explained!

  • @kristianseehrich5200
    @kristianseehrich5200 Před 4 lety

    Great Video, thanks a lot!

  • @muhammedozalp
    @muhammedozalp Před 4 lety

    Thank you very much Kevin

  • @magoxxii
    @magoxxii Před 3 měsíci

    Great video! i loved the use of cats. not anymore in new videos =P thanks as always kevin! you make it so clear, today i saw 4 more videos about it, all of them bring some to the table but yours always is the most educative and descriptive. thanks again from 2024!

  • @rafa6536
    @rafa6536 Před rokem

    Maybe it is a great solution. I didn't know about it. I am learning and on my blog, which I am making to learn while doing it, I have sometimes a post with a lot of pictures. Load time was crazy slow, but the column is not wide, so I wrote myself JavaScript code and server side code which is returning to the user the smallest possible picture depending on column width. Now I think I have to rewrite it using srcset + sizes :) Thanks!

  • @ldlouis
    @ldlouis Před 5 lety

    Very good topic. Thank's for sharing. Like this better than Codepen

  • @nave3411
    @nave3411 Před 5 lety

    Cool! I didn't know about it. Thanks!

  • @stephenaitken1560
    @stephenaitken1560 Před 3 lety

    What an excellent tutorial.

  • @tarcisiomateus1506
    @tarcisiomateus1506 Před 2 lety

    thanks so much, I gonna use it today😊

  • @FreeHindiAdvice
    @FreeHindiAdvice Před 3 lety

    100000 times clap clap clap....you saved my tons of time, Thank you for everything :) :) :)

  • @Faruk-zt5iw
    @Faruk-zt5iw Před 2 lety

    Thanks, I feel like I'm ready to implement this on the real project :)

  • @sakarsr
    @sakarsr Před 5 lety +1

    Nice to know about (scrset). VSCode explanation is good. Use VSCode in all your code examples. Good health.

  • @Lilliebeth001
    @Lilliebeth001 Před 3 lety +5

    Hi Kevin, thank you. This is really interesting, as always. How would i apply this when I am using an img as a background in css though?

  • @TheTallMan67
    @TheTallMan67 Před 4 lety

    so good. Thank you!

  • @salhakim2322
    @salhakim2322 Před 4 lety +3

    Great video, I’m wondering what people’s thoughts are on automating sizing picture sizes? Ideally, I’d like to output sizes in webp for most viewports and jpegs for mobile since support still isn’t there.

  • @DrNio-sh5mx
    @DrNio-sh5mx Před 2 lety

    Great work

  • @babayaga5848
    @babayaga5848 Před 5 lety

    we don't need dislikes for this guy plz, this will be helpful Kev thank you, keep it up ♥

    • @KevinPowell
      @KevinPowell  Před 5 lety

      Haha, always gonna be haters, it's all good

  • @GoogleUser-es9vs
    @GoogleUser-es9vs Před rokem +1

    Thank you so much!!!

  • @briangibson3803
    @briangibson3803 Před 5 lety

    Pole?.. IDE/Text Editor over Code Pen any day... as a newbie just nice to see all the code, not just the CodePen content code (it that made sense?).. and then write it myself in the same editor as VSC and Atom seem to be everyone's flavour at the mo.. Just a lot easier for a newbie to feel out and understand.. Keep up the awesome work dude! : )

  • @ghosttradeindia
    @ghosttradeindia Před 5 lety

    really helpful thanks

  • @abhijitbarman4401
    @abhijitbarman4401 Před 3 lety

    very informative video🧡🧡

  • @Diana-yv9et
    @Diana-yv9et Před rokem

    Thank you!!🥰

  • @ashishrana2089
    @ashishrana2089 Před 5 lety

    You are always with energy Kevin yup

  • @PIRAKAS666
    @PIRAKAS666 Před 3 lety

    very nice!

  • @ajayji1009
    @ajayji1009 Před 4 lety

    Nicely explained Kevin as always. As you mentioned 500w, 1000w in srcset and in media query example you mentioned vw...so, 500vw and 500w are the same?

  • @CarlitoProductions
    @CarlitoProductions Před 3 lety

    this explains well what i had trouble with. thank! question though: for the media queries for the size property, can we somehow access srcset inside of css and implement the properties there? Or something similar?

  • @johnKeysCloudSonics
    @johnKeysCloudSonics Před 2 lety

    I plan on using this for product item photos on e-commerce sites.

  • @kennall45
    @kennall45 Před 3 lety

    Thank you!!!

  • @davidpicarazzi
    @davidpicarazzi Před 4 lety

    What an amazing video, explained so clearly. I have hopefully a small question, before I code websites I design them in XD, say I got a picture in XD, is there anyway to see what its size is instead of having to export it to see it?
    Also, when making smaller versions of a picture should I manually resize them in XD or try out the export @1x 2x 3x options etc?

    • @KevinPowell
      @KevinPowell  Před 4 lety +1

      I'd use the scaling options in XD for exporting! I think if you click on an element you can see it's dimensions on the right sidebar somewhere.

    • @davidpicarazzi
      @davidpicarazzi Před 4 lety

      @Kevin Powell Thanks kevin, so is it best practice to put your lowest quality first?
      As in :
      img src="low quality"
      srcset="low quality
      good quality
      best quality"
      I’m a little confused how you go about it for mobile. Say I make a desktop mockup of a product page that has shoes. And I also design a mobile mobile mock up. Would I export the desktop pics at greater sizes and do the same for mobile?

  • @libbeytds
    @libbeytds Před 2 lety

    What's your recommendation when using a grid of images that scales with the viewport? In that case, would I have to write countless media queries to pass the width of each image at any given screen size? Or is there a better way of doing this?

  • @rahultirkey7950
    @rahultirkey7950 Před 4 lety

    Images make the webpages slow. Thanks that's what I am looking for.

  • @Human_Evolution-
    @Human_Evolution- Před 2 lety

    Cool hair style... Need to add some CSS to that lol

  • @gaziev__9797
    @gaziev__9797 Před 3 lety

    I love you! In the ru community, little is said about it

  • @primerproyecto
    @primerproyecto Před 5 lety

    gracias from spain

  • @gmoneybags01
    @gmoneybags01 Před 5 lety +1

    Hey Kevin, do you have any videos on how to use grunt to make images responsive?

  • @kyleklaiber2225
    @kyleklaiber2225 Před 2 lety

    @kevin powell thanks for this! Did you ever do a part 2 for this? 28:00 I am looking to include something like this in the theme I'm building and not finding any solutions that I like so far!