The CSS Cascade is the rule system browsers use to decide which style wins when multiple CSS rules target the same element. Since browsers can’t guess, they follow a strict hierarchy (like tie-breaker rounds). Once a winner is found, later rules are ignored.
<p>Hello World</p>
<style>
p {
color: blue;
}
</style>
<p class="text" id="main" style="color: red;">Hello</p>
<style>
p { color: blue; } /* lowest specificity */
.text { color: green; } /* class is stronger */
#main { color: purple; } /* id is stronger */
</style>
<p class="note">Hello</p>
<style>
p { color: blue !important; } /* wins */
.note { color: green; }
</style>
<p>Hello</p>
<style>
p { color: blue; }
p { color: green; } /* last rule wins */
</style>
The position property in CSS controls how an element is placed on a webpage. It defines whether an element follows the normal page flow or is moved elsewhere. The property works together with the offset values: top, right, bottom, and left.
Properties | Code |
---|---|
|
|
|
|
|
|
|
|
|
|
Works with positioned elements (relative, absolute, fixed, sticky) to control which element appears on top when they overlap.
Created by positioned elements with z-index, which affects how child elements overlap.
Positioning changes only placement, not whether an element is block or inline