The :Not Pseudo-Class

The :not(selector) selector matches every element that is NOT the specified element/selector. In this example, it will set a background color for all elements that are not a <p> element:

HTML file: Displayed by browser:

<style>
p {
    color: #000000;
}
:not(p) {
    color: #ff0000;
}
</style>


<body>
<h1>This is a heading.</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<div>This is some text in a div element.</div>
<a href="http://www.w3schools.com" target="_blank">Link to W3Schools!</a>
</body>

This is a heading

This is a paragraph.

This is another paragraph.

This is some text in a div element.
This is a Link!

Note: Wow, almost everything was red on this webpage. I had to put everything in paragraph code, with inline styling, to keep them from being red!

Back button Table of Contents Next button