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

What is a CSS Descendant Selector?

By Jennifer Kyrnin, About.com

A CSS descendant selector applies to the elements that are inside another element. For example an unordered list has a <ul> tag with <li> tags as descendants. Or if you make your list items anchors:

<ul>
<li><a href="">...</a></li>
</ul>

Define descendant selectors by using two type selectors separated by spaces.

li a {
text-decoration : none ;
}

But remember that it doesn't matter how many tags are in between the two tags. If the second element is enclosed anywhere within the first element it will be selected.

If you want to select all anchors that are descended from ul elements, you would write:

ul a {
text-decoration : none ;
}

And the selectors that you're descending from don't have to be type descendants. For example, you could set up a descendant selector off of an ID:

#navigation ul {
background-color : #ccc ;
}
More Web Design / HTML Quick Tips

Explore Web Design / HTML

More from About.com

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. CSS
  5. CSS Selectors
  6. CSS Descendant Selectors - What is a CSS Descendant Selector

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

All rights reserved.