Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 36 ยท Elements and Styles

Computed Styles, Inheritance and Style Sources

Use the Computed tab to see final values, trace inherited properties and custom properties, and find which rule set each value, with a runnable inheritance stand-in.

The Styles pane shows the rules that apply to an element. The Computed tab answers a different question: what is the final value of every property after all rules, inheritance and defaults have been resolved? When you need the real answer to "how big, what color, what font?", Computed is the place to look.

What "computed" means

Browsers go through several stages for each property:

  1. Declared: all the values from matching rules.
  2. Cascaded: the single winner after the cascade (see the previous lesson).
  3. Specified: the cascaded value, or the inherited or initial value when nothing was declared.
  4. Computed: relative values resolved as far as possible without layout (for example 2em becomes pixels, inherit becomes a concrete value, currentColor becomes a color).
  5. Used: final value after layout, such as a percentage width turned into pixels.

The Computed tab shows values at about the computed/used stage. That is why width: 50% appears as a pixel size and font-size: 1.5rem appears as 24px.

Reading the Computed tab

  • The box model diagram appears at the top.
  • Under it is an alphabetical list of properties with their final values.
  • Click the small arrow next to a property to expand it and see which rule set it, with the selector and the file link. The rule at the top is the winner; others below are losers.
  • Tick Show all to include properties that have default values. Normally only properties that differ from defaults are shown.
  • Tick Group to organize by category (layout, text, appearance).
  • Use the Filter box to type a property name such as font to narrow the list.

When a value surprises you, click the arrow, then click the selector link to jump to the Styles pane at that rule. This is faster than scrolling through every rule in Styles.

If you are unsure whether an element is visible, check Computed for display, visibility, opacity, width, height and position. Many "ghost" elements are really display: none or height: 0 with overflow: hidden.

Inheritance

Some properties pass from parent to child automatically. These are inherited properties: mainly text-related ones such as color, font-family, font-size, line-height, text-align and visibility. Layout and box properties such as margin, padding, border, background, width and display are not inherited by default.

In the Styles pane, inherited properties are listed under headings like "Inherited from body". In Computed, they appear with their final values and, when expanded, point to the ancestor's rule.

You can force inheritance with CSS keywords:

  • inherit: use the parent's computed value.
  • initial: reset to the property's built-in default.
  • unset: behave as inherit for inherited properties and initial for the rest.
  • revert: go back to the browser's default stylesheet value.

Stand-in: resolving inherited properties

Below is a model of inheritance. Each node has declared styles; the resolver walks up to ancestors for inherited properties and applies defaults for the rest. It is a simplification (it only knows a few properties) built to show the idea.

JS Stand-in: computed values with inheritance

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Look at the output: every p inherits font-size: 18px from body, and the first inherits navy while the second overrides it. margin never passes down, so each p shows 0, even though article has 10px.

CSS custom properties

Custom properties (variables such as --brand) are inherited by default. DevTools understands them:

  • In Styles, a declaration like color: var(--brand) shows the variable; hover it to see its value, and click to jump to its definition.
  • In Computed, the final used value appears (the actual color), and the variable name is listed when you expand the property.
  • In Elements, selecting :root and looking at its rule shows all variables defined for the page. You can edit one value and watch the whole page change, a very fast way to try a color theme.

If var(--x) has no value, the property becomes invalid at computed-value time: it falls back to inherited or initial, not to the earlier rule. This can look like a missing style in Computed. The usual fix is to provide a fallback, var(--x, #333), or to check where the variable is declared (it must be on the element or an ancestor).

Stand-in: finding the source of a value

Debugging often means "which rule gave this value?". This stand-in keeps a list of declarations with their sources and reports the winner as Computed does when you expand a property. It reuses a minimal specificity count.

JS Stand-in: which rule set the value?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Workflow tips

  • To see why a value is wrong: select the element, open Computed, expand the property, click the winning selector.
  • To see which element sets a font: Computed has a Rendered Fonts section in the Fonts area of the pane, which lists the fonts actually used for the node's text, not just the first in font-family. This tells you whether your web font loaded.
  • To find an unexpected inherited value: look in Styles under "Inherited from", then follow the link.
  • To check media-dependent styles: resize the viewport or use Device mode and watch Computed change.
  • To catch a typo: in Styles, the yellow warning triangle appears beside invalid declarations, and the value never reaches Computed.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which tab shows the final value of every CSS property after the cascade and inheritance?

    Computed lists resolved values; Styles lists the rules that apply.
  2. 2. Which property is inherited by default?

    color is a text property that inherits; margin, background and width do not.
  3. 3. A paragraph has font-size: 1.5rem and the root font size is 16px. What does Computed show?

    Relative lengths are resolved to absolute values in the computed value.
  4. 4. How can you find the rule that set a particular computed value?

    Expanding a property in Computed lists the contributing rules and links to them.

Summary

  • Computed shows final values; Styles shows the rules that produced them.
  • Expand a property to trace the winning rule and jump to it.
  • Text properties inherit; box properties do not; custom properties inherit too.
  • Check Rendered Fonts and Show all when diagnosing missing styles.

Next: Pseudo-States, Colors and Live Style Experiments