SlideShare uma empresa Scribd logo
1 de 19
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante 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 how
mirahman
 
Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentation
Murat Çakal
 
Simple introduction Sass
Simple introduction SassSimple introduction Sass
Simple introduction Sass
Zeeshan Ahmed
 
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
Kaelig Deloumeau-Prigent
 

Semelhante 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
 

Mais de Ecaterina Moraru (Valica)

Expectations from Open Source Designers
Expectations from Open Source DesignersExpectations from Open Source Designers
Expectations from Open Source Designers
Ecaterina 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)
 

Mais 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

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
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
panagenda
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 

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