Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-opus-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

Hello. Today I would like to learn how to use the svg filter <feComposite>. I have this…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-sonnet-4-20250514’s answer.
  1. User

    Hello. Today I would like to learn how to use the svg filter . I have this code: Old Amsterdam Old Amsterdam I would like to exclude the text id="front" from the text id="back" using the svg-filter with the operator xor. Do you have an idea how I can do this? Thank you :-)

  2. Claude Assistant

    To use <feComposite> with the xor operator to exclude the front text from the back text, you'll need to create a filter that combines both text elements. Here's how you can modify your SVG:

    <svg width="900" height="300" viewBox="0 0 900 300">
      <defs>
        <filter id="xorFilter">
          <!-- Create the back text as source -->
          <feImage href="#back" result="backImage"/>
          
          <!-- Create the front text as source -->
          <feImage href="#front" result="frontImage"/>
          
          <!-- Apply XOR composite operation -->
          <feComposite in="backImage" in2="frontImage" operator="xor"/>
        </filter>
      </defs>
      
      <!-- Define the text elements but hide them -->
      <defs>
        <text id="back" x="50" y="200" stroke="black" stroke-width="20" fill="white" stroke-linejoin="round">Old Amsterdam</text>
        <text id="front" x="50" y="200" fill="white">Old Amsterdam</text>
      </defs>
      
      <!-- Apply the filter to a container -->
      <g filter="url(#xorFilter)">
        <rect width="900" height="300" fill="none"/>
      </g>
    </svg>
    

    However, there's a more straightforward approach that works better in practice. Since feImage can have cross-browser compatibility issues, here's an alternative method using feComposite more directly:

    <svg width="900" height="300" viewBox="0 0 900 300">
      <defs>
        <filter id="xorFilter" x="-50%" y="-50%" width="200%" height="200%">
          <!-- Get the source graphic (back text) -->
          <feFlood flood-color="white" flood-opacity="1" result="white"/>
          <feComposite in="SourceGraphic" in2="white" operator="xor" result="backXor"/>
          
          <!-- This approach works by applying the filter to a group -->
        </filter>
      </defs>
      
      <!-- Group both texts and apply filter -->
      <g>
        <text x="50" y="200" stroke="black" stroke-width="20" fill="white" stroke-linejoin="round">Old Amsterdam</text>
        <text x="50" y="200" fill="black">Old Amsterdam</text>
      </g>
    </svg>
    

    For the specific effect you're looking for (creating a stroke with the inner text cut out), here's the most practical solution:

    <svg width="900" height="300" viewBox="0 0 900 300">
      <defs>
        <mask id="textMask">
          <!-- White background (shows everything) -->
          <rect width="100%" height="100%" fill="white"/>
          <!-- Black text (hides this area) -->
          <text x="50" y="200" fill="black">Old Amsterdam</text>
        </mask>
      </defs>
      
      <!-- Apply mask to the stroked text -->
      <text x="50" y="200" stroke="black" stroke-width="20" fill="none" stroke-linejoin="round" mask="url(#textMask)">Old Amsterdam</text>
    </svg>
    

    The mask approach is often more reliable than using feComposite with xor for this type of text effect. The xor operator in feComposite performs a bitwise XOR operation on the pixel values, which can sometimes produce unexpected results depending on the colors involved.

    If you specifically need to use feComposite with xor, you might need to experiment with different color combinations and opacity values to achieve the desired visual effect.

  3. User

    OK. Nice that works. Thanks a lot.

  4. Claude Assistant

    You're welcome! Glad the mask solution worked for you. It's often the cleanest approach for creating that hollow text effect with a stroke. If you need to explore more SVG filter effects in the future, feel free to ask!

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