SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
CSS
Variables
Native reusable
custom properties
#iscss@evalica
● The property is an identifier that defines
which feature is considered
● The value describe how the feature must be
handle by the engine
● A property and value pair is called a
declaration
● Declarations are grouped in blocks
● Each block is preceded by a selector
CSS Syntax
● CSS custom properties (variables)
● Property names that are prefixed with --, like
--example-name, represent custom properties
that contain a value that can be reused
throughout the document using the var()
function
● Are subject to the cascade and inherit their
value from their parent
CSS Variables
CSS Preprocessors
CSS Preprocessing
Variables Variants
CSS Saas LESS CSS Variables
Launched 1996 2006 2009 2012
Author W3C Hampton Catlin Alexis Sellier W3C
Type Native CSS Preprocessor CSS Preprocessor Native
Filename .css .css, .scss, .sass .css, .less .css
Syntax $* @* --*
Runtime static static dynamic
CSS VariablesCSS
a:hover {
color: #150C55;
}
LESS SCSS
:root {
--color: #150C55;
}
a:hover {
color: var(--color);
}
@color: #150C55;
a {
&:hover {
color: @color;
}
}
$color: #150C55;
a {
&:hover {
color: $color;
}
}
Example 1: Scope
http://bit.ly/CSSVar1F
AAnswer :
Sass
$var: 10px;
#id1 {
$var: 12px;
font-size: $var;
}
#id2 {
font-size: $var;
}
LESS
@var: 10px;
#id1 {
@var: 12px;
font-size: @var;
}
#id2 {
font-size: @var;
}
CSS
#id1 {
$var: 12px !global;
}
#id1 {
font-size: 12px;
}
#id2 {
font-size: 10px;
}
#id2 {
font-size: 12px;
}
@var: 12px;
Example 2: Computed value time
http://bit.ly/CSSVar2F
AAnswer :
http://bit.ly/CSSVar3F
BAnswer :
Example 3: Fallback
http://bit.ly/CSSVar4F
Verdana,
sans-serifAnswer :
Example 4: Fallback
BAnswer :
http://bit.ly/CSSVar5F
Example 5: Dynamic Media
Other examples
a:lang(en) {--external-link: "external link";}
a:lang(de) {--external-link: "externer Link";}
a[href^="http"]::after {
content: " (" var(--external-link) ")"
}
:root {
--hue: 247; --saturation: 75%; --lightness: 19%;
--shader: 50%;
--lightLighter: calc( var(--lightness) + var(--shader) );
--satLighter: calc( var(--saturation) - var(--shader) );
--mainColorLighter: hsl( var(--hue), var(--satLighter),
var(--lightLighter) );
}
div {
background: hsla( var(--hue), var(--saturation),
var(--lightness) );
color: var(--mainColorLighter);
}
:root {
--color-1: blue;
color: green;
}
.MyID {
Color: Red;
color: var(--coloR-1);
}
A
B
C
● currentColor was the first CSS Variable
● Are subject to the cascade and inherit their value from their parent
● Can provide one or more fallback value/s
● Are case sensitive
● Are dynamic, can be changed in different scopes and at runtime
● Can be used in combination with calc(), SVG, @media, @keyframes animations, etc.
Conclusions: CSS Variables
Can I use?
CSS Variables
(Custom Properties)
Permits the declaration and usage of
cascading variables in stylesheets
87.73% APR 2018
body {
--bg-color: #150C55;
background-color: pink;
}
@supports (background-color: var(--bg-color)) {
body {
background-color: var(--bg-color);
}
}
Thank you
@evalica #iscss
References
● CSS Custom Properties for Cascading Variables
Module Level 1
● MDN: Custom properties (--*)
● CSS Variables: Why Should You Care?
● The Evolution of CSS
● CSS [Variable] Secrets
● Naming decision
● Difference between types of css variables
● CSS Custom Properties explained
● CSS Variables Performance
● Why I Abandoned @apply
● 6 Preprocessor Features Coming to CSS
Quiz Answers
● Example 1 (Slide 8) — A
● Example 2 (Slide 10) — A
● Example 3 (Slide 11) — B
● Example 4 (Slide 12) — /
● Example 5 (Slide 13) — B

Más contenido relacionado

Similar a CSS Variables — Native reusable custom properties

CSS preprocessor: why and how
CSS preprocessor: why and howCSS preprocessor: why and how
CSS preprocessor: why and howmirahman
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassLucien Lee
 
Deep dive into sass
Deep dive into sassDeep dive into sass
Deep dive into sassKnoldus Inc.
 
Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentationMurat Çakal
 
Simple introduction Sass
Simple introduction SassSimple introduction Sass
Simple introduction SassZeeshan Ahmed
 
LESS(CSS preprocessor)
LESS(CSS preprocessor)LESS(CSS preprocessor)
LESS(CSS preprocessor)VIPIN KUMAR
 
