Mornox Tools

CSS Gradient Generator

Create beautiful CSS gradients visually. Generate linear, radial, and conic gradients with live preview and copy the CSS code.

A CSS gradient is a mathematical rendering rule that instructs a web browser to smoothly transition between two or more colors across a specific spatial area, and a CSS gradient generator is a graphical interface that translates these visual design choices into the exact code required to render them. By mastering this concept, developers and designers can create rich, scalable, and bandwidth-efficient backgrounds without relying on heavy, static image files. This comprehensive guide will explore the deep mechanics, mathematics, syntax, and expert strategies for utilizing CSS gradients and generators to elevate modern web design and optimize digital performance.

What It Is and Why It Matters

To understand CSS gradients and the generators that create them, one must first understand the fundamental architecture of web design. Cascading Style Sheets (CSS) is the declarative language used to style and layout web pages. Within CSS, a gradient is a specific type of image generated by the browser's rendering engine rather than being downloaded from a server. It creates a smooth, continuous transition between two or more specified colors, known as color stops, along a defined axis or from a defined center point. A CSS gradient generator is a software tool, typically web-based, that provides a graphical user interface featuring sliders, color pickers, and angle dials. As the user manipulates these visual controls, the generator computes the geometry and color theory in real-time, outputting the exact CSS syntax required to reproduce that visual effect in any standard web browser.

The importance of CSS gradients cannot be overstated in the context of modern web performance and responsive design. Before the native implementation of CSS gradients, developers had to rely on raster image files, such as JPEGs or PNGs, to create color transitions. A simple gradient background might require a 50-kilobyte image file, which necessitates a separate HTTP request to the server, consuming bandwidth and delaying the page load time. Furthermore, raster images are resolution-dependent; if a user views the website on a high-density Retina display, or if the container expands beyond the image's original dimensions, the gradient will appear pixelated and degraded. CSS gradients solve all of these problems simultaneously. Because they are generated mathematically by the browser, a CSS gradient requires only a few bytes of text—often fewer than 100 characters. They scale infinitely without any loss of quality, adapting seamlessly to any screen size, aspect ratio, or pixel density. Understanding how to write and generate these gradients is a foundational skill for anyone looking to build fast, accessible, and visually compelling digital experiences.

History and Origin

The journey to native CSS gradients is a fascinating study in the evolution of web standards and browser competition. In the early days of the World Wide Web, during the late 1990s and early 2000s, backgrounds were strictly limited to solid colors or tiled image patterns. During the "Web 2.0" era, characterized by glossy buttons and reflective surfaces, designers desperately wanted smooth color transitions. To achieve this, developers employed a technique called "slicing," where they would create a gradient in Adobe Photoshop, slice a 1-pixel-wide vertical strip of that gradient, save it as a PNG, and use the CSS background-repeat: repeat-x property to tile it horizontally across the screen. This was highly inefficient, required constant trips back to image editing software for minor color tweaks, and bloated the total page weight with unnecessary image files.

The breakthrough occurred in 2008 when Apple's WebKit team—the developers behind the Safari browser engine—introduced the first proprietary CSS gradient specification. They implemented a function called -webkit-gradient(). However, the syntax was notoriously complex and counterintuitive, requiring developers to define a gradient type, starting point, ending point, and a series of from(), to(), and color-stop() functions. Recognizing the immense utility of the feature, the Mozilla Foundation quickly followed suit for their Firefox browser, introducing -moz-linear-gradient() in 2009 with a significantly simplified and more intuitive syntax. This sparked a period of fragmentation where developers had to use multiple "vendor prefixes" (-webkit-, -moz-, -o- for Opera, and -ms- for Internet Explorer) just to display a single gradient across different browsers.

Finally, in 2011, the World Wide Web Consortium (W3C), the main international standards organization for the web, officially standardized the syntax in the "CSS Image Values and Replaced Content Module Level 3" specification. They largely adopted Mozilla's cleaner syntax, giving birth to the standard linear-gradient() and radial-gradient() functions we use today. The standard continued to evolve, and in 2017, the W3C incorporated conic-gradient() into CSS Level 4, championed heavily by web standards advocate Lea Verou. Today, CSS gradients are universally supported across all modern browsers, standing as a testament to the collaborative, iterative process of web standardization.

Key Concepts and Terminology

To effectively use a CSS gradient generator or write the code manually, one must be fluent in the specific terminology that governs this technology. The most fundamental concept is the Color Stop. A color stop is a coordinate along the gradient line that specifies a precise color at a precise location. It consists of two parts: a color value (such as a hex code, RGB, or HSL value) and an optional length or percentage (such as 50% or 200px). If no position is specified, the browser automatically distributes the color stops evenly along the gradient line.

