How to Create Beautiful CSS Gradients (with Code)

A hands-on guide to linear, radial, and conic gradients with copy-paste code snippets.

🌈 🎨 💻 ✨ 🖌️

TL;DR: CSS gradients let you create beautiful color transitions without any image files. There are three types: linear (straight line), radial (circular), and conic (pie-chart style). They are GPU-rendered, infinitely scalable, and surprisingly easy once you get the syntax down.

Let me be honest: solid-color backgrounds are fine. They get the job done. But gradients? Gradients add personality. They give your designs depth, warmth, and that little spark of "wow, this looks polished" — all without loading a single image file.

The best part? CSS gradients are rendered by the browser in real time. They scale to any screen size, look crispy on retina displays, and weigh exactly zero kilobytes in your download. Let me walk you through everything you need to know.

Why did the CSS gradient break up with the solid color? Because their relationship lacked depth.

The Three Flavors of CSS Gradients

Think of CSS gradients like ice cream — they come in three flavors:

All three are used as values for background or background-image. Quick heads up: they do NOT work with background-color (that property only accepts solid colors).

➡️ Linear = straight line, Radial = spotlight, Conic = pie chart

Linear Gradients: The Workhorse

Linear gradients are the ones you will reach for 90% of the time. Colors blend along a straight line in whatever direction you choose:

/* Top to bottom (default) */
background: linear-gradient(#3498db, #2ecc71);

/* Left to right */
background: linear-gradient(to right, #3498db, #2ecc71);

/* Diagonal */
background: linear-gradient(to bottom right, #3498db, #2ecc71);

/* Custom angle (135 degrees) */
background: linear-gradient(135deg, #3498db, #2ecc71);

The angle system: 0deg points up, 90deg points right, 180deg points down. Think of it like a clock starting at 12 o'clock and going clockwise.

Adding Multiple Color Stops

Two colors is just the beginning. You can add as many as you want, and each one can have a specific position:

background: linear-gradient(
  90deg,
  #ee7752 0%,
  #e73c7e 25%,
  #23a6d5 50%,
  #23d5ab 100%
);

Hard Stops: No Blending Allowed

Want a sharp edge between two colors instead of a smooth transition? Set two adjacent colors to the same position. This is great for creating stripes or split-tone effects:

/* Clean two-tone split */
background: linear-gradient(
  to right,
  #3498db 0%, #3498db 50%,
  #e74c3c 50%, #e74c3c 100%
);

Radial Gradients: The Spotlight Effect

Radial gradients start at a point and radiate outward. They are perfect for creating glows, vignettes, or that subtle "light source" effect behind hero text:

/* Default: ellipse from center */
background: radial-gradient(#3498db, #2c3e50);

/* Circle shape */
background: radial-gradient(circle, #3498db, #2c3e50);

/* Off-center spotlight */
background: radial-gradient(circle at top left, #3498db, #2c3e50);
💡 Radial gradients are your go-to for that "glowing orb" background effect

Conic Gradients: The Fun One

Conic gradients sweep colors around a center point. They are relatively new to CSS and absolutely awesome for things like color wheels, pie charts, and decorative backgrounds:

/* Rainbow color wheel */
background: conic-gradient(red, yellow, green, cyan, blue, magenta, red);

/* Simple pie chart */
background: conic-gradient(
  #e74c3c 0% 40%,
  #3498db 40% 70%,
  #2ecc71 70% 100%
);

Repeating Gradients: Patterns for Free

All three gradient types have repeating versions that tile automatically. This is how people create those cool stripe and ring patterns in pure CSS:

/* Diagonal candy stripes */
background: repeating-linear-gradient(
  45deg,
  #3498db 0px, #3498db 10px,
  #2c3e50 10px, #2c3e50 20px
);

/* Bullseye rings */
background: repeating-radial-gradient(
  circle,
  #3498db 0px, #3498db 10px,
  transparent 10px, transparent 20px
);

Cool Gradient Tricks

Gradient Text

Yes, you can apply a gradient directly to text. It uses a little CSS wizardry with background clipping:

.gradient-text {
  background: linear-gradient(90deg, #ee7752, #e73c7e, #23a6d5);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;  /* fallback */
}

Gradient Borders

CSS doesn't have a border-gradient property (yet), but you can fake it with border-image:

.gradient-border {
  border: 3px solid;
  border-image: linear-gradient(to right, #3498db, #e74c3c) 1;
}

Heads up: border-image does NOT work with border-radius. For rounded gradient borders, you will need a wrapper element trick — gradient background on the outer element, solid background on the inner one, with padding creating the "border."

Ready-to-Use Gradient Recipes

Here are some crowd favorites you can copy right now:

/* Sunset */
background: linear-gradient(to right, #f12711, #f5af19);

/* Ocean breeze */
background: linear-gradient(to right, #2193b0, #6dd5ed);

/* Purple haze */
background: linear-gradient(135deg, #667eea, #764ba2);

/* Soft peach */
background: linear-gradient(to right, #ffecd2, #fcb69f);

/* Dark mode hero */
background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
🎨 Pro move: save your favorite gradients as CSS variables for easy reuse

Tips for Gradients That Actually Look Good

The fastest way to make any website look 37% more professional: replace a solid-color hero background with a subtle gradient. I don't make the rules.

Gradients are one of CSS's most versatile tools. Whether you are designing a subtle background or a vibrant hero section, mastering the syntax opens up endless creative possibilities — all without a single image file. Now go make something beautiful.

Try It Yourself

Use our visual gradient generator to pick colors, adjust angles, and copy the CSS instantly.

Open CSS Gradient Generator →