How to import regular CSS file in SCSS file ? - GeeksforGeeks (2024)

Table of Contents
HTML HTML FAQs

Last Updated : 24 Aug, 2022

Improve

In this article, we will learn how to import regular CSS files into SCSS files. Syntactically Awesome Style Sheet is the superset of CSS. SCSS is the more advanced version of CSS. SCSS was designed by Hampton Catlin and was developed by Chris Eppstein and Natalie Weizenbaum. Due to its advanced features, it is often termed Sassy CSS. SCSS have file extension of .scss.You can achieve this task just by writing one line.

@import keyword: This keyword is used to import other files. For example, we made one file with some property and after some time you feel like you want to change some elements you need to create one different file with a different name. After creating a file you can add that file to the current project with the help of the @import keyword.

Import keyword is used to combine all SCSS and CSS files into one file because the code becomes lengthy when we add too many properties to one file so it is used to separate files into smaller parts and import them later when needed.

Syntax:

@import url "/path/of/the/file";

Approach:

  • First, create an HTML file without CSS property.
  • In the next step, create a file with the .scss extension.
  • In the last step, you need to import the CSS file into the SCSS file using the keyword import.

The process for importing the regular CSS file into the SCSS file: You can create any number of CSS and SCSS files and you can use them using the keyword ‘import’. For example, create one CSS file and import that file into the SCSS file then you can able to use that property in your project.

Example1: In the below code, we will create an HTML file and then with the help of the import keyword we will add some CSS properties to the HTML file.

So, first, we create the GfG.html file

HTML

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content=

"width=device-width, initial-scale=1">

<link rel="stylesheet" href="style.css">

<!-- font-awesome cdn -->

<script src=

</script>

</head>

<body>

<center>

<h1>GeeksforGeeks</h1>

<h3>

A computer science portal for geeks.

</h3>

</center>

</body>

</html>

After creating the GfG.html file, we create One partial named GfG.css

body{ border: 5px solid black; margin: 60px; }

Let us create one more CSS file named two.css

h3{ color:red;}

In the next step, we can import GfG.css in style.scss file and write CSS to style our document. As we have imported the GfG.css and two.css file we can now use them in our style.scss file.

//style.scss@import 'GFG.css';@import 'two.css';

Final style.css file:

@import url(GFG.css);@import url(two.css);

Output:

How to import regular CSS file in SCSS file ? - GeeksforGeeks (1)

Example2: In the below code we will create an HTML file and then with the help of the import keyword, we will add some CSS properties to the HTML file.

So, first, we create the GfG.html file

HTML

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8" />

<title>GeeksforGeeks</title>

<link rel="stylesheet" href="style.css">

</head>

<body>

<center>

<h1>GeeksforGeeks</h1>

<h3>A computer science portal for geeks</h3>

</center>

</body>

</html>

After creating the GfG.html file, we create One partial named one.scss

$green:green;$black:black;$red:red;

In the next step, we can import one.scss in style.scss file and write CSS to style our document. As we have imported the one.css file we can now use them in our style.scss file.

@import 'one';h1{ background-color:$red;}

Final style.css file:

h1 { background-color: red; }

Output:

How to import regular CSS file in SCSS file ? - GeeksforGeeks (2)



`; tags.map((tag)=>{ let tag_url = `videos/${getTermType(tag['term_id__term_type'])}/${tag['term_id__slug']}/`; tagContent+=`

`+ tag['term_id__term_name'] +`

`; }); tagContent+=`
How to import regular CSS file in SCSS file ? - GeeksforGeeks (2024)

FAQs

How to import regular CSS file in SCSS file ? - GeeksforGeeks? ›

The SCSS syntax ( .scss ) is used most commonly. It's a superset of CSS, which means all valid CSS is also valid SCSS.

Does normal CSS work with SCSS? ›

The SCSS syntax ( .scss ) is used most commonly. It's a superset of CSS, which means all valid CSS is also valid SCSS.

How to migrate CSS to SCSS? ›

Steps to Migrate from CSS to SCSS:
  1. Addition of SCSS styles schematics to Angular.json file.
  2. Renaming all the CSS files to SCSS files.
  3. Updating the paths/urls (styleUrls) in component levels.
Dec 12, 2023

How to use SCSS with CSS? ›

The simplest way to get started with SCSS is to download a Sass compiler plugin with your preferred code editor. Your SCSS will be compiled into CSS as you code. For example, Visual Studio has a plugin called Live Sass Compiler which will compile anything you write into your .

How do I import one CSS file into another? ›

  1. Import: Now importing CSS with URL( ) file in HTML document.
  2. CSS: Now write code for style. css file to work on your HTML document.
  3. Note: There are two different ways to import a CSS file into another using @import url(“style2. css”); or @import “style2.
Jan 24, 2024

What is the difference between normal CSS and SCSS? ›

SCSS consists of more advanced features, and thus, it can perform more advanced functions. A regular CSS language does not assign various nested rules. The SCSS language promotes rules that are properly nested. CSS is a styling language that lets users create, design, and style various web pages.

What is the difference between SCSS and plain CSS? ›

CSS consists of various common features, and thus, it can perform some basic functions. SCSS consists of more advanced features, and thus, it can perform more advanced functions. Commonly used to style web pages. Mostly used with the SASS program, which is written in Ruby.

Can I convert CSS to Sass? ›

CSS to SASS is very unique tool for convert CSS to SASS and allows to download, save, share and print CSS data..

What is the import rule in CSS? ›

Definition and Usage. The @import rule allows you to import a style sheet into another style sheet. The @import rule must be at the top of the document (but after any @charset declaration). The @import rule also supports media queries, so you can allow the import to be media-dependent.

Do I need to learn CSS before SCSS? ›

You should complete CSS first, then practice it by makings some cool websites and animation then only move to sass, Remember only learning CSS and no practice will not work for longer.

What is the difference between import and use in SCSS? ›

The new @use is similar to @import . but has some notable differences: The file is only imported once, no matter how many times you @use it in a project. Variables, mixins, and functions (what Sass calls "members") that start with an underscore (_) or hyphen (-) are considered private, and not imported.

How to import scss file in scss? ›

Using @import we can import SCSS or CSS files in our main file, So basically we can combine multiple files together.
  1. Syntax: @import 'Relative path to the file1', 'Relative path to the file2', ...; ...
  2. Nesting Import. We can also nest import inside a specific component in SASS. ...
  3. NOTE: The @import has some serious drawbacks:
Dec 17, 2021

How to combine all CSS files into one? ›

Operation. The "CSS Combine" filter finds all CSS <link> tags. If there was more than one in a flush window, it removes each of those links and replaces them with a single <link> to the merged document, which it places wherever the first CSS <link> originally was.

Why is imported an easy way to insert the file in CSS? ›

The import rule allows you to import files with four different types of media settings: print, screen, speech, and all. By using an import rule, you may also insert a CSS file into an HTML document. The import rule allows you to style items in a separate CSS file before importing them into an HTML document.

How do I link an external CSS file to another folder? ›

The href Attribute

It is a clickable link, so you can also hold CTRL and click it to view the CSS file. For example, href="styles.css" if the CSS file is located in the same folder as the HTML file. Or href="folder/styles.css" if the CSS file is located on another folder.

Should I use CSS or SCSS variables? ›

Sass variables are imperative, which means if you use a variable and then change its value, the earlier use will stay the same. CSS variables are declarative, which means if you change the value, it'll affect both earlier uses and later uses.

Top Articles
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 5833

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.