October 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Create CSS Gradients and Shadows

Use CSS gradient functions for color transitions, then tune box-shadow for elements and text-shadow for glyphs. Includes syntax, choices, and fixes for common styling issues.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a gradient by assigning a CSS gradient function—such as linear-gradient()—to a background, then tune its direction and color stops. Add depth with box-shadow around an element or text-shadow behind text. The examples below show the syntax and the controls to adjust.

How CSS gradients work

A gradient is a CSS-generated image, not a solid color. You can use it anywhere CSS accepts an image, including a background, without creating a separate raster image for the color transition. Gradients are useful for backgrounds, highlights, stripes, and rings.

The main choices are the direction or shape of the transition and the position of each color stop. Two colors make a simple gradient; adding stops gives you more control over how colors change.

Linear gradients

linear-gradient() transitions along a straight line. Its default direction is top to bottom. Set an explicit direction such as to right, or use an angle such as 70deg.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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
/* Left to right, with three color stops. */
.banner {
  background: linear-gradient(to right, #3157d5, #8b5cf6, #f4a261);
}

/* An explicit angle. */
.banner-angled {
  background: linear-gradient(70deg, #3157d5, #8b5cf6, #f4a261);
}

Color stops can include positions to control where each color appears. Adjusting those positions can spread a transition across more of the element or create a sharper boundary between colors.

Radial and conic gradients

radial-gradient() transitions outward from a center. You can specify a shape, size, and center as well as the colors. This example places a circular highlight at the top left:

.card {
  background: radial-gradient(circle at top left, #fff, #dbeafe);
}

conic-gradient() transitions around a center. Its starting angle, center, and color stops help shape the result. Repeating gradient functions create repeated patterns; they are useful for effects such as stripes or rings when the stop positions define the repeat interval.

Choose a gradient for the effect

Effect CSS function Controls to tune
Transition along a straight line linear-gradient() Direction or angle; color-stop positions
Transition from a center radial-gradient() Shape, size, center, and color stops
Transition around a center conic-gradient() Starting angle, center, and color stops
Repeated stripes or rings A repeating gradient function Repeat interval and stop positions

For a smooth blend, position stops to give the colors room to transition. For hard bands, place neighboring stops close together. The gradient’s shape and direction determine where that transition appears on the element.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Add depth with box-shadow

Use box-shadow to cast a shadow around an element’s box or to add an inner shadow. Its values commonly specify horizontal offset, vertical offset, optional blur radius, optional spread radius, and color. The inset keyword makes the shadow appear inside the box. Multiple shadows are separated by commas.

.panel {
  box-shadow: 0 8px 20px rgb(0 0 0 / 18%),
              inset 0 1px rgb(255 255 255 / 60%);
}

In this example, the first layer is an outer shadow; the second is an inset highlight. Adjust the offsets to change its direction, blur to soften it, spread to change its reach, and color to change its strength or hue.

Add a shadow to text

text-shadow applies a shadow to text glyphs. It requires horizontal and vertical offsets, accepts an optional blur length, and can take a color. Specify the color for a predictable appearance. Multiple shadows are comma-separated; the first listed shadow is on top.

.heading {
  text-shadow: 0 2px 4px rgb(0 0 0 / 30%);
}

Keep the shadow subordinate to the text itself: offsets and blur that are too strong can make letters harder to read. If you layer multiple text shadows, remember that their order affects which one appears in front.

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

Build and check a complete style

  1. Choose the transition. Use a linear gradient for a directional blend, radial for a center-out highlight, or conic for a transition around a center.
  2. Set the stops. Start with two colors, then add stops or positions to control where the colors change.
  3. Add a box shadow if needed. Set offsets and color first; add blur or spread only when the design calls for them. Use inset for an inner effect.
  4. Add a text shadow only where it helps. Set explicit offsets and color, then tune blur while checking legibility.
  5. Inspect the result in the page. Gradients and shadows depend on the element’s dimensions, background, and surrounding content, so check the rendered design rather than judging a declaration in isolation.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and fixes

  • The gradient appears to run the wrong way: set its direction explicitly, for example to right, instead of relying on the default top-to-bottom direction.
  • The result looks like abrupt color bands: review the stop positions. Stops close together make a boundary sharper; give them more room for a gradual transition.
  • The gradient is not visible: check that the declaration is applied to the intended element and that the element has visible dimensions. A background image can only be seen where that element is rendered.
  • The box shadow appears inside instead of outside: remove inset from that shadow layer. It changes the shadow to an inner one.
  • The text shadow reduces legibility: reduce its offset or blur and use a less prominent explicit color.
  • One shadow layer seems to cover another: check the comma-separated order. For text-shadow, the first listed shadow is on top.

Compatibility and references

MDN labels text-shadow Baseline Widely available. The cited references describe gradients and box shadows as established CSS features, but they do not provide complete browser-version tables for every gradient subtype or syntax variation. Check the relevant compatibility information if a particular browser or newer syntax variation is a requirement. The associated specifications are CSS Images Module Level 4 for gradients, CSS Backgrounds and Borders Module Level 3 for box-shadow, and CSS Text Decoration Module Level 3 for text-shadow; a specification reference alone does not guarantee uniform implementation of every feature.

References: MDN: Advanced styling effects; MDN: text-shadow; MDN: <gradient>; MDN: Using CSS gradients; MDN: box-shadow.

Or skip the browser setup

If you need a screenshot of a page showing your CSS, ScreenshotNeo can capture a URL with one GET request. Its API can return an image or PDF; you can also use its MCP server from an AI agent.

API documentation

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

Cookie and consent banners are accepted before capture, and more than 60 known consent platforms, newsletter popups, and chat widgets can be removed; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. The MCP tools are take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

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

Sign up for ScreenshotNeo’s free plan.

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. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. 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…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.