CSS Selector element1~element2

The element1~element2 selector selects element2 that are preceded by element1.

Both elements must have the same parent. element2 does not have to be immediately preceded by element1.


CSS Version

CSS Syntax

element1~element2 { 
   style properties 

Browser compatibility

element1~element2 Yes 7.0 Yes Yes Yes


An example showing how to use element1~element2 CSS selector.

<!DOCTYPE html>
p~h2{<!--  ww w  . java 2  s . c  o m-->
    <div>A div element.</div>
    <p>The first paragraph.</p>
    <h2>Another list</h2>
    <p>The second paragraph.</p>

Click to view the demo