o4-mini-2025-04-16· OpenAI
LMArena Human Preference 140K
How to change the color of an SVG text?
- User
How to change the color of an SVG text?
- Assistant
Here are three easy ways to change the color of an SVG
<text>element:-
Inline SVG attribute
<svg width="200" height="50"> <text x="10" y="30" fill="teal">Hello, SVG!</text> </svg> -
In your CSS
<style> .my-text { fill: crimson; } </style> <svg width="200" height="50"> <text class="my-text" x="10" y="30">Hello, SVG!</text> </svg> -
With JavaScript
<svg width="200" height="50"> <text id="myText" x="10" y="30">Hello, SVG!</text> </svg> <script> const txt = document.getElementById('myText'); // Option A: using setAttribute txt.setAttribute('fill', 'orange'); // Option B: using the style object // txt.style.fill = 'orange'; </script>
Notes:
• SVG text color is controlled by thefillproperty (notcolor).
• You can also animate or transitionfillwith CSS if you want smooth color fades.Anything else you’d like to tweak? 😊
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.