Indeed, it is possible to apply CSS styles to SVGs, to some extent.
To style the SVG, it is necessary to utilize it as an inline svg rather than using it within an <img>
or background-image
:
<svg id="lnkLeft" class="c-dark"></svg>
Once implemented, you can directly adjust its appearance through CSS by targeting either .c-dark
or the parent svg
element. Remember that if you wish to change the color of the SVG on hover, you should manipulate the fill
attribute, not the conventional color
:
.c-dark:hover {
fill: #FFF;
}
Sometimes, due to the extensive number of lines in SVG files, this method might clutter your HTML. However, with PHP access, you could alternatively output the SVG using file_get_contents
:
<?php echo file_get_contents("image.svg"); ?>
This will display the SVG directly on the page, allowing for CSS styling.
It's important to note that attempting to reference the SVG within an <img>
tag (or utilizing it as a background-image) will prevent CSS customization!
For additional information, feel free to explore CSS-Tricks' articles here and here.
We hope this explanation proves beneficial!