CSS Tutorial

CSS Shadows

box-shadow lifts a card. text-shadow lifts letters. Keep blur soft so type still reads.

Two shadows

box-shadow paints outside (or inside) the border box. It does not change layout width. The card still occupies the same space; the shade is extra ink on the paper behind it.

text-shadow paints behind glyphs. It is for a heading on a photo or a short label, not for a paragraph. Soft blur keeps letters sharp. A hard offset with no blur looks like a duplicate of the word.

PropertyTypical valuesUse on
box-shadowoffset-x, offset-y, blur, optional spread, colorcards, buttons, popovers
text-shadowoffset-x, offset-y, blur, colorheadings, not long copy

box-shadow syntax

Read a shadow left to right: how far sideways, how far down, how soft, how much extra size, then the color. Spread is optional. Color is often a sky navy at low alpha so the shade tints the paper instead of drawing a black smear.

Example

<style>
  body {
    font-family: Georgia, serif;
    margin: 1.25rem;
    background: #f0f9ff;
    color: #0c4a6e;
  }
  .card {
    background: #fff;
    border-radius: 1rem;
    padding: 1.15rem 1.25rem;
    max-width: 22rem;
    box-shadow: 0 12px 28px rgba(12, 74, 110, 0.16);
  }
</style>
<article class="card">
  <h1>Harbor studio</h1>
  <p>Open 8–16. Tide chart at the desk.</p>
</article>

0 sideways and 12px down puts the shade below the card, as if the light were above. Equal x and y offsets slide the shade toward a corner. Negative y lifts the shade above the box.

Click Try it in CSS under the example. That opens /css/try. Raise the blur from 28px to 8px and the lift turns into a hard edge.

Hover lift and inset

A second, slightly larger shadow on :hover makes a card feel clickable. Pair it with a smalltranslateY in the transforms chapter if you want the box to move. The shadow alone is enough for a first pass.

Prefix inset to draw the shade inside the box — a pressed button or a shallow well. Inset shadows still do not change layout.

Example

<style>
  body {
    font-family: Georgia, serif;
    margin: 1.25rem;
    background: #e0f2fe;
    color: #0c4a6e;
  }
  button {
    font: inherit;
    background: #fff;
    color: #0c4a6e;
    border: 1px solid #7dd3fc;
    border-radius: 0.65rem;
    padding: 0.55rem 1.1rem;
    box-shadow: 0 4px 10px rgba(12, 74, 110, 0.12);
    cursor: pointer;
  }
  button:hover {
    box-shadow: 0 10px 22px rgba(12, 74, 110, 0.2);
  }
  .well {
    margin-top: 1rem;
    padding: 0.75rem 0.9rem;
    border-radius: 0.65rem;
    background: #f0f9ff;
    box-shadow: inset 0 2px 6px rgba(12, 74, 110, 0.18);
  }
</style>
<h1>Harbor studio</h1>
<p><button type="button">Book a desk</button></p>
<p class="well">Inset well — the shade sits inside the padding box.</p>

text-shadow

Same order, no spread: x, y, blur, color. On a dark header, a short dark shadow under light type can help. On a pale page, skip it — gray letters with a glow look dirty, not lifted.

Example

<style>
  body {
    font-family: Georgia, serif;
    margin: 0;
  }
  header {
    background: linear-gradient(to right, #0c4a6e, #0284c7);
    color: #fff;
    padding: 1.75rem 1.25rem;
  }
  h1 {
    margin: 0;
    font-size: 2rem;
    text-shadow: 0 2px 8px rgba(8, 47, 73, 0.45);
  }
  p {
    margin: 0.4rem 0 0;
    text-shadow: none;
  }
</style>
<header>
  <h1>Harbor studio</h1>
  <p>Open 8–16. The paragraph stays unshadowed.</p>
</header>

Stacking many text shadows, or a blur over 12px on small type, hurts reading. One soft shadow on a display heading is the usual limit.

Comma-separated layers

Both properties accept a list. A tight dark shadow plus a wide faint one mimics a real lamp better than a single value. Keep the list short.

RecipeDeclaration
Resting card0 8px 20px rgba(12, 74, 110, 0.12)
Two layers0 1px 2px rgba(12, 74, 110, 0.12), 0 12px 24px rgba(12, 74, 110, 0.1)
Soft heading on a photo0 2px 10px rgba(8, 47, 73, 0.5)

Shadows are still. The next chapter moves the box: translate, rotate, andscale, with transform-origin as the pivot.

Worked examples

The short listings above show one property. These sheets paint documents you would actually ship: a lab dashboard, a clinic form, a marks table, a nav bar.

CSS does not invent meaning. HTML already said what the pieces are. Cascade, specificity, and the box model decide how they look. The numbers are classroom values — current, pH, pulse, 3-4-5 — so the style has something real to sit on.

Preview them in the CSS editor at /css/try. Change one property and watch the page paint. The tags stay the same.

Engineering

Lift a logger card

box-shadow is offset-x, offset-y, blur, colour. Soft blur, low alpha. A hard black shadow looks like 2004. text-shadow lifts letters; keep it 1px so type still reads.

Example

<style>
  .card { box-shadow: 0 8px 20px rgba(15, 118, 110, 0.25); padding: 0.8rem; background: #fff; }
</style>
<div class="card">12 mT · saved</div>

Maths

A light lift on a title

text-shadow: 1px 1px 0 is a stamp. Blur on small type is how formulae become fog.

Example

<style>
  h1 { color: #3730a3; text-shadow: 1px 1px 0 #c7d2fe; }
</style>
<h1>A = 12 m²</h1>

FAQ: CSS Shadows

Common questions about this page.

What is the StudyGrid CSS tutorial?

The StudyGrid CSS tutorial is a full beginner track: selectors, the box model, text, layout, flex, grid, and responsive design. Each chapter has copy-and-preview examples.

Should I run css box-shadow examples locally for better learning?

Yes. Use the browser editor on StudyGrid for a quick check, then Download the example and run it on your computer. Local runs show real errors and the real toolchain, which is one of the fastest ways to learn css box-shadow in this CSS CSS lesson (CSS Shadows).

Is the CSS editor the same as Try HTML?

No. Try CSS is a stylesheet preview at /css/try. Try HTML stays at /html/try. CSS lessons never open the HTML-only editor or the Python editor.

Do I need to install anything to learn CSS?

No. Open a chapter, click Try it in CSS, and the page preview updates in the browser.

Where should I start the CSS tutorial?

Start at CSS Intro, then Syntax, Selectors, and How To. After colors and the box model, continue to flex, grid, and media queries. Use Next at the bottom of each chapter.

Is the CSS tutorial free?

Yes. The CSS studio on StudyGrid (studygrid.in) is free: dashboard, chapters, and the live preview editor.