SlideShare a Scribd company logo
CSS Custom Properties
Add Variables to Your CSS
“CSS Custom Properties” — @geoffrey_crofte 2
Geoffrey Crofte
geoffrey.crofte.fr
creativejuiz.fr
UX/UI Web Designer at Maltem (Foyer)
@geoffrey_crofte
“CSS Custom Properties” — @geoffrey_crofte
Overview
What are Custom Properties?
Quick start with CSS Variables.
Why CSS C.P. instead of Sass variables?
Use cases & Demos
Takeaways
What are Custom Properties?
What are Custom Properties?
CSS Variables
IIIIIIII
$color: #bada55;
@color: #bada55;
This not about…
This is more about…
http://bit.ly/csscurrentcolor
This is more about…
http://bit.ly/csscurrentcolor
currentColor
But this is not about…
“CSS Custom Properties” — @geoffrey_crofte
A custom property is any
property whose name starts
with two dashes […] like --foo
“CSS Custom Properties” — @geoffrey_crofte
Custom properties are solely for
use by authors and users; CSS
will never give them a meaning
beyond what is presented here.
“CSS Custom Properties” — @geoffrey_crofte
Custom properties are solely for
use by authors and users; CSS
will never give them a meaning
beyond what is presented here.
CSS Custom Properties (aka CSS Variable)
Custom properties define variables
Variables are referenced with the var() notation
They are Case-Sensitive
Their value is “extremely permissive”
What the Spec says…
Do the fu%€
you want with them.
In other words…
How to use CSS Variables?
--variableName: value;
CSS Declaration
:root {
}
--variableName: value;
CSS Declaration
.element {
}
property: var(--variableName);
.element {
}
CSS Use
Quick Example of use
Why CSS instead of Sass Variables?
The main issue with Sass (or LESS) variables:
They have to be computed to get their value.
Computation
CSS Variables are alive
JavaScript can access them
Media Queries ❤ CSS Variables
Media Queries ❤ CSS Variables
CSS Variables are inherited
CSS Variables are inherited
CSS Variables are inherited
CSS Variables are inherited
Demos & Use Cases
http://bit.ly/cssvargradient
Mouse position
CSS Transformation
CSS Transformation
CSS Transformation
CSS Transformation
CSS Transformation
CSS Transformation
CSS Transformation
Why not pushing transformations directly in JavaScript?
Now you’re wondering…
Why not pushing transformations directly in JavaScript?
Now you’re wondering…
Why not pushing transformations directly in JavaScript?
Now you’re wondering…
Maintainability / Portability

style=“transform…” is dirty. Period.

Why not pushing transformations directly in JavaScript?
Now you’re wondering…
Maintainability / Portability

style=“transform…” is dirty. Period.

Inheritance

style=“transform…” do not make --x and
--y inherited.
Why not pushing transformations directly in JavaScript?
Now you’re wondering…
Maintainability / Portability

style=“transform…” is dirty. Period.

Inheritance

style=“transform…” do not make --x and
--y inherited.
It’s a philosophy

CSS is for styling. JS is not.

Why not pushing transformations directly in JavaScript?
Now you’re wondering…
Maintainability / Portability

style=“transform…” is dirty. Period.

Inheritance

style=“transform…” do not make --x and
--y inherited.
It’s a philosophy

CSS is for styling. JS is not.

Futur proof

Let the CSS engine handle that part.
http://bit.ly/cssvargradient2
CSS Transformation
Themable interfaces
Themable interfaces
Themable interfaces
Themable interfaces
Themable interfaces
Accessibility Example
Accessibility Example
Responsive
Responsive
Further Takeaways
--variableName: value !important;
:root {
}
CSS Variables are CSS properties
--variableName: lolilol;
:root {
}
(kind of) Silent error
--spacing: 20;
:root {
}
You can’t “build up” values.
margin: var(--spacing)px;
:root {
}
--spacing: 20;
:root {
}
You can’t “build up” values.
margin: var(--spacing)px;
:root {
}
Doesn’t work
--spacing:;
:root {
}
Strange behaviour
--spacing: ;
:root {
}
Invalid
Valid
Yeah, that’s a space caracter.
Fallback value
var(--variableName, default);
Fallback value
Fallback value
Doesn’t support var()
Fallback value
Doesn’t support var()
Fallback is there
Fallback value
Doesn’t support var()
Fallback is there
Fallback value
Doesn’t support var()
Fallback is there
--bgColor Value
Fallback value
Doesn’t support var()
Fallback is there
--bgColor Value
Fallback value
Doesn’t support var()
Fallback is there
--bgColor Value
Transparent
Variable as Fallback
var(--var1, var(--var2, default));
Variable as Fallback
var(--var1, var(--var2, var(--var3,
var(--var4, var(--var5,
default)))));
You can’t cycle with variables
You can’t cycle with variables
@supports (color: var(--)) {
…
}
Support Testing
Compatibility
Polyfills
https://github.com/aaronbarker/css-variables-polyfill
“CSS Custom Properties” — @geoffrey_crofte
Some resources
CSS Variable Secrets (Lea Verou Smashing Conf. 2017)
CSS Custom Properties (CCSWG W3C documentation)
CSS Mouse Tracking Gradient (Gradient on Text demonstration)
CSS Variable Tutorials (A series of 4 short videos about CSS Variables)
Thanks!
“CSS Custom Properties” — @geoffrey_crofte 55
Geoffrey Crofte
geoffrey.crofte.fr
creativejuiz.fr
UX/UI Web Designer at Maltem (Foyer)
@geoffrey_crofte

