<feComposite>

Combines two images using a mathematical or logical operation in an SVG tag on an HTML page.
2 min read
Believemy logo

The <feComposite> tag is an SVG primitive used to combine two images or other graphics using a mathematical operation.

It allows, for example, to:

  • mask;
  • overlay;
  • or blend;

graphic elements, offering precise control over their interaction.

Good to know

Use <feComposite> to apply masking, intersection, or blending effects to your SVG graphics.

 

Structure and syntax of the <feComposite> tag

The <feComposite> tag is always used within an <svg> tag.

Here is a simple example:

HTML
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
    <defs>
        <filter id="compositeExample">
            <feFlood flood-color="blue" result="blueFill" />
            <feFlood flood-color="red" result="redFill" />
            <feComposite in="blueFill" in2="redFill" operator="xor" result="combined" />
        </filter>
   </defs>

    <rect x="10" y="10" width="180" height="180" filter="url(#compositeExample)" />
</svg>

In this example:

  • <feFlood> creates two floods of colors (blue and red);
  • <feComposite> combines the two floods using the xor operator (for mutual exclusion).

Here is our result:

 

Main attributes of <feComposite>

AttributeDescriptionPossible values
inSpecifies the first source graphic to use.Can be a direct source (e.g., SourceGraphic) or an intermediate result (defined by result in other primitives).
in2Specifies the second source graphic to use.Same as in.
operatorDetermines the mathematical or logical operation to apply to combine in and in2.
  • over: Places in over in2.
  • in: Displays only the parts of in that overlap with in2.
  • out: Displays only the parts of in that do not overlap with in2.
  • atop: Displays in over in2, but only where in2 is present.
  • xor: Displays the areas where either in or in2 is present, but not both.
k1, k2, k3, k4Coefficients for customizing calculations when using the arithmetic operator.Numerical values.

 

Browser compatibility

The <feComposite> tag is supported by the majority of modern browsers:

BrowserCompatibility
ChromeYes
FirefoxYes
SafariYes
EdgeYes
Internet ExplorerPartial (IE 10+)

Related terms

Discover our hTML and CSS glossary

Browse the terms and definitions most commonly used in HTML and CSS development.

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.