Get $500+ of the best After Effects files, video templates and music for only $20!
Cross-Browser CSS in Seconds with Prefixr

Cross-Browser CSS in Seconds with Prefixr

Tutorial Details
  • Tool - Prefixr
  • Usage - Automatically update CSS3 properties.

A couple weeks ago, as I began to manually update my stylesheet with all of the various browser prefixes for the new CSS3 properties, I thought to myself, “This is such a waste of time. Surely, there’s an easier way.


Video Overview

Tools like Compass, or even a TextMate bundle are tremendously helpful – I use them often, actually. But, for many projects, they aren’t available. As a result, we’re left in the position of having to copy and paste over, and over…and over.


Introducing Prefixr.com (Alpha)

Prefixr.com

I built Prefixr to do all this tedious work for me. Simply paste in your stylesheet, press Prefixize (or hit Control + Enter), and Prefixr will filter through the applicable CSS3 properties and dynamically update them.

Can’t remember if Opera provides a prefixed version of, say, the transition property (o-transition)? Don’t worry about it; that’s already coded into Prefixr!

With Prefixr, you only code your stylesheets using the official W3C-recommended markup. When ready for deployment, run the stylesheet through Prefixr, and be done with it!


Use the API

Even better than visiting Prefixr.com is using its API from directly within your favorite code editor. Many editors, like TextMate, offer the ability to execute shell scripts. To automatically update your stylesheet in TextMate, create a new command, and paste in:

curl -sSd "css=$TM_SELECTED_TEXT" "http://prefixr.com/api/index.php"
TextMate Screenshot

Now, select your stylesheet, and type the shortcut that you assigned. It will then be filtered through Prefixr, and dynamically updated. (See video above for more details.)


Squash Those Bugs

This is officially an Alpha release, which means that there are still some bugs to squash. All the kinks should be ironed out within this next week. If you find any yourself, there’s a Feedback button on the left-hand side of Prefixr.com that you can use to notify me.

I hope this tool will be of help to you! Be sure to bookmark it!

Add Comment

Discussion 142 Comments

