Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

CSS  Module 1 – How CSS works

Inspecting CSS with browser DevTools

Open DevTools in Chrome, Firefox and Safari, see which CSS rule wins and why, read computed values and the box model, and edit styles live.

  • Beginner
  • 25 minutes
  • Examples run with Node.js 24.21.0
  • By MySmartCoPilot
Free core, Pro depth: 8 of 25 minutes free
Free: Selecting an element separates four common failures · Computed values answer a different question from rules. With a pass: 2 in-depth parts and 3 interview answers, about 17 minutes.

What you will learn

  • Find which rules match an element, which declaration wins and which are overridden
  • Read the computed panel and box-model diagram to explain an element's final size
  • Edit and toggle declarations live, then copy the fix back into the stylesheet
  • Test dark mode, reduced motion and print styles with the browser's emulation tools

Before you start

What you’ll learn · Before you start

What you will learn

  • Find which rules match an element, which declaration wins and which are overridden
  • Read the computed panel and box-model diagram to explain an element's final size
  • Edit and toggle declarations live, then copy the fix back into the stylesheet
  • Test dark mode, reduced motion and print styles with the browser's emulation tools

Before you start

On this page

Every desktop browser has DevTools: A browser's tools for inspecting the current document, styles, resources and behaviour., DevTools for short, that show exactly how CSS applies to any element on a page. Right-click an element and choose Inspect or Inspect Element, depending on the browser (Safari shows the item once its developer features are switched on), and the Elements panel opens with that element selected. Its Styles pane lists every rule that matches the element, the strongest first, with the declarations that lost crossed out and the ones the browser could not use flagged. Its Computed pane shows resolved property values beside a diagram of the element’s box. You can change any value, or switch a declaration off, and the page updates at once.

This lesson works through a small card with three planted bugs, one A valid declaration that loses a cascade comparison to another declaration for the same property. declaration, one invalid and one inactive declaration: A valid CSS declaration whose value does not affect the selected kind of box in the current layout., in Chrome, Firefox and Safari.

Selecting an element separates four common failures

Here is a small order card. Paste the two files into the HTML, CSS & JS Playground and inspect its preview as you read; the steps below find each bug.

An order card with three bugs

HTML · card.html

<div class="panel">
  <article class="card">
    <h2 class="card-title">Order 4821</h2>
    <p>Your parcel has left the Pune warehouse.</p>
    <a class="button" href="#track">Track it</a>
  </article>
</div>

CSS · card.css

.panel {
  font-size: 16px;
  width: 640px;
}

.card {
  font-size: 1.25em;
  width: 50%;
  padding: 0.75em 1em;
  border: 0.1em solid #c8d3e0;
  margin: 0 auto;
  line-height: 1.5;
  color: #243b53;
  justify-content: center;
}

.card-title {
  font-weight: 600;
  colour: #102a43;
}

.card a {
  background: #0b6e4f;
  color: #ffffff;
  padding: 0.25em 0.75em;
}

.button {
  background: #1d4ed8;
}
HTML, CSS & JS Playground (Online Editor) Paste card.html and card.css into its panes, then right-click the preview and inspect it.

The design asked for three things that did not happen: a title darker than the text (#102a43), a blue “Track it” button (#1d4ed8), and the card’s contents centred. None of the three shows an error anywhere on the page.

The first useful split is whether a rule appears for the selected element. A missing rule suggests that its sheet did not load or its selector does not match. If the rule appears, ask a different question: is the declaration invalid, overridden, or valid but inactive on this kind of box? Those are different causes, so making a selector stronger cannot repair every failure.

For normal declarations of the same importance, an element’s style attribute ranks above a selector rule. Between selector rules, specificity comes before source order: a class plus an element can beat a later single class. The Styles pane exposes that contest. A valid winning alignment value may still be inactive on an ordinary block, which is why the final colour or position alone does not explain the cause.

The current view can be edited, but a DevTools edit is not a saved stylesheet. Copy a working fix into the file and reload before treating it as persistent.

Follow the selected rule’s presence and validity before choosing a fix:

Interactive · stage by stage Rule presence separates four kinds of CSS failure Select the element and decide whether a missing, invalid, overridden or inactive declaration explains the result.
Rule presence separates four kinds of CSS failure, step 4 of 4. Showing Find the rule, Check validity, Find the winner, Check box behaviour. In focus: Check box behaviour.Find the ruleCheck validityFind the winnerCheck box behaviour

The drawing shows the whole scene; its 4 steps are listed below.

Every step as text
  1. Is the rule present?. If it is absent, inspect the resource load and selector match. A stronger selector is not the first fix for a file that never loaded.
  2. Is the declaration valid?. A misspelt property or invalid value is a parser problem. Other valid declarations of the rule can remain.
  3. Did the declaration win?. A crossed-out valid declaration lost a cascade comparison. Find the declaration that won before altering specificity.
  4. Does it affect this box?. A valid winning value may be inactive on this box. The original card's justify-content on a block demonstrates that separate case.

Checkpoint

Check: Finding a declaration's problem

  1. Question 1 of 2 A CSS rule is missing from the selected element's Styles pane. What should you check before comparing its specificity?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: Whether the sheet loaded and the selector matches

    A missing rule did not become one of the selected element's applicable rules. Resource loading and selector matching therefore come before comparing competing declarations.

  2. Question 2 of 2 The card uses display: block and justify-content: center. The latter is valid and not overridden, but does nothing. Which category fits?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Inactive for this kind of box

    The declaration can have a computed value without the layout behaviour required to make it affect this ordinary block.

Computed values answer a different question from rules

The Styles pane answers which rule supplied a value; the Computed pane answers what resolved value: The value a CSSOM inspection reports for a property, including used layout values for specified properties. the browser reports. Relative lengths can become pixel lengths, inherited values are included, and a shorthand is represented through its longhands. A reported value is still a value rather than proof of an effect: an alignment property can read center while inactive on an ordinary block.

A The content, padding, border and margin regions used to account for an element's layout dimensions. sum makes the distinction concrete. With A sizing mode in which the declared width describes content; padding and border add to the total box. sizing, width 200 px means 200 px of content. Padding of 0.5em at a 20 px font adds 10 px on each side; a 1 px border adds another pixel per side. The border box is therefore 222 px. Counting one side only gives 211 px, and assuming declared width already includes everything gives 200 px; both miss the sizing rule. Account for both sides of the same 200 px example before answering its size question.

Interactive · stage by stage The public content-box example totals 222 px Count both padding and border sides around the original self-check's 200 px content, rather than treating declared width as the complete box.
The public content-box example totals 222 px, step 3 of 3. Showing Read 200 px content, Add both padding sides, Add both border sides. In focus: Add both border sides.Read 200 px contentAdd both padding sidesAdd both border sides

The drawing shows the whole scene; its 3 steps are listed below.

Every step as text
  1. Read the sizing mode. Under content-box sizing the declared 200 px width is the content, not the padding and borders.
  2. Resolve the padding. The self-check gives a 20 px font and 0.5em padding. That is 10 px on each side, taking the total to 220 px.
  3. Include both borders. The 1 px border on each side adds two more pixels. The complete border box is 222 px; the separate full card record remains in the depth part.

Checkpoint

Check: Written values and box size

  1. Question 1 of 2 Which pane explains why a declaration won rather than just showing the resulting value?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: Styles

    Styles shows the matching rules and their competing declarations. Computed shows the resolved result.

  2. Question 2 of 2 A content-box element has width 200 px, 10 px padding on each side and a 1 px border on each side. What is its border-box width?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: 222 px

    Add the content, both padding sides and both border sides: 200 + 10 + 10 + 1 + 1 = 222.

Inspecting the complete card and resolving its box Pro: opens with a Pro, Premium or Ultimate pass

The three original card bugs each fail for a different reason. The complete stylesheet, schematic and recorded box calculation let you follow each cause to the final result.

In this part:

  • The complete card exposes overridden, invalid and inactive CSS
  • The card measurements explain every box edge

3 diagrams · 1 runnable example (JavaScript) · about 9 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Persisting a fix and testing preference branches Pro: opens with a Pro, Premium or Ultimate pass

A correct current view must survive a reload, and each preference branch needs its own check. The fixed stylesheet and mode stylesheet keep those two jobs separate.

In this part:

  • Live edits need a file change to survive reload
  • Preference and print emulation exercise separate branches

2 diagrams · 2 runnable examples (CSS) · about 6 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Practise: classify the cause before changing a rule

Practice that adapts to you

Practise this lesson

10 questions about 6 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 10 A paragraph <p class="alert"> has no padding. Which declaration does the Styles pane show crossed out?

    Read the code, then choose one answer.

    p.alert {
      padding: 0;
    }
    
    .alert {
      padding: 1rem;
    }
    Show the answer: Question 1 of 10

    Answer: padding: 1rem in .alert, because p.alert is more specific

    p.alert has a class and an element, .alert only a class, so p.alert wins and padding: 1rem is crossed out as overridden. Order of appearance only decides between declarations of equal specificity.

  2. Question 2 of 10 The links inside <nav class="menu"> are not centred vertically. What does the Styles pane show for align-items?

    Read the code, then choose one answer.

    .menu {
      display: block;
      align-items: center;
      min-height: 3rem;
    }
    Show the answer: Question 2 of 10

    Answer: Pale text with an information icon, because align-items has no effect on a block box

    align-items is valid and nothing overrides it, but it only works on flex and grid containers. Chrome and Firefox mark such a declaration as inactive and explain why when you hover over the icon. Making the menu a flex container (display: flex) puts it to work.

  3. Question 3 of 10 The price should be red but shows in the default text colour. What does the Styles pane show for the second declaration?

    Read the code, then choose one answer.

    .price {
      font-weight: 700;
      colour: #b00020;
    }
    Show the answer: Question 3 of 10

    Answer: A warning that the property is invalid, because colour is not a CSS property

    The parser drops a declaration whose property it does not know. Chrome crosses it out with a warning icon, Firefox shows a warning icon and Safari highlights it in yellow. font-weight still applies.

  4. Question 4 of 10 You wrote a rule for an element, but it does not appear in the element's Styles pane at all. Which of these could explain it?

    Choose every answer that is right.

    Show the answer: Question 4 of 10

    Answer:

    • The stylesheet that contains the rule never loaded
    • The rule's selector does not match the element

    The Styles pane lists every rule that matches the element, including rules whose declarations all lost (they are shown crossed out) and rules with invalid values (they are flagged). A rule that is missing altogether either does not match, so check the selector and the element's classes, or never reached the page, so check the Network panel for the stylesheet.

  5. Question 5 of 10 You select <h2 class="title" style="color: black">Orders</h2>. What does the Styles pane show?

    Read the code, then choose one answer.

    .title {
      color: navy;
    }
    Show the answer: Question 5 of 10

    Answer: color: black under element.style at the top, and color: navy in .title crossed out

    Declarations in a style attribute are listed first, as element.style (Firefox: element {}), because they beat the normal author selector rule in this page. color: navy therefore loses and is crossed out.

  6. Question 6 of 10 An element has width: 200px, padding: 0.5em and border: 1px solid, with font-size: 20px and the default box-sizing: content-box. How wide is its border box in the box-model diagram?

    Type a number.

    Show the answer: Question 6 of 10

    Answer: 222 px

    With content-box sizing, width is the content alone. The padding is 0.5 × 20px = 10px on each side and the border 1px on each side, so the border box is 200 + 10 + 10 + 1 + 1 = 222px.

  7. Question 7 of 10 A CSS rule is missing from the selected element's Styles pane. What should you check before comparing its specificity?

    Choose one answer.

    Show the answer: Question 7 of 10

    Answer: Whether the sheet loaded and the selector matches

    A missing rule did not become one of the selected element's applicable rules. Resource loading and selector matching therefore come before comparing competing declarations.

  8. Question 8 of 10 The card uses display: block and justify-content: center. The latter is valid and not overridden, but does nothing. Which category fits?

    Choose one answer.

    Show the answer: Question 8 of 10

    Answer: Inactive for this kind of box

    The declaration can have a computed value without the layout behaviour required to make it affect this ordinary block.

  9. Question 9 of 10 Which pane explains why a declaration won rather than just showing the resulting value?

    Choose one answer.

    Show the answer: Question 9 of 10

    Answer: Styles

    Styles shows the matching rules and their competing declarations. Computed shows the resolved result.

  10. Question 10 of 10 A content-box element has width 200 px, 10 px padding on each side and a 1 px border on each side. What is its border-box width?

    Choose one answer.

    Show the answer: Question 10 of 10

    Answer: 222 px

    Add the content, both padding sides and both border sides: 200 + 10 + 10 + 1 + 1 = 222.

Interview questions

What does the Computed pane in DevTools show that the Styles pane does not?

The Styles pane shows the rules and declarations as they are written in your stylesheets, in cascade order, including the ones that lost, so it explains why a value won. The Computed pane shows the result: one final value for every property of the selected element, as resolved values, the same ones getComputedStyle() returns. The card’s relative lengths become pixels and its colour becomes rgb(). Resolution depends on the property and its box; other properties can keep computed values. Shorthands split into longhands, inherited values are included, and the card’s margins, width and padding report layout sizes, so its margin: auto reads as 138px. Expanding a property shows which declaration set it. Use Computed to see what the browser actually used; use Styles to see why.

  1. Fresher to mid

    You add .price { color: #b00020; } to a stylesheet, reload, and the price is still black. Describe, step by step, how you would use DevTools to find out why, covering every reason a declaration can fail to take effect.

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  2. Fresher to mid

    An element has width: 50%, padding: 0.75em 1em, border: 0.1em solid and margin: 0 auto, with font-size: 20px, inside a 640px container. DevTools shows its box 364px wide and 138px from the left. Explain every number, then make the box exactly half the container.

    Model answer, Pro. First step and follow-ups

  3. Mid to senior

    A card looks correct in the ordinary page but fails in dark mode and print preview. A live DevTools edit repairs it, then the problem returns after reload. Describe how you would locate the failing branches, preserve the fix and check the modes the change could affect.

    Model answer, Pro. First step and follow-ups

Key takeaways

  • Right-click and Inspect opens the Elements panel on that element; Safari first needs “Show features for web developers” in its settings.
  • The Styles pane lists matching rules strongest first: crossed out means overridden, a warning means invalid, pale with an information icon means valid but inactive.
  • The Computed pane shows resolved values, the same as getComputedStyle(): the card’s pixel sizes and rgb() colour, longhands and inherited values. Other properties can keep computed values; a reported value does not prove an effect.
  • Edit, toggle and add declarations live, then copy them back from the Changes panel, because a reload discards them.

Terms in this lesson

DevTools
A browser's tools for inspecting the current document, styles, resources and behaviour.
inactive declaration
A valid CSS declaration whose value does not affect the selected kind of box in the current layout.
resolved value
The value a CSSOM inspection reports for a property, including used layout values for specified properties.

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.