Skip to content
TheChatArchiveThe Chat Archive
o4-mini-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

How to change the color of an SVG text?

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4.1-2025-04-14’s answer.
  1. User

    How to change the color of an SVG text?

  2. Assistant

    Here are three easy ways to change the color of an SVG <text> element:

    1. Inline SVG attribute

      <svg width="200" height="50">
        <text x="10" y="30" fill="teal">Hello, SVG!</text>
      </svg>
      
    2. 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>
      
    3. 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 the fill property (not color).
    • You can also animate or transition fill with CSS if you want smooth color fades.

    Anything else you’d like to tweak? 😊

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.