How-to Guide 5 min read

CSS Gradient Hard Stops: Sharp Colour Splits and Stripes

How to make a CSS gradient with a sharp edge instead of a blend: two stops at one position, split backgrounds, stripes, pie charts and the stop-order gotcha.

css gradient hard stopcss gradient without blendingcss split background two colorscss stripes gradientlinear-gradient sharp edge

The short answer

A CSS gradient has a hard edge wherever two colour stops share the same position. linear-gradient(90deg, #4f6ef7 50%, #7c3aed 50%) gives a left half that is solid blue and a right half that is solid purple, with no blend. In the free CSS Gradient Generator, add stops and drag two neighbouring stops to the same percentage, then copy the CSS.

How gradient stops work

Each colour stop is a colour plus a position. Between two stops, the browser blends from one colour to the next. The distance between the stops decides how long the blend is:

  • Stops at 0% and 100%: the blend takes the whole width.
  • Stops at 40% and 60%: solid colour up to 40%, a short blend, then solid colour from 60%.
  • Stops at 50% and 50%: the blend has zero width, so you see a sharp line.

That third case is a hard stop. There is no special syntax; it's just two stops at the same place.

Example 1: a two-colour split background

background: linear-gradient(90deg, #4f6ef7 0%, #4f6ef7 50%, #7c3aed 50%, #7c3aed 100%);

Reading it left to right:

  • 0% to 50%: blue to blue, so solid blue
  • At 50%: blue to purple with no distance, so a sharp edge
  • 50% to 100%: purple to purple, so solid purple

The angle sets the direction. 90deg runs left to right, 180deg top to bottom, and 135deg gives a diagonal split from top left to bottom right.

You may also see a shorter form, linear-gradient(90deg, #4f6ef7 50%, #7c3aed 50%). Before its first stop a gradient shows the first colour, and after its last stop the last colour, so the outer stops aren't needed. Both forms give the same result.

Example 2: three equal bands

background: linear-gradient(180deg, #ff9933 0%, #ff9933 33%, #ffffff 33%, #ffffff 67%, #138808 67%, #138808 100%);

Six stops make three solid horizontal bands. Change the angle to 90deg for vertical bands.

Example 3: a pie chart with conic-gradient

Hard stops work in conic gradients too, which makes a simple pie chart:

background: conic-gradient(from 0deg, #4f6ef7 0%, #4f6ef7 40%, #7c3aed 40%, #7c3aed 75%, #10b981 75%, #10b981 100%);

Add border-radius: 50%; to the same element to make it round.

That gives slices of 40%, 35% and 25%, starting at the top and going clockwise.

Making a hard stop in the generator

The generator starts with two stops: #4f6ef7 at 0% and #7c3aed at 100%.

  • Choose Linear (or Conic for a pie).
  • Click "+ Add stop" twice. Each new stop is added at the bottom of the list, at 50%, in green (#10b981).
  • Edit the stops so the positions increase down the list. The CSS is written in list order, so set them like this:
  • Stop in the listColourPosition
    1Colour A0%
    2Colour A50%
    3Colour B50%
    4Colour B100%
  • Set the angle with the slider (0° to 360°). Radial mode has no angle; it always uses a circle.
  • Copy the CSS. The output is a single background: line you can paste into your stylesheet.
  • Positions move in whole percentages from 0 to 100, which covers splits like 50/50 or 33/67. If you need exact values such as 33.333%, edit the copied CSS by hand.

    The ordering gotcha

    This catches people out in the generator and in hand-written CSS. If a stop's position is smaller than an earlier stop's position, the browser moves it up to match the earlier one.

    Say your list ends up as A 0%, B 100%, C 50%, D 50% because you added two stops and forgot to reorder them. The browser treats C and D as if they were at 100%. You see a blend from A to B across the whole box, and C barely appears.

    The fix is to make sure positions never go down as you read the list. In the generator, change the colours and positions of the existing rows rather than relying on the order in which you added them.

    Repeating stripes

    The generator writes linear-gradient, not repeating-linear-gradient. For diagonal stripes, copy the CSS and change it by hand:

    background: repeating-linear-gradient(45deg, #4f6ef7 0px, #4f6ef7 10px, #7c3aed 10px, #7c3aed 20px);

    The pattern (10px blue, 10px purple) repeats across the whole element. Using pixels instead of percentages keeps the stripe width the same on any box size.

    Jagged edges on diagonal hard stops

    A hard stop at an angle such as 45deg can look slightly stepped, especially on low-resolution screens, because the browser has no blend to smooth it. If that bothers you, add a tiny gap of about 1px, for example #4f6ef7 50%, #7c3aed calc(50% + 1px). That leaves a one-pixel blend that reads as a clean line.

    Common mistakes

    • Using positions that are close but not equal. 50% and 52% gives a soft 2% blend, not a hard edge.
    • Stops out of order. See the gotcha above: later stops with smaller positions are moved up.
    • Expecting radial gradients to take an angle. Radial gradients spread out from a centre; angles only apply to linear and conic.
    • Hard-coding colours you'll change later. If the split is part of a theme, use CSS variables for the colours.

    For a broader overview of linear, radial and conic gradients, see CSS gradients explained. To pick or convert the colours themselves, use the Color Picker.

    Frequently asked questions

    How do I make a CSS gradient without blending?

    Give two neighbouring colour stops the same position, for example linear-gradient(90deg, blue 50%, purple 50%). The blend between them has zero width, so you get a sharp edge.

    How do I split a background into two colours with CSS?

    Use linear-gradient(90deg, colourA 0%, colourA 50%, colourB 50%, colourB 100%). Change 90deg to 180deg for a top and bottom split.

    Why is my hard-stop gradient not showing the colour I added?

    If a stop's position is smaller than an earlier stop's position, the browser moves it up to the earlier position. Make sure positions never decrease as you read the list.

    Can I make repeating stripes with the CSS Gradient Generator?

    The generator outputs linear, radial and conic gradients. For stripes, copy the CSS and change it to repeating-linear-gradient with pixel stop positions.

    Try this tool on Lazyblink

    Put this guide into practice with our free online tool — no signup required.

    Open tool