• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Css Basic: gradientUnits

December 20, 2023

CSS Basics: gradientUnits

In CSS, gradients are a popular way to add visual interest and depth to backgrounds and elements. With the gradientUnits property, you can control how the gradient is rendered and positioned within an element.

Understanding gradientUnits

The gradientUnits property is used in conjunction with the linear-gradient() and radial-gradient() functions to define the coordinate system for the gradient. It determines whether the gradient is sized and positioned relative to the element’s bounding box or the entire page.

There are two possible values for the gradientUnits property:

  • objectBoundingBox: This value specifies that the gradient is sized and positioned relative to the bounding box of the element. The bounding box is the smallest rectangle that encloses the element’s content, padding, and border.
  • userSpaceOnUse: This value specifies that the gradient is sized and positioned relative to the entire page. It uses the coordinate system of the SVG viewport, which is typically the size of the browser window.

Examples

Let’s take a look at some examples to understand how the gradientUnits property works.

Example 1: objectBoundingBox

.gradient {
  background: linear-gradient(to right, red, blue);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  gradientUnits: objectBoundingBox;
}

In this example, the gradient is applied to the text within an element. The gradientUnits property is set to objectBoundingBox, which means the gradient is sized and positioned relative to the bounding box of the text. This ensures that the gradient is contained within the text and doesn’t overflow to the surrounding area.

Example 2: userSpaceOnUse

.gradient {
  background: radial-gradient(circle, yellow, green);
  gradientUnits: userSpaceOnUse;
}

In this example, the gradient is applied to the background of an element. The gradientUnits property is set to userSpaceOnUse, which means the gradient is sized and positioned relative to the entire page. This allows the gradient to cover the entire background of the element, regardless of its size or position.

Conclusion

The gradientUnits property in CSS allows you to control how gradients are sized and positioned within elements. By understanding the two possible values, objectBoundingBox and userSpaceOnUse, you can create visually appealing gradients that enhance the design of your website.

Summary

In summary, the gradientUnits property in CSS is used to define the coordinate system for gradients. It can be set to objectBoundingBox or userSpaceOnUse. To learn more about CSS and how it can enhance your website, visit Server.HK.

Recent Posts

  • CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  • Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  • Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 2026
  • Hong Kong VPS vs Singapore VPS: Which Is Better for Your Asia Business in 2026?
  • How to Migrate from CentOS 8 to AlmaLinux or Rocky Linux Safely

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot