October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

CSS Inheritance: How the `inherit` Keyword Works

CSS `inherit` sets a property to its parent’s computed value—even when that property does not inherit by default. See examples, keyword comparisons, and shorthand guidance.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In CSS, inherit sets a property on an element to the computed value of that same property on its parent in the document tree. It works whether or not the property normally inherits automatically. For example, color usually inherits by default, but border does not—unless you explicitly write border: inherit.

What does inherit mean in CSS?

inherit is a CSS-wide keyword. Use it as a property’s value to request that the element take that property’s computed value from its parent. The parent is the element directly above it in the document tree, not necessarily the element that visually contains it.

As an Amazon Associate I earn from qualifying purchases.

.parent {
  color: rebeccapurple;
}

.child {
  color: inherit;
}

Here, the child’s computed color is the parent’s computed color. Because color normally inherits when no other value is specified, this explicit declaration often produces the same result as leaving the child’s color unset. It is more useful when a declaration would otherwise give the child a different value, or when you want a normally non-inherited property to take its parent’s value.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

How do I make a property inherit from its parent?

Write inherit as the value of the specific property you want to inherit. It applies to that property only; it does not copy all of the parent’s styles.

#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
.parent {
  border: 1px solid;
}

.child {
  border: inherit;
}

Borders do not normally inherit. The explicit declaration makes the child request the parent’s computed border value. Check a property’s reference to find whether it inherits by default; do not assume that every property does.

Inheritance depends on the document tree

A child inherits from its parent element in the document tree, not from whichever element happens to surround it visually or establish its containing block. On the root element, there is no parent to inherit from, so inherit resolves to that property’s initial value.

inherit vs. initial, unset, and rollback keywords

Keyword Effect
inherit Use the parent’s computed value for this property. It always requests inheritance, even for a property that does not inherit by default.
initial Use the property’s initial value.
unset Act like inherit for a property that normally inherits; otherwise act like initial.
revert Roll the value back to one from an earlier cascade origin.
revert-layer Roll the value back to one from an earlier cascade layer.

The practical distinction is that inherit always asks for the parent’s computed value. unset makes that choice depend on the property’s normal inheritance behavior. These CSS-wide keywords are available as values for properties, including custom properties.

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

When should I use inherit?

  • Use it for a targeted override when a child should match its parent for a particular property.
  • Use it to pass down a value for a property that does not normally inherit, such as a border.
  • Prefer naming the property you want to inherit over copying every property with all.

Use caution with all: inherit

all: inherit requests the parent’s computed values for all properties to which the all shorthand applies. This can copy layout-affecting values as well as visual ones. For example, if inline children of a paragraph inherit its block-level display value, their layout can change unexpectedly. If you only need matching text color, write color: inherit; if you only need matching font weight, write font-weight: inherit.

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

How inheritance works with shorthand properties

Leaving a component out of a shorthand does not make that component inherit. Omitted shorthand components receive their initial values. To inherit just one component, set that component’s longhand explicitly to inherit.

/* Inherit only the border color; set the other border components separately. */
.child {
  border-width: 1px;
  border-style: solid;
  border-color: inherit;
}
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

To inspect a page’s rendered appearance without setting up a local browser capture, make one request to the ScreenshotNeo API:

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

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.

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

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. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

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.