Sass Functions

What You’ll Learn
Sass ships built-in modules of functions. Load one with @use "sass:math" (or color, list, map, meta, selector, string) and call its functions with the module name as a prefix.
@use "sass:math";
@use "sass:map";
@use "sass:string";
$sizes: (sm: 480px, md: 768px);
.box {
width: math.div(100%, 3);
max-width: map.get($sizes, md);
content: string.to-upper-case("hello");
} Function Index
Math Functions
Numbers, rounding, trigonometry, and constants.
math.abs()TutorialAbsolute Value of a Number
math constantsTutorialRead-only $pi, $e, $epsilon and number limits.
math.acos()TutorialArccosine in Degrees
math.asin()TutorialArcsine in Degrees
math.atan()TutorialArctangent in Degrees
math.atan2()TutorialTwo-Argument Arctangent
math.ceil()TutorialRound a Number Up
math.clamp()TutorialKeep a Number in Range
math.compatible()TutorialCompatible Units Check
math.cos()TutorialCosine of an Angle
math.div()TutorialDivide Numbers & Cancel Units
math.floor()TutorialRound a Number Down
math.hypot()TutorialHypotenuse & Vector Length
math.is-unitless()TutorialCheck for No Units
math.log()TutorialNatural Log & Custom Base
math.max()TutorialHighest of One or More Numbers
math.min()TutorialLowest of One or More Numbers
math.percentage()TutorialDecimal to %
math.pow()TutorialRaise a Base to a Power
math.random()TutorialRandom Numbers at Compile Time
math.round()TutorialRound to the Nearest Whole Number
math.sin()TutorialSine of an Angle
math.sqrt()TutorialSquare Root
math.tan()TutorialTangent of an Angle
math.unit()TutorialRead a Number’s Units
Color Functions
Read, adjust, mix, and convert colors.
color.adjust()TutorialShift Channels by Fixed Amounts
adjust-hue()TutorialDeprecated — Use color.adjust
color.alpha()TutorialRead Opacity 0–1 — Prefer color.channel
color.blackness()TutorialHWB Blackness 0%–100% — Prefer color.channel
color.blue()TutorialRGB Blue 0–255 — Prefer color.channel
color.change()TutorialSet Channels to Exact Values
color.channel()TutorialRead One Channel as a Number
color.complement()TutorialRotate Hue 180deg
darken()TutorialDeprecated — Prefer color.scale / color.adjust
desaturate()TutorialDeprecated — Prefer color.scale / color.adjust
fade-in()TutorialDeprecated — Prefer color.scale / color.adjust
fade-out()TutorialDeprecated — Prefer color.scale / color.adjust
color.grayscale()TutorialMute to Gray, Keep Lightness
color.green()TutorialRGB Green 0–255 — Prefer color.channel
color.hue()TutorialHSL Hue 0deg–360deg — Prefer color.channel
color.ie-hex-str()Tutorial#AARRGGBB for Legacy IE Filters
color.invert()TutorialNegative / Inverse Colors
color.is-legacy()TutorialDetect rgb / hsl / hwb Spaces
color.is-missing()TutorialDetect none Channels
color.is-powerless()TutorialHue That Doesn’t Affect Look
lighten()TutorialDeprecated — Prefer color.scale / color.adjust
color.lightness()TutorialHSL Lightness 0%–100% — Prefer color.channel
color.mix()TutorialBlend Two Colors with Weight
opacify()TutorialDeprecated — Prefer color.scale / color.adjust
color.opacity()TutorialRead Alpha 0–1 — Prefer color.channel
color.red()TutorialRGB Red 0–255 — Prefer color.channel
rgb()TutorialBuild RGB Colors — Global Constructor
rgba()TutorialRGB + Alpha — Global Constructor
color.same()TutorialVisual Equality Across Spaces
saturate()TutorialDeprecated — Prefer color.scale / color.adjust
color.saturation()TutorialHSL Saturation 0%–100% — Prefer color.channel
color.scale()TutorialFluid Channel Scaling Toward Min/Max
color.space()TutorialRead a Color’s Space Name
color.to-gamut()TutorialMap Colors Into a Target Gamut
color.to-space()TutorialConvert Between Color Spaces
transparentize()TutorialDeprecated — Prefer color.scale / color.adjust
color.whiteness()TutorialHWB Whiteness 0%–100% — Prefer color.channel
List Functions
Build and inspect lists.
list.append()TutorialAdd a Value to the End of a List
list.index()TutorialFind a Value’s 1-Based Position
list.is-bracketed()TutorialDetect Square-Bracket Lists
list.join()TutorialMerge Two Lists Into One
list.length()TutorialCount Items in a List
list.nth()TutorialGet a List Item by 1-Based Index
list.separator()TutorialRead space, comma, or slash
list.set-nth()TutorialReplace a List Item by Index
list.slash()TutorialBuild a Slash-Separated List
list.zip()TutorialPair Parallel Lists into Sublists
Map Functions
Read, merge, and update maps.
map.deep-merge()TutorialRecursively Merge Nested Maps
map.deep-remove()TutorialDelete a Nested Map Key by Path
map.get()TutorialRead a Map Value by Key or Path
map.has-key()TutorialCheck If a Map Key Exists
map.keys()TutorialList All Keys in a Map
map.merge()TutorialCombine Two Maps
map.remove()TutorialDelete Top-Level Map Keys
map.set()TutorialAdd or Update a Map Key
map.values()TutorialList All Values in a Map
Meta Functions
Introspect values, call functions and mixins, and work with modules.
meta.accepts-content()TutorialCan a Mixin Take @content?
meta.apply()TutorialInclude a Mixin Value
meta.calc-args()TutorialRead Calculation Arguments
meta.calc-name()TutorialName of a Calculation
meta.call()TutorialInvoke a Function Value
meta.content-exists()TutorialWas @content Passed?
meta.feature-exists()TutorialDeprecated Feature Check
meta.function-exists()TutorialIs a Function Defined?
meta.get-function()TutorialResolve a Function Value
meta.get-mixin()TutorialResolve a Mixin Value
meta.global-variable-exists()TutorialIs a Global Defined?
meta.inspect()TutorialDebug Any Value as a String
meta.keywords()TutorialNamed Args from $args...
meta.load-css()TutorialInclude Another Module’s CSS
meta.load()TutorialLoad a Stylesheet as a Module Value
meta.mixin-exists()TutorialIs a Mixin Defined?
meta.get-module()TutorialFetch a Loaded Module by Namespace
meta.module-functions()TutorialList a Module’s Functions
meta.module-mixins()TutorialList a Module’s Mixins
meta.module-variables()TutorialList a Module’s Variables
meta.type-of()TutorialWhat Type Is This Value?
meta.variable-exists()TutorialDoes This Variable Exist Here?
Selector Functions
Work with selectors as values.
selector.append()TutorialGlue Selectors Without Spaces
selector.extend()TutorialRewrite Selectors Like @extend
selector.is-superselector()TutorialDoes This Selector Cover That One?
selector.nest()TutorialNest Selectors Like Nested SCSS
selector.parse()TutorialTurn a String Into a Selector Value
selector.replace()TutorialSwap a Selector Piece
selector.simple-selectors()TutorialSplit a Compound Selector
selector.unify()TutorialFind the Overlap of Two Selectors
String Functions
Slice, search, and transform strings.
string.index()TutorialFind a Substring Position
string.insert()TutorialInsert Text at an Index
string.length()TutorialCount Characters in a String
string.quote()TutorialMake a Quoted String
string.slice()TutorialExtract a Substring
string.split()TutorialSplit a String into a List
string.to-lower-case()TutorialConvert to Lowercase
string.to-upper-case()TutorialConvert to Uppercase
string.unique-id()TutorialGenerate a Unique CSS Identifier
string.unquote()TutorialRemove Quotes from a String
Frequently Asked Questions
Next: Sass math.abs Function
Start with the first tutorial in this section.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful
