In my current project, I checked something that was already developed, and there is a webpart project item, which has embedded CSS on the HTML markup.

I dont like this way because the code does not look clean, and I think it would be easier to maintain if there is a separate css file in the 14 hive or something

The question is: 1. How to provision CSS files to the 14 hive? 2. Will those css be available to all site collections? 3. I suppose that I would need to change the master page to be available to use the CSS classes in the webparts.

1 Answer 1


There's two ways to do this:

  1. store your css file in the style library (css can be different for eacht site collection.

To do so: Use a module

 <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <Module Name="Test" Url="Style Library/CSS Style Sheets" Path="" RootWebOnly="FALSE">
     <File Url="Test.css" Type="GhostableInLibrary"/>

More info: http://msdn.microsoft.com/en-us/library/gg447066.aspx

  1. store your css in the 14/_layouts folder (css will be the same for all site collections)

To do so: add a mapped folder (layouts) in your Visual Studio 2010 solution and add the css file in a subfolder of this folder. This will be provisioned on deployment without feature or so.

more info: http://msdn.microsoft.com/en-us/library/ee231521.aspx

  1. You will, indeed, need to change your masterpage by adding this line:

http://pastie.org/3379314 (could not paste it here, dont know why)

BTW, the above explanation also works for jquery files etc...

  • FYI - if you paste code in here, select it and click the { } symbol in the toolbar, it'll apply formatting so it renders when you post.
    – James Love
    Commented Feb 14, 2012 at 8:50
  • As you can see, ive done this in my first line of code. But the second line (the one i've put on pastie) did not work. It removed 50% of the code :| Commented Feb 14, 2012 at 9:14
  • Why the hell does he change my numbered list ??? It's supposed to be 1, 2, 3 :( Commented Feb 14, 2012 at 11:37
  • Lol, bit buggy at times, is the text editor :P
    – James Love
    Commented Feb 14, 2012 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.