Add SVGs as Component Properties

About This Resource

Webflow components are great for scalability, but there’s one limitation, you can’t add SVGs as component properties. In this resource, I’ll show you how to make it work in easy steps.

Step 1: Add The Following CSS

Paste in inside <head> tag of page or site settings
<style>
.svg-wrap svg {
  width: 100% !important;
  height: 100% !important;
}
.svg-wrap.cc svg path {
  fill: currentColor !important;
}
</style>

Step 2: Add The Folllowing Javascript

Paste inside before </body> tag of page or site settings
<script>
  document.querySelectorAll('.svg-code').forEach(el => {
    // Get the inner text (escaped SVG code)
    const svgCode = el.textContent.trim();
    // Replace the div with actual SVG
    el.outerHTML = svgCode;
  });
</script>

Step 3: Define Width and Height

Add a div where you want the icon to appear, give it a class of svg-wrap, and set its width and height to match the size you want for the icon.

Step 4: Connect Property

Add another div inside the svg-wrap div, give it the class svg-code set it to display none, and connect it to the component’s text property.

Step 6: Publish

Add your code inside the property, then publish.

By default, the color of an SVG is defined by its original color. If you want to apply a color using the text color property (and change it on hover), give the svg-wrap a combo class of cc. This way, the SVG will inherit its color from the svg-wrap text color.

Frequently Asked Questions

Webflow doesn’t natively allow you to connect SVG code directly to Component Properties. However, you can follow the method I shared above to make it work.

You can change the color of an SVG on hover by applying a combo class cc to the svg-wrap element. Once that’s done, the SVG will inherit the text color from the svg-wrap, allowing it to change smoothly when you apply a hover state.