Import regular CSS file in SCSS file?
Looks like this is unimplemented, as of the time of this writing:
https://github.com/sass/sass/issues/193
For libsass (C/C++ implementation), import works for *.css
the same way as for *.scss
files - just omit the extension:
@import "path/to/file";
This will import path/to/file.css
.
See this answer for further details.
See this answer for Ruby implementation (sass gem)
You must prepend an underscore to the css file to be included, and switch its extension to scss (ex: _yourfile.scss
). Then you just have to call it this way:
@import "yourfile";
And it will include the contents of the file, instead of using the CSS standard @import directive.
After having the same issue, I got confused with all the answers here and the comments over the repository of sass in github.
I just want to point out that as December 2014, this issue has been resolved. It is now possible to import css
files directly into your sass file. The following PR in github solves the issue.
The syntax is the same as now - @import "your/path/to/the/file"
, without an extension after the file name. This will import your file directly. If you append *.css
at the end, it will translate into the css
rule @import url(...)
.
In case you are using some of the "fancy" new module bundlers such as webpack, you will probably need to use use ~
in the beginning of the path. So, if you want to import the following path node_modules/bootstrap/src/core.scss
you would write something like @import "~bootstrap/src/core"
.
NOTE:
It appears this isn't working for everybody. If your interpreter is based on libsass
it should be working fine (checkout this). I've tested using @import
on node-sass and it's working fine. Unfortunately this works and doesn't work on some ruby instances.
This was implemented and merged starting from version 3.2
(pull #754 merged on 2 Jan 2015 for libsass
, issues originaly were defined here: sass
#193 #556, libsass
#318).
To cut the long story short, the syntax in next:
to import (include) the raw CSS-file
the syntax is **without `.css`** extension at the end (results in actual read of partial `s[ac]ss|css` and include of it inline to SCSS/SASS):@import "path/to/file";
to import the CSS-file in a traditional way
syntax goes in traditional way, **with `.css` extension** at the end (results to `@import url("path/to/file.css");` in your compiled CSS):@import "path/to/file.css";
And it is damn good: this syntax is elegant and laconic, plus backward compatible! It works excellently with libsass
and node-sass
.
__
To avoid further speculations in comments, writing this explicitly: Ruby based Sass still has this feature unimplemented after 7 years of discussions. By the time of writing this answer, it's promised that in 4.0 there will be a simple way to accomplish this, probably with the help of @use
. It seems there will be an implementation very soon, the new "planned" "Proposal Accepted" tag was assigned for the issue #556 and the new @use
feature.
UPD: on 26 October 2020 lib-sass was deprecated, therefore issue #556 was immediately closed.
__
answer might be updated, as soon as something changes.