Introduction
CSS cascade decides which style rules apply when many rules target the same element. It helps browsers pick the right style so your page looks good.
/* No special syntax for cascade itself, but it works with selectors and declarations like: */ selector { property: value; }
p {
color: blue;
}
p {
color: red;
}.special { color: green; } p { color: blue; }
p {
color: blue !important;
}
p {
color: red;
}<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>CSS Cascade Example</title> <style> p { color: blue; font-size: 1.2rem; } .highlight { color: red; } #unique { color: green; } </style> </head> <body> <p>This paragraph is blue because of the element selector.</p> <p class="highlight">This paragraph is red because the class selector is more specific.</p> <p id="unique" class="highlight">This paragraph is green because the ID selector is the most specific.</p> </body> </html>
p { color: blue; }
.highlight { color: yellow; }
#special { color: green; }<p id="special" class="highlight">Hello</p>
p { color: blue !important; }
p.special { color: red; }<p class="special">Text</p>
div { color: black; }
.alert { color: orange !important; }
#warning { color: red; }<div id="warning" class="alert">Warning!</div>
Pass the test and this pattern moves unknown