Implementing CSS support for React Native
Implementing CSS support for React NativeImplementing CSS support for React Native
Implementing CSS support for React NativeKristerKari
 
Raleigh Web Design Meetup Group - Sass Presentation
Raleigh Web Design Meetup Group - Sass PresentationRaleigh Web Design Meetup Group - Sass Presentation
Raleigh Web Design Meetup Group - Sass PresentationDaniel Yuschick
 
Introduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and SecurityIntroduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and SecurityMapR Technologies
 
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassBringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassClaudina Sarahe
 
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018Codemotion
 
Finding your way with Sass+Compass
Finding your way with Sass+CompassFinding your way with Sass+Compass
Finding your way with Sass+Compassdrywallbmb
 
Learn Sass and Compass quick
Learn Sass and Compass quickLearn Sass and Compass quick
Learn Sass and Compass quickBilly Shih
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperWynn Netherland
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsKaelig Deloumeau-Prigent
 

Similar a CSS Variables — Native reusable custom properties (20)

CSS preprocessor: why and how
CSS preprocessor: why and howCSS preprocessor: why and how
CSS preprocessor: why and how
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
 
Deep dive into sass
Deep dive into sassDeep dive into sass
Deep dive into sass
 
SASS Lecture
SASS Lecture SASS Lecture
SASS Lecture
 
Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentation
 
Simple introduction Sass
Simple introduction SassSimple introduction Sass
Simple introduction Sass
 
LESS(CSS preprocessor)
LESS(CSS preprocessor)LESS(CSS preprocessor)
LESS(CSS preprocessor)
 
Implementing CSS support for React Native
Implementing CSS support for React NativeImplementing CSS support for React Native
Implementing CSS support for React Native
 
Raleigh Web Design Meetup Group - Sass Presentation
Raleigh Web Design Meetup Group - Sass PresentationRaleigh Web Design Meetup Group - Sass Presentation
Raleigh Web Design Meetup Group - Sass Presentation
 
Advanced sass
Advanced sassAdvanced sass
Advanced sass
 
Introduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and SecurityIntroduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and Security
 
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassBringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
 
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
 
CSS - Basics
CSS - BasicsCSS - Basics
CSS - Basics
 
NoSql Database
NoSql DatabaseNoSql Database
NoSql Database
 
Finding your way with Sass+Compass
Finding your way with Sass+CompassFinding your way with Sass+Compass
Finding your way with Sass+Compass
 
Learn Sass and Compass quick
Learn Sass and Compass quickLearn Sass and Compass quick
Learn Sass and Compass quick
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS Developer
 
Intro to SASS CSS
Intro to SASS CSSIntro to SASS CSS
Intro to SASS CSS
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
 

Más de Ecaterina Moraru (Valica)

UI/UX Tips & Tricks for developers - FOSDEM2020
UI/UX Tips & Tricks for developers - FOSDEM2020UI/UX Tips & Tricks for developers - FOSDEM2020
UI/UX Tips & Tricks for developers - FOSDEM2020Ecaterina Moraru (Valica)
 
Difficulties in having more designers participate in Open Source
Difficulties in having more designers participate in Open SourceDifficulties in having more designers participate in Open Source
Difficulties in having more designers participate in Open SourceEcaterina Moraru (Valica)
 
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...Ecaterina Moraru (Valica)
 
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...Ecaterina Moraru (Valica)
 

Más de Ecaterina Moraru (Valica) (20)

UI/UX Tips & Tricks for developers - FOSDEM2020
UI/UX Tips & Tricks for developers - FOSDEM2020UI/UX Tips & Tricks for developers - FOSDEM2020
UI/UX Tips & Tricks for developers - FOSDEM2020
 
UI/UX Tips & Tricks for developers
UI/UX Tips & Tricks for developersUI/UX Tips & Tricks for developers
UI/UX Tips & Tricks for developers
 
Sketching Session
Sketching SessionSketching Session
Sketching Session
 
CSS Grid vs. Flexbox
CSS Grid vs. FlexboxCSS Grid vs. Flexbox
CSS Grid vs. Flexbox
 
Designing in the open
Designing in the openDesigning in the open
Designing in the open
 
XWiki Skin 10.x+ ideas
XWiki Skin 10.x+ ideasXWiki Skin 10.x+ ideas
XWiki Skin 10.x+ ideas
 
Difficulties in having more designers participate in Open Source
Difficulties in having more designers participate in Open SourceDifficulties in having more designers participate in Open Source
Difficulties in having more designers participate in Open Source
 
Icon Themes
Icon ThemesIcon Themes
Icon Themes
 
Design proposals status 9.x
Design proposals status 9.xDesign proposals status 9.x
Design proposals status 9.x
 
What's new in XWiki 8.x and half of 9.x
What's new in XWiki 8.x and half of 9.x What's new in XWiki 8.x and half of 9.x
What's new in XWiki 8.x and half of 9.x
 
Expectations from Open Source Designers
Expectations from Open Source DesignersExpectations from Open Source Designers
Expectations from Open Source Designers
 
Success stats from OSD community
Success stats from OSD communitySuccess stats from OSD community
Success stats from OSD community
 
Future of XWiki Skins
Future of XWiki SkinsFuture of XWiki Skins
Future of XWiki Skins
 
Design process in an Open Community
Design process in an Open CommunityDesign process in an Open Community
Design process in an Open Community
 
XWiki Usability Testing Sessions
XWiki Usability Testing SessionsXWiki Usability Testing Sessions
XWiki Usability Testing Sessions
 
About XWiki.org
About XWiki.orgAbout XWiki.org
About XWiki.org
 
Evolution of CSS
Evolution of CSSEvolution of CSS
Evolution of CSS
 
XWiki Improvements Review (ver 2.4 - 5.1)
XWiki Improvements Review (ver 2.4 - 5.1)XWiki Improvements Review (ver 2.4 - 5.1)
XWiki Improvements Review (ver 2.4 - 5.1)
 
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...
 
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...
 

Último

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

CSS Variables — Native reusable custom properties

  • 2. ● The property is an identifier that defines which feature is considered ● The value describe how the feature must be handle by the engine ● A property and value pair is called a declaration ● Declarations are grouped in blocks ● Each block is preceded by a selector CSS Syntax
  • 3. ● CSS custom properties (variables) ● Property names that are prefixed with --, like --example-name, represent custom properties that contain a value that can be reused throughout the document using the var() function ● Are subject to the cascade and inherit their value from their parent CSS Variables
  • 6. Variables Variants CSS Saas LESS CSS Variables Launched 1996 2006 2009 2012 Author W3C Hampton Catlin Alexis Sellier W3C Type Native CSS Preprocessor CSS Preprocessor Native Filename .css .css, .scss, .sass .css, .less .css Syntax $* @* --* Runtime static static dynamic
  • 7. CSS VariablesCSS a:hover { color: #150C55; } LESS SCSS :root { --color: #150C55; } a:hover { color: var(--color); } @color: #150C55; a { &:hover { color: @color; } } $color: #150C55; a { &:hover { color: $color; } }
  • 9. Sass $var: 10px; #id1 { $var: 12px; font-size: $var; } #id2 { font-size: $var; } LESS @var: 10px; #id1 { @var: 12px; font-size: @var; } #id2 { font-size: @var; } CSS #id1 { $var: 12px !global; } #id1 { font-size: 12px; } #id2 { font-size: 10px; } #id2 { font-size: 12px; } @var: 12px;
  • 10. Example 2: Computed value time http://bit.ly/CSSVar2F AAnswer :
  • 14. Other examples a:lang(en) {--external-link: "external link";} a:lang(de) {--external-link: "externer Link";} a[href^="http"]::after { content: " (" var(--external-link) ")" } :root { --hue: 247; --saturation: 75%; --lightness: 19%; --shader: 50%; --lightLighter: calc( var(--lightness) + var(--shader) ); --satLighter: calc( var(--saturation) - var(--shader) ); --mainColorLighter: hsl( var(--hue), var(--satLighter), var(--lightLighter) ); } div { background: hsla( var(--hue), var(--saturation), var(--lightness) ); color: var(--mainColorLighter); } :root { --color-1: blue; color: green; } .MyID { Color: Red; color: var(--coloR-1); } A B C
  • 15. ● currentColor was the first CSS Variable ● Are subject to the cascade and inherit their value from their parent ● Can provide one or more fallback value/s ● Are case sensitive ● Are dynamic, can be changed in different scopes and at runtime ● Can be used in combination with calc(), SVG, @media, @keyframes animations, etc. Conclusions: CSS Variables
  • 16. Can I use? CSS Variables (Custom Properties) Permits the declaration and usage of cascading variables in stylesheets 87.73% APR 2018 body { --bg-color: #150C55; background-color: pink; } @supports (background-color: var(--bg-color)) { body { background-color: var(--bg-color); } }
  • 18. References ● CSS Custom Properties for Cascading Variables Module Level 1 ● MDN: Custom properties (--*) ● CSS Variables: Why Should You Care? ● The Evolution of CSS ● CSS [Variable] Secrets ● Naming decision ● Difference between types of css variables ● CSS Custom Properties explained ● CSS Variables Performance ● Why I Abandoned @apply ● 6 Preprocessor Features Coming to CSS
  • 19. Quiz Answers ● Example 1 (Slide 8) — A ● Example 2 (Slide 10) — A ● Example 3 (Slide 11) — B ● Example 4 (Slide 12) — / ● Example 5 (Slide 13) — B