Derk Jan Speelman Derk Jan Speelman - 2 months ago 11
CSS Question

It is possible to give <path> tag a class for css purposes?

I'd like to have two paths in my svg with classes so i can toggle opacity when I hover the svg with my mouse.

Answer

The answere to this question is easy to find, but anyway: yes it is. See the Global Attributes in https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path

.shape {
  opacity: .5;
}
<svg width="300px" height="300px" viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
  <path class="shape" d="M 100 100 L 300 100 L 200 300 z" fill="orange" stroke="black" stroke-width="5" />
</svg>

Comments