“CSS Custom Properties” — @geoffreycrofte 2
Geoffrey Crofte
geoffrey.crofte.fr/en
creativejuiz.fr/en
Lead Designer at Foyer Group
@geoffreycrofte
Slide 3
Slide 3 text
“CSS Custom Properties” — @geoffreycrofte
Overview
What are Custom Properties?
Quick start with CSS Variables.
Why CSS C.P. instead of Sass variables?
Use cases & Demos
Takeaways
Slide 4
Slide 4 text
What are Custom Properties?
Slide 5
Slide 5 text
What are Custom Properties?
CSS Variables
IIIIIIII
Slide 6
Slide 6 text
$color: #bada55;
@color: #bada55;
This not about…
Slide 7
Slide 7 text
This is more about…
http://bit.ly/csscurrentcolor
Slide 8
Slide 8 text
This is more about…
http://bit.ly/csscurrentcolor
Slide 9
Slide 9 text
currentColor
But this is not about…
Slide 10
Slide 10 text
“CSS Custom Properties” — @geoffreycrofte
A custom property is any
property whose name starts
with two dashes […] like --foo
Slide 11
Slide 11 text
“CSS Custom Properties” — @geoffreycrofte
Custom properties are solely for
use by authors and users; CSS
will never give them a meaning
beyond what is presented here.
Slide 12
Slide 12 text
“CSS Custom Properties” — @geoffreycrofte
Custom properties are solely for
use by authors and users; CSS
will never give them a meaning
beyond what is presented here.
Slide 13
Slide 13 text
No content
Slide 14
Slide 14 text
Custom properties define variables
Variables are referenced with the var() notation
They are Case-Sensitive
Their value is “extremely permissive”
What the Spec says…
property: var(--variableName);
.element {
}
CSS Use
Slide 20
Slide 20 text
Quick Example of use
Slide 21
Slide 21 text
Why CSS instead of Sass Variables?
Slide 22
Slide 22 text
The main issue with Sass (or LESS) variables:
They have to be computed to get their value.
Computation
Slide 23
Slide 23 text
CSS Variables are alive
Slide 24
Slide 24 text
CSS Variables are alive
Slide 25
Slide 25 text
JavaScript can access them
Slide 26
Slide 26 text
Media Queries ❤ CSS Variables
Slide 27
Slide 27 text
Media Queries ❤ CSS Variables
Slide 28
Slide 28 text
CSS Variables are inherited
Slide 29
Slide 29 text
CSS Variables are inherited
Slide 30
Slide 30 text
CSS Variables are inherited
Slide 31
Slide 31 text
CSS Variables are inherited
Slide 32
Slide 32 text
CSS Variables are inherited
Slide 33
Slide 33 text
CSS Variables are inherited
Slide 34
Slide 34 text
Demos & Use Cases
Slide 35
Slide 35 text
http://bit.ly/cssvargradient
Slide 36
Slide 36 text
http://bit.ly/cssvargradient
Slide 37
Slide 37 text
Mouse position
Slide 38
Slide 38 text
CSS Transformation
Slide 39
Slide 39 text
CSS Transformation
Slide 40
Slide 40 text
CSS Transformation
Slide 41
Slide 41 text
CSS Transformation
Slide 42
Slide 42 text
CSS Transformation
Slide 43
Slide 43 text
CSS Transformation
Slide 44
Slide 44 text
CSS Transformation
Slide 45
Slide 45 text
Why not pushing transformations directly in JavaScript?
Now you’re wondering…
Slide 46
Slide 46 text
Why not pushing transformations directly in JavaScript?
Now you’re wondering…
Slide 47
Slide 47 text
Why not pushing transformations directly in JavaScript?
Now you’re wondering…
Maintainability / Portability
style=“transform…” is dirty. Period.
Slide 48
Slide 48 text
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.
Slide 49
Slide 49 text
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.
Slide 50
Slide 50 text
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.