Comment Page 1 of 31 2 3
  1. Jeffrey Way says:
    Author

    Hey guys –

    Just a couple quick notes on bugs that I’m fixing today:

    1) Commented CSS3 properties are prefixized as well. Needs to be fixed.

    2) Prefixr gets pissy at @import statements. (Should be a quick fix.)

    • bill says:

      Do people still use @import?

      • Lucas C says:

        Yes, actually. I use it in WordPress themes. I create the base style.css, an then use multiple @import statements to bring those files in from a css directory.

        It allows things to be much more neat and organized, in my opinion.

      • Ignaty Nikulin says:

        @import is quite useful if you want include CSS files that will be removed or renamed in future, easily and separately add CSS reset, when you need to add CSS file to not make it messy with previous designer code or simply don’t have access to Header to add them there (for example sometimes when you work with .net).

        So, yes, people still use them.

        :)

      • edwinhollen says:

        Of course!

        I use @import to link the CSS reset. It’s a lot better than having that brick of text at the top of my editor.

      • Mark Dijkstra says:

        Yes a lot of people do use @import, i use it to split big css files(sort the stuff)

        Nice tool Jeff!

      • Travis Watson says:

        Correct me if I’m wrong, but I think bill was commenting on the fact that the best practice was to *not* use @import, and instead create additional ‘s, or use a build script. The @import method creates an unnecessary delay.

        If all stylesheets are in tags, the browser may initiate all requests as soon as the is processed and there is no delay.

        Using the @import method, only the first stylesheet can be loaded while the head is processed, and all subsequent stylesheets must be loaded after the initial stylesheet request has been loaded, because the @import command won’t even be visible to the browser until the request is complete and the file parsed (at lease up to the line with the @import command).

        In my Super Duper Scientific™ quick test, you can see that with two simple stylesheets, the CSS load time effectively doubles for the exact same end effect:
        http://travis.watson.ws/css-latency/at-import/

        Note that this is on HostGator Reseller hosting (aka shared) so the actual load times are going to be all over, but you can at least see the concept.

      • Travis Watson says:

        …and I forgot to escape my entities, I’m so pro. In that first sentence, there’s a lone apostrophe-s, that’s supposed to be: “<link>’s”

    • ralph says:

      your book realy don’t make sense !

  2. Jacob Dubail says:

    Awesome! I’ve been watching the videos that you post on the twit-machine and am very excited to give it a whirl!

  3. FireDart says:

    Looks great Jeff!

  4. lxn says:

    Prove it for sure! Thanks for sharing!

  5. Paulo Griiettner says:

    Hello Jeffrey…

    Definatelly another great tool you bring to us… luved

  6. Mehdi Raza says:

    Awesome tool…
    I hope it graduates to beta version soon.

  7. Jeff Adams says:

    YOU ARE A MACHINE!!!

    Another great freebie thanks for this – this is precisely waht makes Envato great because you guys could have easily made this and sold it over at CodeCanyon but you chose to give it away for free.

    Thanks a bunch!!!

  8. Chris says:

    Excellent tool!

    Def bookmarked and sent around the office!

    Thank you so much!

  9. Jonathan says:

    body{
    text-transform:uppercase;
    }

    gets converted to

    body{
    -webkit-transform: uppercase;
    -moz-transform: uppercase;
    -o-transform: uppercase;
    -ms-transform: uppercase;
    transform: uppercase;
    }

  10. alex says:

    Hey nice. I have a question.

    I don’t have a Mac. So i don’t have a TextMate :(

    How i cant integrate this feature (to prefixize) my code in Dreamweaver CS4 or CS5?

    Is this possible?

    • NakkiNyan says:

      I don’t think CS4/CS5 would really need to allow command line scripting first. Also it does not hurt to have the original with the settings for 1 browser and then copy/paste on the web interface and click compress and upload that version while retaining the original on your OS (easier to edit).

      • NakkiNyan says:

        I meant : “I think CS4/CS5 would really need to allow command line scripting first.”… don’t ask, I reworded something and butchered it.

    • David Smith says:

      Hi Alex,

      You asked about getting this to work in a Windows based editor?

      I use E Text Editor and I can confirm that this works perfectly. E is basically a Text Mate clone for Windows. I highly recommend it.

      Good luck!

  11. Ananda Rizki says:

    Great stuff for time safer! this is what i’m looking for. Thanks, i’m look forward for next version

  12. webster says:

    thanks Jeffrey :)

  13. Fily says:

    Nice app!

    Would it be possible to add comments?

    Something like….

    -moz-border-radius: 10px; /* FF1-3.6 */
    -webkit-border-radius: 10px; /* Saf3-4, iOS 1-3.2, Android <1.6 */
    border-radius: 10px; /* Opera 10.5, IE9, Saf5, Chrome, FF4, iOS 4, Android 2.1+ */

    Thanks a lot for sharing.

  14. Geet Purwar says:

    Awesome Jeffrey.
    That save lots of time. Bookmarked with pleasure.
    Thanks.

  15. Matt says:

    Jeffrey, THANK YOU!!! :) Any plans for a coda plugin?

  16. DeeFi says:

    I’m working with sublime text editor. I’m somewhat new to all this stuff. Is it possible to run curl under sublime? If yes – how to?

  17. I agree, well done. As Matt said, do you know anyway to get this to work with Coda?

  18. Moksha says:

    really amazing thanks a lot for making it so simple

  19. nacim says:

    NO COMMENT !!
    i love this tool ! thx

  20. egiova says:

    Or you are a genius, or you are like me: tired to make rounds like a cat after its tail asking you wtf is happening. And after two hours, two bucks of coffee, and after playing with the tomahawk, discovering that in lines 3675, 4211, 5734 of your css you had typed wbkt, or webkt, or maz.

    Thanks for your huge contribution to designer’s mental health! You’ll be blessed for that, for sure.

  21. Kevin Jensen says:

    Holy, sh** balls, Jeffrey. This is awesome. Well done.

  22. arnold says:

    For PC users whats for us? … some notepad++ or dreamweaver plugin will be great..

  23. Jeffrey Way says:
    Author

    Hey guys – I don’t know how to implement shell scripts on Coda, Dreamweaver, or Notepad++. I’m sure there’s a way. If you use that editor and know how to do it, please leave a comment, and I’ll update the docs!

  24. Matt Webb says:

    This is really sweet.

    If anyone knows how to integrate this into Aptana 3 that would be very very sweet.

    Thanks Jeffrey for another kick ass freebie.

  25. Matt says:

    This is fantastic, Jeffrey! One question, though. Is there a way to do something like:

    border-top-right-radius: 6px;

    and convert it into:

    -webkit-border-top-right-radius: 6px;
    -moz-border-radius-topright: 6px;
    border-top-right-radius: 6px;

    …since right now only the border-radius property will convert. Cheers!

  26. Davin Studer says:

    Is “css=” the only option in the api? Are there options for the exclusion and formatting features in the api as well?

  27. Sacha Schmid says:

    Just a quick question. Which browsers need -ms and -khtml prefixes?

  28. Alexander Smirnoff says:

    It’s amazing!!! It’s great!

    Is anybody know how to integrate this feature into NetBeans ?

    Thanks a lot.

  29. Jason Leung says:

    hey Jeffrey
    how about opacity?

  30. Joseph says:

    Here is a textmate command that works better for me:
    curl -sd “css=`cat`” “http://prefixr.com/api/index.php”

    Set the input to entire document and output to replace entire document for prefixr-ing the entire css file without selected all. Or set the input to selected text and output to replace selected text for prefixr-ing just the selected text. I made both commands. Also you should probably set the scope to source.css

  31. Dean says:

    ahh-mazing!!

    This will save hours of coding; Thank You very much!

  32. wburningham says:

    Any ideas on how to integrate this with MacVim?

    • Jason says:

      So I’m definitely far from experienced with VIM but I haven’t seen anything regarding a VIM command to access the API, and I’ve been playing around trying to get it to work. Hopefully someone more skilled can help sort out the mess I’ve made. So far all I can do is run a command from inside VIM to return the result of a string of CSS written in the command: (only been playing with this on my Windows machine, but I don’t think anything would be different on Linux or Mac except the calling curl part)
      :r !path\to\curl.exe -sS http://prefixr.com/api/index.php –request POST –data css=”border-radius:5px;”
      Will write:
      -webkit-border-radius:5px;
      -moz-border-radius:5px;
      -o-border-radius:5px;
      -ms-border-radius:5px;
      -khtml-border-radius:5px;
      border-radius:5px
      into the buffer at your cursor.

      Problems I’m having:
      - Using text from the file as the POST data, I’ve been looking around and found that % should be a reference to the entire contents of the file. When I try something like :r % this behaves as expected, and writes the entire contents of the file at the cursor. However when I use % in place of explicit border-radius declaration in the command, the filename is used instead of the contents of the file. I’ve probably been searching with the wrong keywords – if anyone can shed some light for me on how to pass a variable into an arbitrary position in the command that would be awesome
      - This one’s probably much easier, and probably gives me a big bright badge that says “VIM NEWBIE” – but replacing text in the buffer with the returned data from the API, right now I’m just using :r which will just insert the result at the cursor, leaving behind the content that was already there.

  33. salmanlp says:

    check http://prefixr.com on ie 8 css3 is not working.
    any reason?

  34. Dan Avery says:

    You seriously rock, Jeffery! Thanks a ton.

  35. Tim says:

    For those of you that use Coda, I created a plugin to to access the Prefixr api via shortcut.. I’ve sent it to Jeffrey to include in the Prefixr documentation but until it he posts it publicly I’ve uploaded it to my S3 account and made it available for download.. you can access it here: https://s3.amazonaws.com/rawcreative/misc/Prefixr.codaplugin

    Usage is simple, make a selection and hit Control+Option+P and it will send the info to Prefixr and replace the selection with Prefixr’s results. If Jeffrey adds any additional functionality to the API I’ll update the plugin and redistribute it.. you can also email me at tim at rawcreativestudios dot com with questions/issues

  36. That’s really amazing. I can save a lot of time spending to write lines of code for these.

  37. Ryan says:

    This is really sweet! I will have to start using it!

  38. Rigel Glen says:

    Is there a way to use the API in Vim

  39. Brandon says:

    I know this may be more difficult and possibly not even desired in this tool but older versions of IE dont understand rgba, it would be sweet if the code had a background-color of say rgba(255,255,255,.5) that it would output #FFFFFF as a background color also for browsers that ignored rgba.

  40. luka says:

    What a good idea! Thanks Jeffrey

  41. Daniel G says:

    Really neat tool Jeffrey!

    Is it possible you can optimize it for SASS/SCSS code?

  42. nice post! it is great pleasure to visit your site. thanks!!

  43. Would love to know how to include this in Notepad++ Can anybody explain me how to do this?

  44. Thibaut says:

    Awesome.

    We now just need an AppleScript or Automator service o be able to use in any app. :)

  45. Wayne Saunders says:

    This is a great time saver!!

    Any way that you would be able to add the includes for PIE?

  46. Miroslav says:

    “text-shadow” don’t work

  47. Looks really nice. Currently we use Compass with Sass but need to check this out for non-Sass sites.

  48. Sitebase says:

    Very cool project Jeffrey!

  49. Jordan says:

    Added this into KomodoEdit. Works awesome. Thanks.

Comment Page 1 of 31 2 3

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.