CSS Backgrounds and Borders: Gradients, border-radius

background-size, position and gradients, multiple backgrounds, border-radius and outline vs border, with live controls.

Related chapters

Keep learning

Overview

Chapter 12 · backgrounds and borders The background is painted in layers you can place A box paints its background, then its border, then its content. Each of those steps has a property that says where it starts and stops. Learn them and most decorations need no extra elements and no images.

1. A see-through border needs a clipped background

Lower the border alpha. Nothing changes until you switch background-clip, because the white background runs underneath the border by default.

Three boxes, three keywords

border-box, padding-box and content-box name the edges of the box model. background-clip says where painting stops. background-origin says where position 0 0 is. They are separate, so you can position from the content edge and still paint under the padding.

2. More than one border

A box has one border. box-shadow with only a spread value draws a solid ring, and it takes a comma-separated list, so you can stack several. outline adds one more.

What the fake borders do not do

Shadows and outlines are painted outside the layout: they do not push neighbours away and they are not part of the hit area. Add a matching margin if they must not overlap the next element. outline follows border-radius in current browsers, but keep it for focus rings where you can, because people rely on seeing it.

3. Position from any corner

The usual background-position: 100% 100% glues an image to the corner with no gap. Name the edge and the distance instead, or move the origin to the content box so the padding becomes the gap.

4. Stripes are gradients with no fade

A gradient is an image the browser draws. Put two color stops at the same position and the blend has zero length, which gives a crisp edge.

From stripes to patterns

Several gradients can be layered with commas, the first one on top. Checkerboards, grids and polka dots are layers of hard-stop linear and radial gradients with a shared background-size. Keep the colors in custom properties so a pattern can be retuned in one place.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • Databases in depth — How a query becomes work. Indexes, isolation, locks, and the plans that explain why a page is slow — not an ORM tour.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.