Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
SASS | Style Rules
Next article icon

SASS | Style Rules

Last Updated : 29 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
Just like CSS, style rules are also the base of SASS. It is used similar to CSS. Select the elements to be styled using a selector and then declare it's properties which further affects the look of those elements. Example: Sass Code: css
.header   padding: 3px 10px   font-size: 40px   font-family: sans-serif   border: 2px solid green 
This would result in the following CSS output:
  .header{    padding: 3px 10px;    font-size: 40px;    font-family: sans-serif;    border: 2px solid green;  }  
But, the advantage as it is merely just repeating itself. SASS wishes to make your code easy, not just repeat itself. So, in SASS, you may avoid repeating the same selector again and again. You can easily write one style rule inside the other. SASS automatically do your desired job. This feature of SASS is known as nesting. Example: Sass Code css
navbar   ul     padding: 2px     list-style: square    li     display: inline-block    a     display: block     padding: 4px 10px     font-family: sans-serif 
This would result in the following CSS output:
  navbar ul{      padding: 2px;      list-style: square;  }  navbar li{      display: inline-block;  }  navbar a{      display: block;      padding: 4px 10px;      font-family: sans-serif;  }  
Nesting rules are quite useful, but sometimes they can create a large amount of CSS. The more you nest, the more bandwidth it takes to generate CSS, and the more work will be done by your browse to render it. Hence the selectors must be kept shallow. Some more useful examples: Nested rules are quite useful for handling the selector lists. Selector lists refer to the list of selectors separated with commas. These are compiled as the following example: SASS Code: css
.abc, .def   ul, p     padding: 2px     font-family: sans-serif     border: 1px 
This would result in the following CSS output:
  .abc ul, .abc p, .def ul, .def p {      padding: 2px;      font-family: sans-serif;      border: 1px  }  
Interpolation: In order to insert values like variables and functions into the selectors, you can use interpolation. Interpolation is very useful while creating mixins as it allows you to generate selectors from the parameters your users have provided. Example: Sass Code css
@mixin full-form($name, $glyph)      span.full-form-#{$name}      font-family: sans-serif     padding: 4px     border: 10px     content: $glyph @include full-form("GFG", "GeeksForGeeks") 
This would result in the following CSS output:
  span.full-form-GFG {    font-family: sans-serif;    padding: 4px;    border: 10px;    content: "GeeksForGeeks";  }  
Sass only analyses selectors after interpolation is completely resolved, meaning you are safe to use interpolation for generating any part of the selector without worrying that it won’t work.

Next Article
SASS | Style Rules

S

Slash_IT
Improve
Article Tags :
  • Web Technologies
  • CSS
  • SASS

Similar Reads

    Sass | At-rules
    At-rules are simply some CSS statements that instructs the CSS how to behave in particular conditions. They start with an "@" sign, followed by an identifier and ends with a semicolon (in case of SCSS), or the next CSS statement (in case of SASS), depending upon the Sass syntax used.  Syntax: css @i
    2 min read
    SASS @for and @while Rule
    @for rule is used to count up or down from one number to another and check the section for every number that comes in between the given range. Every number is assigned a given variable name. In order to exclude the last number, use to and in order to include it, use through. Syntax: css @for <var
    2 min read
    SASS @for Rule
    The @for rule in SASS is used to count up or down from one number to another and check the section for every number that comes in between the given range. Every number is assigned a variable name that can be accessed in the loop. It can be used in two ways: 1. start through end: In this type, the "s
    2 min read
    SASS sass:string Module
    The sass:string module makes it easy to combine, search, or split strings apart. The following are the list of functions that can be used using this module. 1. string.quote() function: This function returns a quoted string. Syntax: string.quote(string) quote(string) Example: css @debug string.quote(
    3 min read
    SASS Parent Selector
    Parent selector is a special type of selector in SASS, which allows us to reuse the outer(Parent) selector in an efficient way. See the example below to get the idea: For example: Suppose we have following CSS style block, a { text-decoration: none; display: inline-block; background-color: lightgray
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences