Open In App

SVG patternContentUnits Attribute

The patternContentUnits attribute is used to indicate which coordinate system must be used for the contents of the <pattern> element.

Syntax:



patternContentUnits ="userSpaceOnUse"

// Or 

patternContentUnits ="objectBoundingBox"

Attribute Values: The patternContentUnits attribute accepts the values mentioned above and described below:

Note: Default value is userSpaceOnUse.



Example 1: Below is the example that illustrated the use of patternContentUnits attribute using objectBoundingBox value.




<!DOCTYPE html>
<html>
  
<body>
    <h1 style="color: green; 
        margin-left: 2%;">
        GeeksforGeeks
    </h1>
  
    <svg viewBox="0 0 300 200" 
        xmlns="http://www.w3.org/2000/svg">
          
        <pattern id="geek2" width="40%" 
            height="40%" fill="green" 
            patternContentUnits="objectBoundingBox">
              
            <ellipse cx=".2" cy=".1" rx=".2" ry=".1" />
        </pattern>
          
        <rect width="50" height="50" 
            fill="url(#geek2)" />
    </svg>
</body>
  
</html>

Output: Below is the output generated corresponding to the above code

Example 2: Below is the example that illustrated the use of patternContentUnits attribute using userSpaceOnUse value.




<!DOCTYPE html>
<html>
  
<body>
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
  
    <svg viewBox="0 0 200 200" 
        xmlns="http://www.w3.org/2000/svg">
          
        <pattern id="geek2" width="40%" 
            height="40%" fill="green" 
            patternContentUnits="userSpaceOnUse">
              
            <ellipse cx="5" cy="5" rx="2" ry="1" />
        </pattern>
          
        <rect width="50" height="50" 
            fill="url(#geek2)" />
    </svg>
</body>
  
</html>

Output: Below is the output generated corresponding to the above code


Article Tags :