The Gradient Line is the invisible geometric axis along which the browser calculates the color transitions. In a linear gradient, this line passes through the center of the element. The angle of this line determines the direction of the gradient. Angles in CSS can be expressed in several units: degrees (deg), radians (rad), gradians (grad), or turns (turn). For example, 0deg points straight up (equivalent to "to top"), 90deg points to the right ("to right"), and 180deg points straight down ("to bottom"). Understanding how this angle interacts with the dimensions of the HTML element is crucial, as the gradient line automatically extends so that the starting and ending colors perfectly hit the corners of the box.

Another critical concept is Interpolation, which refers to the mathematical process the browser uses to calculate the intermediate colors between two defined color stops. By default, browsers historically interpolated colors in the sRGB Color Space, a standard gamut of colors used on the web. However, newer CSS specifications introduce the concept of specifying different color spaces for interpolation (such as Oklab or Oklch), which dramatically changes how the transition looks, preventing the "muddy" or gray midpoints that often plague sRGB transitions. Finally, the Alpha Channel is an essential term; it refers to the transparency of a color. Gradients are not limited to opaque colors; transitioning from a solid color to a completely transparent color (rgba(0,0,0,0)) is a standard technique for creating overlays and fading effects.

How It Works — Step by Step

When a browser encounters a CSS gradient rule, it does not treat it as a color; it treats it as an image generated on the fly. The standard syntax follows this structure: background-image: linear-gradient(direction, color-stop1, color-stop2, ...);. Let us walk through exactly how a browser parses and renders a specific rule, and how a generator builds it. Imagine you are using a generator and you set the angle dial to 135 degrees. You place a bright red color at the very beginning of the slider, and a bright blue color at the very end. The generator outputs: background-image: linear-gradient(135deg, rgb(255, 0, 0) 0%, rgb(0, 0, 255) 100%);.

First, the browser examines the target HTML element, let's say a <div> that is 400 pixels wide and 300 pixels tall. It establishes the center point of this box at coordinates (200, 150). Next, it draws the invisible Gradient Line passing through this center point at an angle of 135 degrees (pointing to the bottom right corner). The browser then determines the starting and ending points of the gradient line. It does this by drawing perpendicular lines from the gradient line to the corners of the <div> box. The point where the perpendicular line from the top-left corner intersects the gradient line becomes the 0% mark. The intersection from the bottom-right corner becomes the 100% mark.

Once the geometry is established, the browser maps the color stops. It places pure red (rgb(255, 0, 0)) exactly at the 0% mark and pure blue (rgb(0, 0, 255)) exactly at the 100% mark. Finally, the rendering engine iterates through every single pixel within the 400x300 box. For each pixel, it projects a perpendicular line onto the gradient line to find its percentage position. If a pixel projects onto the 50% mark of the gradient line, the browser calculates the exact midpoint color between red and blue. It then paints that specific pixel on the monitor. This calculation happens millions of times per second, utilizing the device's Graphics Processing Unit (GPU) to ensure the transition appears perfectly smooth to the human eye.

The Mathematics of Color Interpolation

To truly master CSS gradients, one must understand the underlying mathematics of color interpolation. When a browser calculates the color of a pixel located between two color stops, it uses linear interpolation (often abbreviated as "lerp"). The browser calculates the red, green, and blue channels entirely independently of one another. The fundamental formula for linear interpolation is:

C_result = C1 + (C2 - C1) * [ (P_target - P1) / (P2 - P1) ]

Where:

  • C_result is the final color channel value (R, G, or B) at the target position.
  • C1 is the color channel value of the first color stop.
  • C2 is the color channel value of the second color stop.
  • P1 is the percentage position of the first color stop.
  • P2 is the percentage position of the second color stop.
  • P_target is the percentage position of the pixel currently being calculated.

Let us perform a complete worked example. Assume we have the following CSS rule: linear-gradient(to right, rgb(100, 50, 0) 20%, rgb(200, 150, 250) 80%);. We want to mathematically determine the exact RGB color that the browser will render at exactly the 50% mark of the element.

First, we define our variables based on the CSS:

  • P1 = 20
  • P2 = 80
  • P_target = 50
  • The interpolation factor is: (50 - 20) / (80 - 20) = 30 / 60 = 0.5. (This means the 50% mark is exactly halfway between the 20% stop and the 80% stop).

