Role of CSS :only-of-type Selector

CSSWeb DevelopmentFront End Technology

Use the CSS :only-of-type selector to style every <p> element that is the only <p> element of its parent.


You can try to run the following code to implement the :only-of-type selector

Live Demo

<!DOCTYPE html>
         p:only-of-type {
            background: orange;
            color: white;
         <p>This is demo text 1.</p>
         <p>This is demo text 2.</p>
         <p>This is demo text 3.</p>
         <p>This is demo text 4.</p>
Updated on 01-Jul-2020 08:58:41