Power CSS3 – universal, type, id and class selectors

CSS3 selectors actually select the content we want to style. Obviously a CSS selector is the part of a CSS rule set. Here we will be familiar with the power of basic CSS3 selectors.

At the end of this article, there is a link about more advance CSS3 selectors. I’m sure you will be excited to know about them.

universal, type, id and class selectors

1. * (universal selector)

The universal selector * or wildcard character or star symbol, selects all elements on a page. It targets every single element on the page.

Many developers use this trick to zero out the margins and padding. I’d advise you to never use this in production code as it adds too much weight on the browser and is unnecessary. The * can also be used with child selectors.

Compatible with: IE6+, Firefox, Chrome, Safari, Opera

2. X (type selector)

type selector must match one or more HTML elements of the same name. So if you need to target all unordered lists, use ul {}. To state more a selector of nav would match all HTML nav elements.

View Demo | Compatible with: IE6+, Firefox, Chrome, Safari, Opera

3. #X (id selector)

To allow a selector to target by id, prefix it by a hash symbol. This is the most common uses.

id selectors are rigid and don’t allow for reuse. So ask yourself do I absolutely need to apply an id to this element in order to target it? then if possible, first try to use a tag name, one of the new HTML5 elements, or even a pseudo-class. View Demo | Compatible with: IE6+, Firefox, Chrome, Safari, Opera

4. .X (class selector)

The class selector is the most useful of all CSS selectors. Using class selector you can target multiple elements. Use classes when you want your styling to apply to a group of elements.

HTML allows multiple classes to be added to a single element, making class selectors more valuable.

View Demo | Compatible with: IE6+, Firefox, Chrome, Safari, Opera


So here we have come to know about universal, type, id and class selectors and we visited their demo as well. In upcoming articles of this series we will know about power of more advance CSS3 selectors. Check the part 2 here.

You Might Interested In

Leave a Reply

Enclose a code block like: <pre><code>Your Code Snippet</code></pre>.