Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

Adjacent Sibling Selectors

Precise Definitions of CSS Styles

By Jennifer Kyrnin, About.com

Cascading Style Sheets defines siblings as elements that are next to one another. They are also called adjacent elements. This means that you can define a style rule on an element based on what element immediately precedes it in the XHTML.

How to define a sibling rule:
  h1 + h2 { color : #00f; }

This rule says that any h2 that immediately follows an h1 should be colored blue.

Browser Support

The adjacent sibling selector is not supported in IE 6 and lower for Windows or Netscape 4 for Windows. It did work in Safari and Internet Explorer 5.2 for Macintosh.

Explore Web Design / HTML

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. CSS
  5. Advanced CSS
  6. Adjacent Sibling CSS Selectors

©2009 About.com, a part of The New York Times Company.

All rights reserved.