Now, we calculate each color channel independently using the formula:

Red Channel Calculation:

  • C1_red = 100
  • C2_red = 200
  • Red_result = 100 + (200 - 100) * 0.5
  • Red_result = 100 + (100) * 0.5
  • Red_result = 100 + 50 = 150

Green Channel Calculation:

  • C1_green = 50
  • C2_green = 150
  • Green_result = 50 + (150 - 50) * 0.5
  • Green_result = 50 + (100) * 0.5
  • Green_result = 50 + 50 = 100

Blue Channel Calculation:

  • C1_blue = 0
  • C2_blue = 250
  • Blue_result = 0 + (250 - 0) * 0.5
  • Blue_result = 0 + (250) * 0.5
  • Blue_result = 0 + 125 = 125

Therefore, at exactly the 50% mark of this element, the browser will render the color rgb(150, 100, 125). A CSS gradient generator performs this exact mathematical operation in reverse when showing you a preview, calculating the pixel values across the preview canvas so you can see the result before copying the code.

Types, Variations, and Methods

The CSS specification defines three primary geometric variations of gradients, each serving distinct design purposes. The most common is the Linear Gradient (linear-gradient()), which transitions colors along a straight axis. As discussed, this is controlled by an angle or a directional keyword (e.g., to bottom right). Linear gradients are the workhorses of web design, used for everything from subtle button shading to full-page background washes. They are highly predictable and form the foundation of most user interface depth effects.

The second type is the Radial Gradient (radial-gradient()). Instead of transitioning along a straight line, a radial gradient transitions colors outward from a specific center point, creating a circular or elliptical shape. The syntax allows developers to define the shape (circle or ellipse), the size (closest-side, farthest-corner, etc.), and the exact X/Y coordinates of the center point. For example, radial-gradient(circle at 50% 50%, red, blue) creates a perfect red circle in the center of the element that smoothly fades into a blue background. Radial gradients are exceptionally useful for creating artificial lighting effects, such as a soft spotlight illuminating a product image, or for drawing the user's eye toward the center of a call-to-action container.

The third and newest type is the Conic Gradient (conic-gradient()). While a radial gradient radiates outward from the center, a conic gradient sweeps around the center point, much like the sweeping hand of a clock or the slices of a pie chart. The color stops in a conic gradient are defined by angles (degrees or percentages of a circle) rather than linear lengths. For example, conic-gradient(red 0deg, blue 180deg, red 360deg) creates a metallic, cone-like 3D effect. Beyond these three primary types, CSS also provides Repeating Gradients (repeating-linear-gradient(), repeating-radial-gradient(), repeating-conic-gradient()). These functions take the defined color stops and tile them infinitely to fill the container. By placing hard color stops close together, developers can use repeating gradients to generate complex geometric patterns like stripes, checkerboards, and grid paper without using any external image files.

Real-World Examples and Applications

To understand the practical power of CSS gradients, we must look at concrete, real-world scenarios where they solve specific design problems. Consider a common layout pattern: The Hero Image Overlay. A designer has a high-resolution, full-width photograph at the top of a webpage, and they need to place white headline text over it. Because photographs have varying areas of light and dark, the white text might be unreadable against a light portion of the image. The solution is a CSS gradient overlay. By applying background-image: linear-gradient(to bottom, rgba(0,0,0,0) 0%, rgba(0,0,0,0.8) 100%), url('hero.jpg');, the developer creates a gradient that is completely transparent at the top and smoothly transitions to 80% opaque black at the bottom. This ensures the text sitting at the bottom of the hero section has a dark, high-contrast background, while the top of the photograph remains fully visible.

Another powerful application is creating Data Visualizations and Progress Bars. Imagine a dashboard tracking a user's budget. A 35-year-old earning $85,000 has spent 65% of their monthly allowance. Instead of using complex JavaScript or SVG to draw a progress bar, a developer can use a single HTML <div> and a linear gradient with "hard stops." A hard stop occurs when two different colors are assigned the exact same percentage position, eliminating the smooth transition and creating a sharp line. The CSS linear-gradient(to right, #4CAF50 0%, #4CAF50 65%, #E0E0E0 65%, #E0E0E0 100%) instantly creates a progress bar that is solid green for exactly 65% of its width and solid gray for the remaining 35%.

A third example is the replication of Complex Branding Assets. The iconic Instagram logo background is not a static image file; in modern web environments, it is often replicated entirely using a complex CSS gradient. It utilizes a radial gradient layered with linear gradients to achieve its signature vibrant wash. A simplified version looks something like background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%, #d6249f 60%, #285AEB 90%);. By using a CSS gradient generator, a developer can easily tweak these precise percentages and hex codes to perfectly match a company's brand guidelines, ensuring the branding scales perfectly on a massive 4K monitor or a tiny smartwatch screen.

Common Mistakes and Misconceptions

Despite their ubiquity, CSS gradients are frequently misunderstood by beginners, leading to frustrating bugs and suboptimal designs. The most prevalent misconception is treating gradients as a background color. Beginners frequently attempt to write background-color: linear-gradient(...) and are confused when the browser renders nothing. Gradients are mathematically generated images. Therefore, they must be applied to the background-image property, or the shorthand background property. Because they are images, they can be layered on top of actual background colors or other background images using comma separation, which is impossible with standard colors.

Another highly common mistake is creating what designers call the "Gray Dead Zone". This occurs when a developer attempts to transition between two highly saturated, complementary colors in the default sRGB color space—for example, transitioning from pure green (#00FF00) to pure magenta (#FF00FF). Because the browser mathematically interpolates the RGB values straight across the color wheel, the midpoint calculation results in a desaturated, muddy gray color (#808080) that looks visually unappealing. Beginners often assume the generator is broken. The solution is to manually add a third color stop in the middle (like a bright blue or yellow) to "route" the gradient around the outside of the color wheel, or to use newer CSS Color Level 4 properties to specify an interpolation color space like in hsl or in oklch.

A third pitfall involves misunderstanding how percentages map to physical dimensions. If a developer writes linear-gradient(to right, red 10%, blue 90%) on a container that is 1000 pixels wide, the pure red stops at 100 pixels, the pure blue begins at 900 pixels, and the transition happens over the 800 pixels in between. However, if the container shrinks to 100 pixels wide on a mobile device, the transition now happens over just 80 pixels. This dynamic scaling can cause gradients to look vastly different across devices. Beginners often fail to test their gradients on multiple viewport sizes, resulting in transitions that look beautiful on a desktop but become compressed and harsh on a mobile phone.

Best Practices and Expert Strategies

Professional front-end developers employ specific strategies to elevate simple gradients into robust, maintainable, and visually stunning design elements. One of the most important best practices is the use of Non-Linear Easing. In nature, light and shadows rarely transition in a perfectly linear mathematical fashion. Standard CSS gradients often look rigid or artificial because the linear interpolation creates a perceived "sharp edge" where the gradient begins or ends. Experts solve this by using multiple color stops to simulate a cubic-bezier easing curve (similar to CSS animations). Instead of a simple transparent to black transition, an expert might write a 10-stop gradient that eases into the blackness slowly at first, then accelerates, creating a much softer, more photographic shadow effect. Many advanced CSS gradient generators now include "easing" toggles that automatically generate these complex multi-stop rules.

Another expert strategy is the integration of CSS Custom Properties (Variables) with gradients. Hard-coding hex values into a gradient makes maintaining a large codebase difficult. If the brand's primary color changes, the developer must hunt down every instance of that hex code. Instead, professionals define variables at the root level: :root { --brand-start: #ff7e5f; --brand-end: #feb47b; }. They then apply these variables to the gradient: background-image: linear-gradient(135deg, var(--brand-start), var(--brand-end));. This approach is particularly powerful for implementing Dark Mode. By simply redefining the variables in a @media (prefers-color-scheme: dark) query, every gradient on the website instantly updates to a dark-themed equivalent without having to rewrite the gradient geometry.

Furthermore, experts frequently use the technique of Gradient Stacking. The background-image property accepts multiple comma-separated values. The first value in the list is rendered on top, the next value is rendered beneath it, and so on. By stacking multiple gradients with transparent sections, developers can create incredibly complex, resolution-independent patterns. For example, stacking two repeating linear gradients at 90-degree angles to each other can create a perfect plaid or tartan pattern. Stacking a radial gradient over a linear gradient can create a textured, 3D button effect. Mastering the Z-axis of background images is what separates basic gradient usage from advanced CSS artistry.

Edge Cases, Limitations, and Pitfalls

While highly versatile, CSS gradients are not without their physical and technical limitations. The most notorious edge case is Color Banding. Banding manifests as visible, distinct stripes or "steps" of color rather than a perfectly smooth transition. This occurs because standard computer monitors operate on an 8-bit color depth, meaning there are only 256 possible shades of red, green, and blue. If you stretch a gradient over a very large area—for example, a 2,000-pixel wide background transitioning from #111111 to #222222—the browser has to stretch only 17 available shades of gray across 2,000 pixels. The math dictates that each shade must be over 100 pixels wide, resulting in visible bands. The primary workaround for this hardware limitation is to overlay a subtle, semi-transparent noise texture (a tiny repeating PNG or SVG) over the gradient. The noise introduces optical dithering, tricking the human eye into perceiving a perfectly smooth blend.

Performance is another critical limitation, particularly on low-powered mobile devices. While a single linear gradient is computationally cheap, stacking multiple complex radial gradients, or animating gradients over large areas, can cause significant "paint lag." When a gradient is animated (for instance, shifting the background-position to create a shimmering effect), the browser must recalculate the pixel colors for every frame of the animation (ideally 60 times per second). If the gradient covers the entire screen, this can overwhelm a mobile GPU, causing the device to heat up and the scrolling to stutter. Developers must profile their gradient animations using browser developer tools to ensure they are not causing performance bottlenecks.

Finally, print stylesheets present a unique pitfall. By default, almost all modern web browsers strip out background images and background colors when a user attempts to print a webpage. This is a deliberate feature designed to save the user's expensive printer ink. However, if your website relies on a dark CSS gradient background with white text on top, printing the page will result in invisible white text on a blank white piece of paper. Developers must explicitly handle this edge case by writing a @media print query that changes the text color to black and removes the gradient, or by using the non-standard -webkit-print-color-adjust: exact; property if the gradient is absolutely necessary for the printed document.

Industry Standards and Benchmarks

In professional web development, the use of CSS gradients is governed by strict accessibility standards and performance benchmarks. The most critical standard is the Web Content Accessibility Guidelines (WCAG), maintained by the W3C. WCAG 2.1 Level AA requires that regular text have a contrast ratio of at least 4.5:1 against its background, and large text (18pt or 14pt bold) have a ratio of at least 3.0:1. When text is placed over a solid color, this is easy to calculate. However, when text sits over a gradient, the background color is constantly changing. The industry standard practice is to measure the contrast ratio against the lightest or darkest part of the gradient that the text touches. If a gradient transitions from dark blue to light blue, and white text spans across it, the developer must ensure the contrast ratio between the white text and the lightest blue section still meets the 4.5:1 threshold. Failure to do so renders the site inaccessible to visually impaired users and legally non-compliant in many jurisdictions.

From a performance benchmarking perspective, CSS gradients are the gold standard for payload reduction. A typical performance budget for a modern web page aims to keep the total initial payload under 500 kilobytes. If a designer creates a full-screen, high-resolution gradient background in Photoshop and saves it as a high-quality JPEG, the file size will typically range from 150KB to 300KB. This single visual asset consumes up to 60% of the performance budget. In stark contrast, the CSS code to generate that exact same visual effect is typically between 50 and 150 bytes. By replacing the raster image with a CSS gradient, the developer achieves a 99.9% reduction in payload size for that asset. This benchmark is a primary reason why performance audits (like Google Lighthouse) heavily penalize the use of large images for simple background patterns.

Browser support is another crucial benchmark. In the current landscape, the standard linear-gradient() and radial-gradient() functions enjoy over 97% global support across all devices, according to data from CanIUse.com. This means developers no longer need to rely on vendor prefixes (-webkit-, -moz-) for standard gradients, nor do they need to provide solid-color fallbacks for ancient browsers like Internet Explorer 9, which has been officially deprecated. However, newer features like conic-gradient() and advanced color space interpolation (e.g., in oklch) have lower support benchmarks (around 90-93%). When utilizing these cutting-edge features, industry standards dictate using a @supports feature query to provide a standard linear gradient as a fallback for browsers that have not yet implemented the newer specifications.

Comparisons with Alternatives

While CSS gradients are powerful, they are not the only method for drawing color transitions on the web. Understanding how they compare to alternatives is vital for choosing the right tool for the job. The most direct alternative is SVG Gradients (Scalable Vector Graphics). Like CSS, SVG gradients are mathematically generated, resolution-independent, and perfectly scalable. However, SVG gradients are defined within HTML markup using <linearGradient> and <radialGradient> tags, and applied to vector shapes using the fill attribute. The primary difference lies in the use case. CSS gradients are optimal for styling the rectangular box model of the DOM (backgrounds, buttons, overlays). SVG gradients are optimal for complex, non-rectangular vector illustrations, logos, and icons. Furthermore, SVG supports complex gradient morphing and path-following that CSS simply cannot achieve natively.

Another alternative is the use of Raster Images (JPEG, PNG, WebP). As discussed, raster images are generally inferior to CSS gradients for simple background transitions due to file size and pixelation. However, there is a specific scenario where a raster image is superior: highly complex, photographic, or textured gradients. If a designer creates a gradient that includes photographic noise, complex masking, or abstract, fluid "mesh" shapes (like the macOS Monterey wallpaper), a CSS gradient cannot easily replicate this. While advanced developers can sometimes hack together CSS mesh gradients using dozens of overlapping radial gradients, the resulting code is often heavier and slower to render than a highly compressed WebP image. In cases of extreme visual complexity, a modern raster format is the better choice.

Finally, there is the HTML5 Canvas API. Canvas allows developers to draw gradients imperatively using JavaScript (ctx.createLinearGradient()). The comparison here is between declarative and imperative programming. CSS is declarative; you tell the browser what you want, and the browser's highly optimized internal engine figures out how to draw it. Canvas is imperative; you must write JavaScript to tell the browser exactly how to draw every pixel frame by frame. Canvas gradients are generally unnecessary for standard UI design. However, if you are building a browser-based video game, a highly interactive particle system, or a data visualization tool that requires manipulating thousands of gradients at 60 frames per second based on complex user input, the Canvas API (or WebGL) provides the low-level control and rendering performance that standard CSS cannot match.

Frequently Asked Questions

Can I animate a CSS gradient? Yes, but with caveats. You cannot natively animate the color stops or angles of a background-image using standard CSS transition properties in older browsers, because browsers historically could not interpolate between two different image states. The traditional workaround is to create a gradient that is larger than the container (e.g., background-size: 200% 200%) and animate the background-position property to slide the gradient back and forth. However, in modern browsers supporting the CSS @property rule (Houdini API), you can define custom variables as colors and animate those variables directly, allowing for true, smooth color-stop animation.

Why does my gradient look gray and muddy in the middle? This is a mathematical artifact of interpolating colors in the default sRGB color space. When you transition between two complementary colors (colors on opposite sides of the color wheel, like blue and yellow, or red and cyan), the mathematical midpoint of their RGB values is a desaturated gray. To fix this, you must either manually add a third color stop in the middle of your CSS rule to push the transition toward a more vibrant hue, or use the newer CSS Color Level 4 syntax to specify a different interpolation space, such as linear-gradient(in oklch to right, blue, yellow).

How many color stops can I add to a single gradient? Theoretically, the CSS specification does not impose a strict limit on the number of color stops you can include in a single gradient function. You can add dozens or even hundreds of stops separated by commas. Practically, however, you are limited by human readability, code maintainability, and eventually, browser parsing memory. Most complex gradients (like mimicking a detailed rainbow or a metallic texture) rarely require more than 10 to 15 color stops. If you find yourself writing hundreds of stops, an SVG or a highly compressed WebP image might be a more efficient approach.

How do I make a hard line instead of a smooth color transition? To create a hard line, also known as a "hard stop," you must assign two different colors to the exact same percentage or length position along the gradient line. For example, linear-gradient(to right, red 0%, red 50%, blue 50%, blue 100%). Because the browser has zero pixels of distance between the end of the red stop (50%) and the beginning of the blue stop (50%), it cannot perform any interpolation. The result is a sharp, pixel-perfect line exactly in the middle of the element, which is highly useful for creating stripes, flags, or progress bars.

What is the difference between deg and turn when setting angles? Both deg (degrees) and turn are valid units for defining the angle of a linear or conic gradient. Degrees operate on a standard 360-degree circle, where 0deg points to the top, 90deg points to the right, 180deg points to the bottom, and so on. The turn unit simply represents fractions of that full circle. Therefore, 1turn is exactly equal to 360deg. 0.25turn is equal to 90deg, and 0.5turn is equal to 180deg. Many modern developers prefer turn for conic gradients because it is mathematically easier to visualize fractions of a pie chart than to calculate specific degree angles.

Can I apply a CSS gradient to typography instead of a background? Yes, applying gradients to text is a highly popular modern design trend. However, there is no direct text-gradient property in CSS. Instead, developers achieve this effect by applying a standard gradient to the background of the text element, and then using two specific properties to mask it. You must apply background-clip: text; (often requiring the -webkit- prefix), which clips the background image exactly to the shape of the typography. Then, you must set the text color itself to transparent using color: transparent;. This allows the clipped background gradient to show through the invisible letters.

Command Palette

Search for a command to run...