Turning SVG into CSS is magic

  Рет қаралды 23,722

Matt Visiwig

Matt Visiwig

5 ай бұрын

I'm going to show you how to take your own vector design and place it on a website, whether you design in Illustrator, Figma, Inkscape, or wherever.
Instead of placing your SVG code into HTML, you can now place your SVG code into CSS. We do so using the CSS property background image.
In the video I show you some real use cases, and then show you how to convert SVG into CSS, and how to customize that on your website.
LINKS----
SVG to CSS Converter:
www.svgbackgrounds.com/tools/...
SVG OMG (optimizer):
jakearchibald.github.io/svgomg/
Website graphics sourced from:
www.svgbackgrounds.com/?...
Custom CSS Bullets (video):
• Create custom HTML bul...
Custom CSS Bullets (article):
www.svgbackgrounds.com/custom...
Buy me a coffee:
www.buymeacoffee.com/mattvisiwig

Пікірлер: 56
@ogadit
@ogadit 5 ай бұрын
This is such an awesome video. Straightforward, useful and without any flashy animations Subscribed!
@MattVisiwig
@MattVisiwig 5 ай бұрын
Thanks, but I spent days and days on the intro animation where the SVG icon slides into the laptop 😅
@Blackkorso
@Blackkorso 5 ай бұрын
Your website and KZfaq content are awesome. Thank you for all your work!
@MattVisiwig
@MattVisiwig 5 ай бұрын
Hey thanks, I appreciate that! Going to keep at it :)
@Totomenu
@Totomenu 4 ай бұрын
Subscribed 👍 and than tried to add you links to my bookmarks, just to realise that I had already bookmarked your website years ago. I think it proves that videos where you show how to use it are very useful
@MattVisiwig
@MattVisiwig 4 ай бұрын
Thanks for Sharing Antoine! I'm trying to go full-time on SVGBackgrounds.com so I appreciate the nudge to keep at it.
@digitalsahara6670
@digitalsahara6670 4 ай бұрын
wow just found this channel and cannot believe how good this is and the value you add. thank you so much
@MattVisiwig
@MattVisiwig 4 ай бұрын
Hey, thank you so much! Glad you got something out of the video.
@mariusthgersen1614
@mariusthgersen1614 5 ай бұрын
This was a really useful tip, and your website is amazing! Thank you
@MattVisiwig
@MattVisiwig 5 ай бұрын
Thanks Marius, glad you think so :)
@ei1589
@ei1589 5 ай бұрын
Very underrated channel, thanks for the info, keep doing this! :))
@MattVisiwig
@MattVisiwig 5 ай бұрын
Hey, I appreciate this and plan on releasing videos more often.
@bobhearinger
@bobhearinger 5 ай бұрын
Thanks, Matt. Will be watching your future videos :)
@MattVisiwig
@MattVisiwig 5 ай бұрын
Awesome, I can't wait to watch them too
@alexmacol228
@alexmacol228 5 ай бұрын
Thanks for the info Matt! I didn't know your channel! Just subscribed! Greetings from Brazil!
@MattVisiwig
@MattVisiwig 5 ай бұрын
Glad you found the video useful Alex!
@knecks7374
@knecks7374 4 ай бұрын
this is so awesome. THANK YOU!!
@MattVisiwig
@MattVisiwig 4 ай бұрын
Glad you think so!
@DanieleManca1983
@DanieleManca1983 4 ай бұрын
I really enjoyed the video, and found useful the use case mentioned, 😊
@MattVisiwig
@MattVisiwig 4 ай бұрын
Great to hear Daniele!
@bustozoni
@bustozoni 5 ай бұрын
That was lovely! Hermoso!
@MattVisiwig
@MattVisiwig 5 ай бұрын
Thanks so much!
@cebuanoninoy
@cebuanoninoy 4 ай бұрын
Thanks for this video.
@MattVisiwig
@MattVisiwig 4 ай бұрын
Thank you for the comment :)
@nyitigvilaga
@nyitigvilaga 4 ай бұрын
Thank you very much!
@MattVisiwig
@MattVisiwig 4 ай бұрын
You're very welcome!
@realalgato
@realalgato 5 ай бұрын
Here before this channel blows up
@MattVisiwig
@MattVisiwig 5 ай бұрын
Thanks for the confidence boost :)
@septimusforster
@septimusforster 29 күн бұрын
To kill many birds with one stone. Best of all, wholesome lack of vulgarity. Subscribed to, Mr Visiwig. God bless you.
@MattVisiwig
@MattVisiwig 23 күн бұрын
Thanks for the kind words :)
@tejasthorat
@tejasthorat 4 ай бұрын
0:11 Missed the epic drop 1st time I watched .😅😅
@MattVisiwig
@MattVisiwig 4 ай бұрын
I just sat here repeatedly clicking the 0:11, think I'm going to take the rest of the day off.
@JeremyVienney
@JeremyVienney 5 ай бұрын
Great content ! Is it not a bad practice to add in css data:image instead directly inline them on the DOM ? I learned from Harry Roberts that icons or images defined like that in css was always a red flag because it was render blocking the paint. Your way make lighter the first document response but add weight to css entries files and could add a delay to the paint render process. What do you think about it ?
@MattVisiwig
@MattVisiwig 5 ай бұрын
Thanks Jeremy, good question: One man's bad practice is another man's treasure. In my examples, we place a single icon (1kb of data) as a list bullet or in a search bar - where it's hard to place inline SVG. In the scheme of things, I don't think this could be considered in the same league as other bad practices like scroll-jacking, dark patterns, or ignoring accessibility. I'm also not advocating this method to replace inline SVG or to be used for an entire icon system. But I do think there are some situations where this is super useful. If you're website is serving millions of visitors a day, you're probably nit-picking over every decision and pixel - including this decision. But you're also probably not taking advice from some rando on KZfaq (that's me). For the average site, this is a great trick to have in your tool-box.
@JeremyVienney
@JeremyVienney 5 ай бұрын
@@MattVisiwig Thanks Matt, It's interesting because I've been thinking about this optimisation since yesterday. I usually inline everything and use them as sprites, but I have to admit that on some projects, this creates a real burden on the html document and inevitably has an impact on the construction of the DOM tree. And you're right, on 1kb icons of this type, it's better to do that and add a class to an HTML element than to add a svg>use N times on the page... In fact it's mainly the parsing of base64 into css that's problematic (decoding and transforming into base64 adds too much weight). Your technique for simple elements that are repeated often is in fact probably the best way of managing a site's decorative elements, because you retain control over their styles (I didn't know that svg can be styled by its classes in base:image css) and you can extract them all into a dedicated css with ultra-long caching (svg additions and modifications are rare). So even if it has an impact on the time it takes to paint a page with large SVGs, it's probably negligible compared to the time saved downloading and parsing the html page. I'd have to do some comparative tests with the different techniques, if I can find the time to do that I'll come back and share them with you. PS: you're not a random guy on youtube and your video makes me want to see more. I must even have been a customer on a previous viersion of your site ! :)
@MattVisiwig
@MattVisiwig 4 ай бұрын
@@JeremyVienney sounds great, would love to know the results if you find the time to run tests. PSS: thanks, this videos reception def makes me want to post more :)
@Linuxdirk
@Linuxdirk 4 ай бұрын
You can simply embed SVG files using HTML image tags or the various CSS options. You don’t need to inline your SVG files.
@theseangle
@theseangle 4 ай бұрын
Have fun changing its color and being Nostradamus with CSS selectors. Especially if that icon is used in many places with slight modifications.
@codedjango
@codedjango 5 ай бұрын
How to trigger animation on objects within the svg (in layers) using browser events such as cursor hover?
@MattVisiwig
@MattVisiwig 5 ай бұрын
This question deserves it's own video. If you plan on using :hover (css) I'd highly recommend inline SVG placed in the HTML document over what this video demonstrates (SVG in CSS). This is because you'd be able to manipulate the SVG better through CSS. For example if the SVG has an ID of 'KZfaq', you could change a few properties with hover like so... #KZfaq{ fill: black; transition: fill .2s, stroke-width .2s, transform .2s; } #KZfaq:hover{ fill: red; stroke-width: 3px; transform: translate(5px, 5px) rotate(15deg); } Disclaimer: I didn't test this CSS.
@jfftck
@jfftck 4 ай бұрын
This is something that is not recommended, but it isn’t a terrible idea. As others have pointed out, it has many drawbacks and that is why I can’t recommend using it for anything more than icons.
@MattVisiwig
@MattVisiwig 4 ай бұрын
Don't forget the main use case that "isn't a terrible idea" is backgrounds. Using inline SVG for backgrounds is doable, but clunky. Instead I would much rather let background-image and the other background properties do what they do best.
@heatherfarnham3185
@heatherfarnham3185 4 ай бұрын
Can you use multiple background svg images in one div or would you place them in separate divs?
@MattVisiwig
@MattVisiwig 4 ай бұрын
Great question. You can place multiple backgrounds on a single container with this technique. Simply comma separate the backgrounds as the value of the background-image. You can comma separate other values to properties like background--size and background-position-or use a single value if it applies to multiple backgrounds.
@heatherfarnham3185
@heatherfarnham3185 4 ай бұрын
@@MattVisiwig that's great, thanks!
@michaelkamko
@michaelkamko 4 ай бұрын
🔥🔥🔥👍🤝
@MattVisiwig
@MattVisiwig 4 ай бұрын
🤝🙏
@johnsonb8727
@johnsonb8727 4 ай бұрын
Does this technique trigger a http request?
@MattVisiwig
@MattVisiwig 4 ай бұрын
Nope. There's a request to get your CSS file, but not the Data URI. It's the equivalent of inlining SVG in your CSS.
@johnsonb8727
@johnsonb8727 4 ай бұрын
very cool@@MattVisiwig
@diegognoatto8706
@diegognoatto8706 5 ай бұрын
very bad idea mate, we use it inline for many reasons but the most important one is to have full controll of it. try to animate a something or even change the color if you do that. its a pain for some things and for most is impossible. i bet you didnt mentioned that "very small detail" because you selling premuim svg backgrounds to non-coders newbies that got no idea what they going into. thats called bad faith.
@MattVisiwig
@MattVisiwig 5 ай бұрын
Caught me red handed mate. But I will point out my free and paid graphics all work as inline SVG too. As with any idea, there are times and places for it. I gave two specific use cases that make sense. Ever try placing inline SVG in an input? You can't. Instead you need to use a pseudo element or the much easier method: an SVG as a background-image. You could use inline SVG within an unorder list (), but you'd need to duplicate the code for every bullet or better yet, just place the SVG in CSS and let CSS do what it does best. I do need to give you credit for making one great point: "to have full control" and "animate" the SVG, it should be inline. Agree. There are lots of reasons to use inline SVG, and I only gave one in this video - not to trick anyone - but to keep my video on topic and to the point.
@NicoHeinrich
@NicoHeinrich 5 ай бұрын
If you want an inline SVG in an input (e.g. magnifier in search field), you simply add padding to the end of the input and position that icon absolute.
@AppyDave
@AppyDave 4 ай бұрын
@@MattVisiwig excellent video @MattVisiwig, good production value and as any content creator knows, you can't cover every edge case in a video if you want people to fiind it interesting, awesome work.
A new approach to container and wrapper classes
25:27
Kevin Powell
Рет қаралды 251 М.
ПРОВЕРИЛ АРБУЗЫ #shorts
00:34
Паша Осадчий
Рет қаралды 7 МЛН
No empty
00:35
Mamasoboliha
Рет қаралды 10 МЛН
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 17 МЛН
Learn CSS Subgrid in 14 minutes
14:19
Slaying The Dragon
Рет қаралды 65 М.
SVG Animation
7:32
CatWebDev
Рет қаралды 486
Login Form | HTML CSS
1:00
Learning Axis
Рет қаралды 519 М.
Use these instead of vh
6:06
Kevin Powell
Рет қаралды 493 М.
Create a clean, modern navigation with HTML & CSS
25:17
Kevin Powell
Рет қаралды 147 М.
These CSS PRO Tips & Tricks Will Blow Your Mind!
8:48
Coding2GO
Рет қаралды 165 М.
The Secret Science of Perfect Spacing
9:40
Chainlift
Рет қаралды 387 М.
Сделала Сюрприз Брату После 3 лет Разлуки ❤️
0:26
Глеб Рандалайнен
Рет қаралды 2,2 МЛН
¡Ñom Ñom! ¡Es la Hora de Comer! #pinkfongespañol
0:16
Pinkfong en español - Canciones Infantiles
Рет қаралды 10 МЛН
Gym lover..#trollface #short #shortsfeed
0:21
DS SIPUN OFFICIAL
Рет қаралды 8 МЛН
哈哈这些娃娃可烦人了!#火影忍者 #佐助 #家庭
0:31
火影忍者一家
Рет қаралды 34 МЛН
¡Ñom Ñom! ¡Es la Hora de Comer! #pinkfongespañol
0:16
Pinkfong en español - Canciones Infantiles
Рет қаралды 10 МЛН
Я обещал подарить ему самокат!
1:00
Vlad Samokatchik
Рет қаралды 9 МЛН
Я не голоден
1:00
К-Media
Рет қаралды 3,1 МЛН