More Related Content

What's hot (20)

PDF
Migrating Oracle database to Cassandra
Umair Mansoob
 
PDF
What is DBT - The Ultimate Data Build Tool.pdf
MounikaPolabathina
 
PDF
DVC - Git-like Data Version Control for Machine Learning projects
Francesco Casalegno
 
PPTX
HBase Vs Cassandra Vs MongoDB - Choosing the right NoSQL database
Edureka!
 
PDF
7.-Bootstrap-5-report powerpoint presentation
JohnLagman3
 
PDF
Building Reliable Data Lakes at Scale with Delta Lake
Databricks
 
PPTX
AZ-900 Section 1 (Cloud Concepts)..pptx
IPSpecialist
 
PPTX
Azure vnet
zekeLabs Technologies
 
PPTX
Azure Networking - The First Technical Challenge
Aidan Finn
 
PPTX
Responsive web-design through bootstrap
Zunair Sagitarioux
 
PPTX
Disaster Recovery Using Azure Services
Adil Arif
 
PPTX
Introduction to Apache Camel
Claus Ibsen
 
PPTX
Apache kafka
Kumar Shivam
 
PDF
Towards Functional Programming through Hexagonal Architecture
CodelyTV
 
PPTX
Introduction to Node js
Akshay Mathur
 
PDF
Confluent Workshop Series: ksqlDB로 스트리밍 앱 빌드
confluent
 
PDF
Best Practices for Middleware and Integration Architecture Modernization with...
Claus Ibsen
 
PDF
Azure Data Factory V2; The Data Flows
Thomas Sykes
 
PPTX
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Lucas Jellema
 
PPTX
Client side scripting using Javascript
Bansari Shah
 
Migrating Oracle database to Cassandra
Umair Mansoob
 
What is DBT - The Ultimate Data Build Tool.pdf
MounikaPolabathina
 
DVC - Git-like Data Version Control for Machine Learning projects
Francesco Casalegno
 
HBase Vs Cassandra Vs MongoDB - Choosing the right NoSQL database
Edureka!
 
7.-Bootstrap-5-report powerpoint presentation
JohnLagman3
 
Building Reliable Data Lakes at Scale with Delta Lake
Databricks
 
AZ-900 Section 1 (Cloud Concepts)..pptx
IPSpecialist
 
Azure Networking - The First Technical Challenge
Aidan Finn
 
Responsive web-design through bootstrap
Zunair Sagitarioux
 
Disaster Recovery Using Azure Services
Adil Arif
 
Introduction to Apache Camel
Claus Ibsen
 
Apache kafka
Kumar Shivam
 
Towards Functional Programming through Hexagonal Architecture
CodelyTV
 
Introduction to Node js
Akshay Mathur
 
Confluent Workshop Series: ksqlDB로 스트리밍 앱 빌드
confluent
 
Best Practices for Middleware and Integration Architecture Modernization with...
Claus Ibsen
 
Azure Data Factory V2; The Data Flows
Thomas Sykes
 
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Lucas Jellema
 
Client side scripting using Javascript
Bansari Shah
 

Similar to CSS Custom Properties (aka CSS Variable) (20)

PDF
CSS3: Are you experienced?
Denise Jacobs
 
PDF
20111129 modernizr
brooky-yen
 
PPTX
HTML Tour - Buenas prácticas en el desarrollo web
Plain Concepts
 
PDF
CSS vs. JavaScript - Trust vs. Control
Christian Heilmann
 
PDF
Extreme CSS Techniques - MadWorld Europe 2018, Scott DeLoach, ClickStart
Scott DeLoach
 
KEY
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
applicake
 
PDF
Intro to CSS3
Denise Jacobs
 
KEY
Slow kinda sucks
Tim Wright
 
KEY
Sass Essentials at Mobile Camp LA
Jake Johnson
 
PDF
960 grid psd
Raju Nag
 
PDF
Simply Responsive CSS3
Denise Jacobs
 
PDF
Css3 transitions and animations + graceful degradation with jQuery
Andrea Verlicchi
 
PDF
CSS3: Ripe and Ready
Denise Jacobs
 
PDF
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
 
PDF
Refresh OKC
Nathan Smith
 
PDF
CSS3: Ripe and Ready to Respond
Denise Jacobs
 
KEY
Advanced sass/compass
Nick Cooley
 
PPTX
The New UI - Staying Strong with Flexbox, SASS, and {{Mustache.js}}
Eric Carlisle
 
CSS3: Are you experienced?
Denise Jacobs
 
20111129 modernizr
brooky-yen
 
HTML Tour - Buenas prácticas en el desarrollo web
Plain Concepts
 
CSS vs. JavaScript - Trust vs. Control
Christian Heilmann
 
Extreme CSS Techniques - MadWorld Europe 2018, Scott DeLoach, ClickStart
Scott DeLoach
 
A brief look at CSS3 techniques by Aaron Rodgers, Web Designer @ vzaar.com
applicake
 
Intro to CSS3
Denise Jacobs
 
Slow kinda sucks
Tim Wright
 
Sass Essentials at Mobile Camp LA
Jake Johnson
 
960 grid psd
Raju Nag
 
Simply Responsive CSS3
Denise Jacobs
 
Css3 transitions and animations + graceful degradation with jQuery
Andrea Verlicchi
 
CSS3: Ripe and Ready
Denise Jacobs
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
 
Refresh OKC
Nathan Smith
 
CSS3: Ripe and Ready to Respond
Denise Jacobs
 
Advanced sass/compass
Nick Cooley
 
The New UI - Staying Strong with Flexbox, SASS, and {{Mustache.js}}
Eric Carlisle
 
Ad

Recently uploaded (20)

PPTX
High-Rise Interior Mastery by Top 3D Visualization Experts
Yantram Animation Studio Corporation
 
PPTX
CompanyReviewTypeOfPowerpointThatIsColor
plukleomarigpuara
 
PDF
🔴BUKTI KEMENANGAN HARI INI SELASA 08 JULI 2025 !!!🔴
GRAB
 
PDF
SS27 Men's Fashion Trend Book Peclers Paris
Peclers Paris
 
PPT
Teaching Learning-1- (New) 2020.pptuuuo
omarekaabed
 
PPTX
hall ppt 1 it for basic tamolet .pptx
ashishbehera64
 
PPTX
slidesgo-s-story-of-zara-a-strategi.pptx
Ehsan63
 
PDF
Black and Blue Modern Technology Presentation.pdf
hjaders1104
 
PPT
Javrhrbthtbryin6trtvrhnberra-without-BlueJ.ppt
jotola6956
 
PPTX
Town planning is a concept used in architectural design. It plays a very impo...
IshikaPanchal11
 
PPTX
BMC S6 M3 P1 building mATERIALS AND CONSTRUCTION.pptx
RizwanAlavi
 
PDF
Uber Driver Hackday Sprint Solving Ride Cancellations
YellowSlice1
 
DOCX
Ai Vehicle traffic signal detector Literature Review.
DavidNameza
 
PDF
Empowering Artisans Through Technology Karmakar App Concept
yellowslice2
 
PPTX
(2) Cell Wall Inhibitors_Cephalosporins others.pptx
mkurdi133
 
PDF
CRAC- Adobe Photoshop CC 2016 (32 64Bit) Crack
utfefguu
 
DOCX
Redefining Master Plans for creating sustainable cities-Jharkhand Conference...
JIT KUMAR GUPTA
 
PDF
The Role of Logos as Identity Shapers (IFIC Logo)
Md. Mehedi Hasan Asif
 
PDF
Case Study on good and bad acoustics in auditorium
Disha Agrawal
 
PPTX
619813902-Fun-friday-Identify-Bollywood-movie-from-dialogues-deliver-the-dial...
in4withme
 
High-Rise Interior Mastery by Top 3D Visualization Experts
Yantram Animation Studio Corporation
 
CompanyReviewTypeOfPowerpointThatIsColor
plukleomarigpuara
 
🔴BUKTI KEMENANGAN HARI INI SELASA 08 JULI 2025 !!!🔴
GRAB
 
SS27 Men's Fashion Trend Book Peclers Paris
Peclers Paris
 
Teaching Learning-1- (New) 2020.pptuuuo
omarekaabed
 
hall ppt 1 it for basic tamolet .pptx
ashishbehera64
 
slidesgo-s-story-of-zara-a-strategi.pptx
Ehsan63
 
Black and Blue Modern Technology Presentation.pdf
hjaders1104
 
Javrhrbthtbryin6trtvrhnberra-without-BlueJ.ppt
jotola6956
 
Town planning is a concept used in architectural design. It plays a very impo...
IshikaPanchal11
 
BMC S6 M3 P1 building mATERIALS AND CONSTRUCTION.pptx
RizwanAlavi
 
Uber Driver Hackday Sprint Solving Ride Cancellations
YellowSlice1
 
Ai Vehicle traffic signal detector Literature Review.
DavidNameza
 
Empowering Artisans Through Technology Karmakar App Concept
yellowslice2
 
(2) Cell Wall Inhibitors_Cephalosporins others.pptx
mkurdi133
 
CRAC- Adobe Photoshop CC 2016 (32 64Bit) Crack
utfefguu
 
Redefining Master Plans for creating sustainable cities-Jharkhand Conference...
JIT KUMAR GUPTA
 
The Role of Logos as Identity Shapers (IFIC Logo)
Md. Mehedi Hasan Asif
 
Case Study on good and bad acoustics in auditorium
Disha Agrawal
 
619813902-Fun-friday-Identify-Bollywood-movie-from-dialogues-deliver-the-dial...
in4withme
 
Ad

CSS Custom Properties (aka CSS Variable)