The top 10 CSS3 techniques
Denise Jacobs reveals her top tips on how to use the most exciting CSS3 properties - and provide fallbacks for older browsers
This article originally appeared in issue 210 of .net magazine - the world's best-selling magazine for web designers and developers.
While the following list does not include all of the great new properties in the CSS3 specification, this selection of the top 10 will give you a great start with your front-end coding projects. They’ll save you a lot of time and effort. Note: with the exception of @font-face, neither IE6, 7 nor 8 (from here on referred to as “the older IEs”) support any of the CSS3 properties. IE9 supports several properties and will be indicated.
1. @font-face
@font-face allows for fonts to be downloaded from a web server to the user’s computer to correctly render a given font. The syntax is:
- @rule-name {
- font-family: "Fontname";
- src: url(fontfilename.ext) format('formatname');
- }

The full solution
- @font-face {
- font-family: 'Colaborate Light';
- src: url('ColabLig.eot');
- src: local('☺'), url('ColabLig.woff') format('woff'),
- url('ColabLig.ttf') format('truetype');
- font-weight:normal;
- font-style:normal;
- font-variant:normal;
- }
The smiley face glyph is intentional: it keeps the browser from looking for a local copy of the font and forces it to use the downloadable ones. Alternatively, to proactively code for potential Internet Explorer bugs:
- @font-face {
- font-family: 'Colaborate Light';
- src: url('ColabLig.eot');
- font-weight:normal;
- font-style:normal;
- font-variant:normal;
- }
- @font-face {
- font-family: 'Colaborate Light';
- src: local('☺'), url('ColabLig.woff') format('woff'),
- url('ColabLig.ttf') format('truetype');
- font-weight:normal;
- font-style:normal;
- font-variant:normal;
- }
2. Opacity
- opacity: <value>;
- filter: alpha(opacity=40);
- filter: progid:DXImageTransform.Microsoft.
- Alpha(opacity=40);
- -ms-filter: "progid:DXImageTransform.
- Microsoft.Alpha(opacity=40)";
The full solution
- .opacity {
- background-color: #3C4C55;
- color: #fff;
- opacity: 0.5;
- -ms-filter: "progid:DXImageTransform.Microsoft.
- Alpha(opacity=20)";
- /* above line is IE8 only */
- filter: progid:DXImageTransform.Microsoft.
- Alpha(opacity=20);
- /* above line works in IE6, IE7, and IE8 */
- filter: alpha(opacity=20);
- }
3. RGBA
- property: rgba(<r color value>, <g color value>, <b
- color value>, <opacity value>);
The full solution
- #sidebar{
- background: rgb(255, 0, 0); /* fallback color in RGB
- */
- background: rgba(255, 0, 0, 0.3);
- }
- #sidebar {
- background-color: #ff0000; /* fallback color in
- hexidecimal */
- background-color: rgba(255, 0, 0, 0.3);
- }
- .rgba {
- background-color: #ff0000; /* fallback color in
- hexidecimal. */
- background-color: transparent; /* transparent is
- key for the filter to work in IE8. best done
- through conditional comments */
- background-color: rgba(255, 0, 0, 0.3);
- -ms-filter: "progid:DXImageTransform.
- Microsoft.gradient(startColorstr=#4CFF0000,
- endColorstr=#4CFF0000)";
- /* filter for IE8 */
- filter: progid:DXImageTransform.Microsoft.
- gradient(startColorstr=#4CFF0000,
- endColorstr=#4CFF0000);
- /* filter for older IEs */
- }
4. Border-radius
- border-radius: <top value>, <right value>, <bottom
- value>, <left value>;
The full solution
- .roundcorners {
- -moz-border-radius: 20px;
- -webkit-border-radius: 20px;
- border-radius: 20px;
- }
- .roundcorners {
- border: 5px solid #aaa;
- -moz-border-radius: 10px 5px;
- -webkit-border-top-left-radius: 10px;
- -webkit-border-top-right-radius: 5px;
- -webkit-border-bottom-right-radius: 10px;
- -webkit-border-bottom-left-radius:
- 5px;
- border-radius: 10px 5px;
- }
Top tool: A fantastic generator for border radius is aptly named border-radius.com. The tool quickly produces cross-browser compliant code for creating border-radius.
5. Box-shadow
Another long-awaited feature: box-shadow generates drop-shadows on elements, with no more image swapping, slicing or other shenanigans. The syntax is:
- box-shadow: <position> <x-offset>, <y-offset>,
- <blur radius>;
- position: the default value is outset and does not need to be stated. The other value is inset and needs to be established if desired.
- horizontal/x-offset: a positive value places the shadow on the right of the box; a negative value places the shadow on the left of the box.
- vertical/y-offset: a positive value places the shadow below the box; a negative value places the box-shadow above the box. If this third value is omitted, then the blur will be set to 0.
- blur radius: 0 is the sharpest, as there is no blur; higher numbers increase the blur. A measurement notation must be given.

The full solution
- .boxshadow {
- -moz-box-shadow: 3px 3px 10px #333;
- -webkit-box-shadow: 3px 3px 10px #333;
- box-shadow: 3px 3px 10px #333;
- /* For IE 8 */
- -ms-filter: "progid:DXImageTransform.
- Microsoft.Shadow(Strength=4, Direction=135,
- Color='#333333')";
- /* For IE 5.5 - 7 */
- filter: progid:DXImageTransform.Microsoft.
- Shadow(Strength=4, Direction=135,
- Color='#333333');
- }
6. Text-shadow
The kissing cousin to box-shadow, textshadow adds drop shadows to text, allowing for effects such as outer glow, embossed and letterpress looks. The syntax for text-shadow is identical to that of box-shadow, except that the value inset is not applicable to text-shadow. Like its box counterpart, text-shadow is also well supported by all the modern browsers and Internet Explorer 9. Also like box-shadow, you can assign multiple shadows to a single element by listing the multiple property value sets. It’s possible to get some really good effects on text that way.
The full solution
- .textshadow h2 {
- text-shadow:1px 1px 2px rgba(48,80,82,0.8);
- -ms-filter: "progid:DXImageTransform.
- Microsoft.Shadow(Strength=2,
- Direction=135, Color='#305052')";
- /* For IE 5.5 - 7 */
- filter: progid:DXImageTransform.Microsoft.
- Shadow(Strength=2, Direction=135,
- Color='#305052');
- }
- Top tool: There are several great CSS3 generation tools at WestCiv.com, including ones for box-shadow and text-shadow: westciv.com/tools/shadows/ and westciv.com/tools/text-properties/index.html
7. Gradient
- The -moz- and standard syntax notate the type of gradient before the list of values enclosed in the parentheses
- The -moz- syntax allows for a degree value
- The position names vary between the two browsers
- The -webkit- syntax denotes the colour stops with from and to
The full solution
- .gradient {
- color: #fff;
- background: #aaaaaa url(gradient_slice.jpg) 0 0
- x-repeat; /*background color matches one
- of the stop colors. The gradient_slice.jpg is
- 1px wide */
- background-image: -moz-linear-gradient(top, #07407c, #aaaaaa);
- background-image: -webkit-gradient(linear,left
- top,left bottom,color-stop(0, #07407c),color-stop
- (1, #aaaaaa));
- -ms-filter: "progid:DXImageTransform.Microsoft.
- gradient(startColorStr='#07407c',
- EndColorStr='#aaaaaa')";
- filter:
- progid:DXImageTransform.Microsoft.gradient
- (startColorStr='#07407c', EndColorStr='#aaaaaa');
- }
8. Multiple background images
- background:
- <image> <position> <size> <repeat> <attachment> <box>,
- <image> <position> <size> <repeat> <attachment> <box>,
- <image> <position> <size> <repeat> <attachment> <box>,
- <image> <position> <size> <repeat> <attachment> <box> <color>;
- background-image: <image>, <image>, <image>, <image>;
- background-repeat: <repeat>, <repeat>, <repeat>,<repeat>;
- background-position: <position>, <position>, <position>,<position>;
- /* plus any background attachment and/or box properties as needed */
The full solution
- #wrap {
- background: url(body-full.gif) top left no-repeat;
- background:
- url(body-top.gif) top left no-repeat,
- url(body-bottom.gif) bottom left no-repeat,
- url(body-middle.gif) left repeat-y;
- -ms-filter: "progid:DXImageTransform.
- Microsoft.AlphaImageLoader(src=' body-top.gif',
- sizingMethod='scale')";
- filter: progid:DXImageTransform.Microsoft.
- AlphaImageLoader(src='body-top.gif', sizingMethod='scale');
- zoom: 1;
- }
- body {
- background: url(all_layers.jpg) no-repeat 0 0;
- background-image:
- url(first_layer.png),
- url(second_layer.png),
- url(third_layer.png),
- url(fourth_layer.png);
- background-repeat: no-repeat, no-repeat,
- no-repeat, no-repeat;
- background-position: 0 0, 0 50, 0 100, 0 200;
- -ms-filter: "progid:DXImageTransform.
- Microsoft.AlphaImageLoader(src=' body-top.gif',
- sizingMethod='scale')";
- filter: progid:DXImageTransform.Microsoft.
- AlphaImageLoader(src='
- body-top.gif', sizingMethod='scale');
- zoom: 1;
- }
9. Transform
Transform has a number of values that do various things: rotate, scale, skew, translate and matrix. I’ll only discuss rotate here: for full details on the rest of the transform values see standardista.com/css3-transforms. The generic syntax is:
- <-prefix->transform: type(<value>) type(<value>)
- type(<value>) type(<value>);
- <-prefix->transform: rotate(<value>)
The full solution
- .rotate {
- -moz-transform: rotate(-5deg);
- -o-transform: rotate(-5deg);
- -webkit-transform: rotate(-5deg);
- transform: rotate(-5deg);
- -ms-filter: "progid:DXImageTransform.
- Microsoft.Matrix(M11=0.9961946980917455,
- M12=0.08715574274765817, M21=-
- sizingMethod='auto expand')";
- filter: progid:DXImageTransform.Microsoft.
- Matrix(sizingMethod='auto expand',
- M11=0.9961946980917455,
- M12=0.08715574274765817,
- M21=-0.08715574274765817,
- M22=0.9961946980917455);
- zoom: 1;
- }
10. Transition
- <-prefix->transition:<property> <duration>
- <timing-function> <delay>;
- property: you can name the specific CSS property to which the transition is applied, or you can use the value all.
- duration: defines the length of time that the transition will take.
- timing-function: describes easing functions – the intermediate values used during a transition – will be calculated.
- delay: defines the start of the transition. You can have multiple value sets to one transition property.

The full solution
- #photos > img:hover {
- -moz-transform: scale(1.1,1.1);
- -webkit-transform: scale(1.1,1.1);
- -o-transform: scale(1.1,1.1);
- transform: scale(1.1,1.1);
- -moz-transition: all 1s ease-in-out;
- -webkit-transition: all 1s ease-in-out;
- -o-transition: all 1s ease-in-out;
- transition: all 1s ease-in-out;
- }
Hopefully this primer has given you the inspiration to get on the bandwagon and start using CSS3 now. Its acceptance and adoption by front-end developers and designers increases in popularity daily, and every new release of the modern browsers shows increased support, even IE9. And if CSS3 is getting you excited, then you should check out some of the great HTML5 features, such as how to add HTML5 video to your site! What are you waiting for?




9 comments
Comment: 1
background-image: -o-linear-gradient(top,rgb(100,100,100),rgb(200,200,200));
More info: http://dev.opera.com/articles/view/css3-linear-gradients/
Comment: 2
http://www.css3files.com
Comment: 3
Comment: 4
i am quite confused for that...
---------
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=20)";
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=20);
filter: alp;
----------
first one, should be just " then progid instead of “ ?
the last one, alp or alpha?
Comment: 5
Here are the top 10 errors (one for each technique)
1) Fails in Android.
2) CSS2 property
3) Background shorthand to declare color only is a bad idea.
4) 5px 10px works in webkit
5) description incomplete (and syntax errors)
6) browser support is wrong
7) browser support is wrong (so are fallbacks)
8) history and syntax errors
9) browser support is wrong
10) browser support is wrong (and methodology is completely wrong)
Comment: 6
And they have a ton of kits, too. Shameless plug for a site I rely on all the time!
Comment: 7
Comment: 8
As for validation, the validators are coming up -- have you used Unicorn yet? http://validator.w3.org/unicorn/ and http://www.sitepoint.com/w3c-unicorn-validator/. There is some support for CSS3, it's just the vendor prefixes that will show up as errors (and rightly so, as they are really there for the vendors to work out the execution of the specification).
I really highly recommend going ahead and using CSS3 for the client sites -- especially if your site's audience is using modern browsers and has a very small percentage using the IEs. It's well-established enough and has enough future-proofing built into to be be safe, IMHO.
Comment: 9
http://www.bestbonds.co.uk