Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

How to Create a Linear Gradient in CSS

Learn the CSS linear-gradient() syntax, then customize direction, color-stop positions, hard edges, and repeating patterns.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use CSS’s linear-gradient() function as a background image. For a left-to-right blue-to-purple gradient, write:

.element {
  background: linear-gradient(to right, #2563eb, #a855f7);
}

Change the direction, colors, and color-stop positions to control the result. A gradient is an image value, so use it with background or another property that accepts images—not background-color, which accepts a color.

How linear-gradient() works

The function creates an image whose colors transition along a line. Its first argument can set the line’s direction; the remaining arguments specify colors and, optionally, where each color appears. The W3C’s CSS Images Module Level 3 defines the first argument as the gradient line, which determines its direction and the positioning of color stops.

A gradient has no intrinsic dimensions. It is drawn within the box where the image is used, so the element’s dimensions affect how the gradient appears. The basic pattern is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
background: linear-gradient(direction, color1, color2);

The direction is optional, but at least two colors are needed.

Set the gradient direction

Use side or corner keywords

If you omit the direction, the gradient runs downward, from the top of the element to the bottom. Use to followed by a side or corner to choose another direction:

.right {
  background: linear-gradient(to right, #2563eb, #a855f7);
}

.diagonal {
  background: linear-gradient(to bottom right, #2563eb, #a855f7);
}

Other examples include to top and to left. Direction keywords describe where the gradient is headed; to right means it moves from left to right.

Use an angle

Angles provide more precise control. CSS gradient angles start at upward: 0deg points up, and positive values turn clockwise. That means 90deg points right, 180deg points down, and 270deg points left.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.angled {
  background: linear-gradient(135deg, #f97316, #7c3aed);
}

Choose a keyword for a direction that reads naturally, or an angle when you want a specific slant. For a practical guide to gradients and their direction, see MDN’s guide to using CSS gradients.

Position colors with stops

Color stops determine which colors appear and where transitions happen. If you leave stop positions out, the first and last colors anchor the ends and any intervening unpositioned colors are distributed between their neighboring stops.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
.banner {
  background: linear-gradient(
    90deg,
    #0f172a 0%,
    #2563eb 55%,
    #e0f2fe 100%
  );
}

Here, the middle color is placed at 55% along the gradient line. Positions may be percentages or lengths. Adjusting them changes the portions of the gradient occupied by each color and the location of each transition.

Create a hard edge

Give two different colors the same stop position to create a sharp boundary instead of a gradual blend. For a two-color split, specify the beginning and end positions of each color:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.stripe {
  background: linear-gradient(90deg, #2563eb 0 50%, #f97316 50% 100%);
}

Both colors meet at 50%, so there is no blended band between them. This is useful for stripes, blocks, or a two-tone background.

Shift the transition midpoint

A percentage color hint between two color stops can shift where the transition reaches its midpoint. A hint changes the distribution of the blend between those colors; it is not an extra color stop.

Repeat a gradient pattern

Use repeating-linear-gradient() when the pattern should repeat across the image. The distance between its first and last stop sets the repeating segment. If the colors at the segment boundary differ, the repeat can create a hard seam; matching the boundary colors allows a continuous transition across repetitions.

.pinstripe {
  background: repeating-linear-gradient(
    45deg,
    #1d4ed8 0 8px,
    #dbeafe 8px 16px
  );
}

This example repeats alternating 8-pixel color bands. For the function’s syntax, see MDN’s repeating-linear-gradient() reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use newer color-space interpolation carefully

CSS Images Module Level 4 adds optional color-interpolation syntax. For example, linear-gradient(90deg in oklab, blue, red) specifies the oklab color space for interpolation; hsl is another possible choice. This is distinct from the basic gradient syntax, and newer interpolation options are not implemented in every browser. Check support for the browsers you target before depending on one. The specification is documented in the W3C CSS Images Module Level 4. MDN describes basic linear-gradient() as widely available since July 2015, but that broad support statement does not guarantee support for every newer interpolation feature. See the MDN linear-gradient() reference.

Common problems and fixes

  • The gradient does not appear: Check that you assigned it to an image-accepting property such as background. background-color accepts a color, not a gradient image.
  • The direction seems reversed or unexpected: Remember that the default runs downward. For angles, zero points up and positive angles rotate clockwise; use to right for a left-to-right gradient.
  • The transition is not where you want it: Set explicit stop positions, then adjust them. Unpositioned stops are distributed between their neighboring stops.
  • You wanted a solid boundary, but got a blend: Give the adjacent colors the same stop position.
  • The repeated pattern has an unwanted seam: Check the first and last colors at the repeat boundary. Different colors there make a hard seam.
  • A newer interpolation form fails in a target browser: Use the basic gradient syntax or another supported form, and verify the newer feature against the browsers you need to support.

Or skip the browser setup

If you need a screenshot of a page with your gradient, ScreenshotNeo can return an image or PDF from one API request. Its clean-shot steps can accept cookie or consent banners and remove 60+ known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify the page verdict and billing status in headers. An MCP server also lets AI agents use take_screenshot, get_page_info, and capture_pdf.

Example request (replace the URL with your page and provide your API key):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.