Top 10 Features in CSS 3

January 18, 2011

Cascading Style Sheets 3 and HTML5 are all the buzz these days, and for good reason. Together, they represent what will become another major evolutionary step forward for the World Wide Web, helping developers to create increasingly compelling and attractive Web applications. In fact, CSS3 eventually will become the Web's next standard for stylizing presentational markup.

I've been digging into CSS3 in recent weeks, and I am pretty excited about what's possible. In this article, I highlight 10 new features that you'll undoubtedly see in use around the Web as browser developers continue racing to complete CSS3 support. Keep in mind that some of these features are still in a state of flux, and in several cases you'll see that some are browser-specific, as the property prefixes will indicate.

1. Attribute Selectors

CSS selectors make it easy to apply styles to specific HTML elements. CSS3 introduces several new selectors which make it even easier to target very specific elements according to an attribute value. The following example will apply a bold font styling to any element having a title which ends in highlight:

Other attribute selectors are also supported, including [attribute^="value"], which will match attributes starting with the value, and [attribute*="value"], which will match attributes containing the value.

2. Rounded Corners

Rounded corners have long been something of an obsession within the web design community, having been implemented in countless ways, often using wildly imaginative workarounds. In recognition of their importance, the ability to easily add rounded corners has been implemented within CSS3:

3. Multi-Column Layouts

Speaking from the perspective of somebody who has spent a fair amount of time in the publishing world, I find the prospect of easily integrating multi-column layouts into a page quite exciting. CSS3 offers a very simple way to present a block of text in accordance with a specific number of columns, column spacing, and border decoration, as demonstrated here:

4. Setting the Opacity

Like the aforementioned rounded corners feature, setting opacity has long been a feature of great interest within the web design community. This feature is now available natively within CSS3. For instance, to set an element's opacity to 30 percent, use the following CSS declaration:

#opacity { background: #CCC; opacity: 0.3;}......

5. Font Flexibility

Fonts have long been one area where the Web has long fallen woefully short, with the choice of fonts limited to the browser's default settings. While workarounds and browser-specific implementations have come and gone over the years, the matter is now en route to being definitively resolved thanks CSS3, which allows developers the flexibility of using any OpenType or TrueType font. For instance,

Of course, you'll need to arrange for the licensing of any commercial fonts you use within your website.

6. Word Wrapping

Another useful property for online publishers seeking to control every aspect of the text layouts is CSS3's word-wrap property. You can use this feature to enforce the breaking of long words which might otherwise spill out of a predefined area. This presents many useful opportunities, including preventing malicious users from making your blog look bad by trying to post long strings of text. For instance, the following use of word-wrap will break the user's long string before it exceeds the DIV boundaries:

7. Text Shadowing

Adding a text shadow is another CSS3 feature offering huge potential. The following example will apply a gray text shadow 2px to the lower right, and further blurring it 5px:

#sidebar h3 { text-shadow: 2px 2px 5px #CCC;}...Welcome

8. Applying Box Shadowing

Web designers have long used an image editing program such as The Gimp to create shadows which were they applied as background images to a page element. CSS3 makes this process much easier (particularly for the design challenged individuals in the audience, present party included) by offering the box-shadow property:

9. Transforming Elements

Another promising CSS3 feature is the ability to rotate, scale, and skew a page element using the transform property. For instance, the following example will rotate the page element defined by the sale ID 25 degrees:

10. Using Gradients

Last but certainly not least, I'd like to introduce CSS3's amazing gradient feature. You can use the gradient property to apply a two-color gradient to a page element, and can even specify the starting and ending points within the element, as well as the direction. Here's an example: