SlideShare a Scribd company logo
1 of 25
Colors in CSS3
  A presentation by Lea Verou
Color formats in CSS2
•   Hex format – #RRGGBB
•   Shorthand hex format - #RGB
•   rgb() format – rgb(red, green, blue)
•   Named colors – white, black, beige etc
New color formats in CSS3
•   HSL – hsl(hue, saturation, lightness)
•   CMYK – cmyk(cyan, magenta, yellow, black)
•   HSLA – hsl(hue, saturation, lightness, alpha)
•   RGBA – rgba(red, green, blue, alpha)
HSL
• HSL stands for Hue, Saturation, Lightness.
• A format that is easier for humans to
  understand and manipulate.
• HSL makes it much easier to create color
  palettes: You just use a color picker for the
  basic colors of the palette and not for the
  lighter/darker variants.
CMYK
• CMYK stands for Cyan, Magenta, Yellow, blacK
• Easier for most people to understand and
  manipulate.
• Easier to produce good-looking colors
• Allows us to define precisely how our colors will
  get printed
• Graphic designers are already accustomed to it so
  it will be easier for them to switch to Web design
• Smaller color gamut than RGB
• Not supported yet by any browser 
RGBA and HSLA
• RGBA and HSLA allow for a fourth parameter –
  Alpha.
• Alpha defines the transparency of the color –
  where 1 is fully opaque and 0 is fully
  transparent.
• This brings a revolution in web design that
  many designers are still unaware of.
Isn’t opacity enough?
• No! Opacity is very useful but it’s not enough
• Opacity allows us to make the whole
  container semi-transparent, including it's
  contents
• RGBA/HSLA allow us to make only the
  border/background/text color/etc semi
  transparent which opens up great possibilities
  in web design
Isn’t opacity enough? Example
Browser support for
             RGBA/HSLA/HSL
•   Mozilla Firefox 3+
•   Opera 10+ (still in Alpha)
•   Apple Safari 3+
•   Google Chrome
RGBA backgrounds: workarounds
• RGBA backgrounds are the easiest ones for
  compatibility workarounds.
• They are based on the fact that if a browser
  doesn’t understand RGBA, it ignores the
  declaration that contains RGBA values
  completely.
• They are used like this:
  /* Workarounds here */
  background: rgba(255,0,80,0.5);
• Important! The declaration that contains the
  RGBA value should always come after the
  workarounds.
RGBA backgrounds: workarounds
• IE gradient filter
• 1x1 png images:
   – As external files
   – Embedded in the CSS via Data URIs
Workaround for IE: Gradient filter
• IE supports a proprietary “extended hex” format in the
  parameters of some of it’s filters.
• In that format the Alpha parameter is converted to the range
  00-FF and concatenated in front of a normal hex value, which
  results to #AARRGGBB
• We can use the gradient filter to simulate RGBA backgrounds
  for IE, which looks like this:
  filter:progid:DXImageTransform.Microsoft.grad
  ient(startColorstr=#CC000000, endColorstr=#CC
  000000);
  That's equivalent to: background:rgba(0,0,0,0.8);
Problems with the filter workaround

• Filters make the text aliased:
Problems with the filter workaround

Filters are lengthy and add lots of non-standard clutter in
our CSS:
-ms-filter:quot;progid:DXImageTransform.Microsoft.grad
ient(startColorstr=#CC000000, endColorstr=#CC000000)
quot;; /* For IE8 beta */
filter:progid:DXImageTransform.Microsoft.gradient(st
artColorstr=#CC000000, endColorstr=#CC000000);
zoom:1; /* To give the element “layout” */


O_o!!
Problems with the
filter workaround

Doesn't play along
well with other
workarounds, since it
doesn't modify the
background of the
element.
More problems with the filter
           workaround
• Filters are slow
• Filters are only for IE. What about Firefox 2-
  , Opera 9.6-?
• To use that method, RGBA values need to be
  converted to hex values. Too much of a hassle.
PNGs via Data URIs
• Data URIs allow us to embed a file inside our
  CSS
• They look like this:
  background: url(data:image/png;base64,
  iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAA
  fFcSJAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/w
  D/oL2nkwAAAA1JREFUCNdjYGBgOAMAANEAzdAP7
  DMAAAAASUVORK5CYII=);
Disadvantages of Data URIs
• IE7- doesn’t support Data URIs, so if we use
  them, the filter method and all it’s
  disadvantages should be used as well in order
  to support IE7-.
• Not easily changeable, you will need a
  converter of some sort to change the color
  even a little bit.
• Clutter in our CSS file. Lots of clutter!
• The image itself cannot be cached.
Advantages of Data URIs
• Less external http requests = faster website
• The png image loads instantly, since it’s
  embedded in the CSS file. Not a single glimpse
  of containers without backgrounds!
External png images
• You don’t need to create them yourself, let PHP do
  the hard work!
• You can find a script of mine that does exactly that
  here: http://leaverou.me/2009/02/bulletproof-
  cross-browser-rgba-backgrounds/
• It’s used like this:
  background: url(rgba.php?r=255&g=0&b=80&a=50);
  or
  background: url(rgba.php?name=white&a=50);
RGBA/HSLA in other CSS
           properties
• RGBA/HSLA is not only useful for
  backgrounds! Backgrounds are just the easiest
  to workaround and the most frequently
  needed to.
• For solid borders, you can use 2 containers
  with an appropriate padding and background.
• For text color, in most cases opacity (or the
  alpha filter for IE) is sufficient.
Detect RGBA via JavaScript
• Try to assign an RGBA value to a CSS property
  that accepts color values (e.g.
  color, background-color, border-color etc) on
  any element .
• If the browser is not RGBA capable, it will do
  nothing, and may also throw an error (IE)
• Otherwise the value will be applied
RGBA detection: code
function supportsRGBA() {
    var elem = document.getElementsByTagName('script')[0],
       prevColor = elem.style.color;
    try {
       elem.style.color = 'rgba(1,5,13,0.44)';
    } catch(e) {}
    var result = elem.style.color != prevColor;
    elem.style.color = prevColor;
    return result;
}
RGBA detection: improvements
• Performance: Cache the result
• Accuracy: What happens if the element
  already has that rgba color?
• Completeness: We can detect HSL, HSLA and
  CMYK in the exact same way.
Thank you!
You can find me at:
• http://leaverou.me
• http://twitter.com/LeaVerou
• leaverou@fresset.gr

More Related Content

What's hot

CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations Rob LaPlaca
 
Web development with Python
Web development with PythonWeb development with Python
Web development with PythonRaman Balyan
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation Salman Memon
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptFahim Abdullah
 
Web Development with HTML5, CSS3 & JavaScript
Web Development with HTML5, CSS3 & JavaScriptWeb Development with HTML5, CSS3 & JavaScript
Web Development with HTML5, CSS3 & JavaScriptEdureka!
 
data structures and its importance
 data structures and its importance  data structures and its importance
data structures and its importance Anaya Zafar
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5Gil Fink
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest pathArafat Hossan
 
HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!Ana Cidre
 
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxKADAMBARIPUROHIT
 
HTML5 - Insert images and Apply page backgrounds
HTML5 - Insert images and Apply page backgroundsHTML5 - Insert images and Apply page backgrounds
HTML5 - Insert images and Apply page backgroundsGrayzon Gonzales, LPT
 

What's hot (20)

Unit 2 dhtml
Unit 2 dhtmlUnit 2 dhtml
Unit 2 dhtml
 
Intro to html 5
Intro to html 5Intro to html 5
Intro to html 5
 
CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
Web development with Python
Web development with PythonWeb development with Python
Web development with Python
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
CSS for Beginners
CSS for BeginnersCSS for Beginners
CSS for Beginners
 
Html media
Html mediaHtml media
Html media
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
Web Development with HTML5, CSS3 & JavaScript
Web Development with HTML5, CSS3 & JavaScriptWeb Development with HTML5, CSS3 & JavaScript
Web Development with HTML5, CSS3 & JavaScript
 
data structures and its importance
 data structures and its importance  data structures and its importance
data structures and its importance
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
All pair shortest path
All pair shortest pathAll pair shortest path
All pair shortest path
 
HTML and CSS crash course!
HTML and CSS crash course!HTML and CSS crash course!
HTML and CSS crash course!
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Html n CSS
Html n CSSHtml n CSS
Html n CSS
 
Introduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptxIntroduction to HTML+CSS+Javascript.pptx
Introduction to HTML+CSS+Javascript.pptx
 
Plot function in R
Plot function in RPlot function in R
Plot function in R
 
HTML5 - Insert images and Apply page backgrounds
HTML5 - Insert images and Apply page backgroundsHTML5 - Insert images and Apply page backgrounds
HTML5 - Insert images and Apply page backgrounds
 

Viewers also liked

Social Networks Ev.Liotzis
Social Networks Ev.LiotzisSocial Networks Ev.Liotzis
Social Networks Ev.Liotzisguest5e75c
 
Turning to the client side
Turning to the client sideTurning to the client side
Turning to the client sideLea Verou
 
Google Application Engine
Google Application EngineGoogle Application Engine
Google Application Engineguestd77e8ae
 
Antonis Plessas Podcamp Music Use Licencing
Antonis Plessas Podcamp Music Use LicencingAntonis Plessas Podcamp Music Use Licencing
Antonis Plessas Podcamp Music Use LicencingAntonios Plessas
 
Drupal Introduction
Drupal IntroductionDrupal Introduction
Drupal IntroductionPanos Ladas
 
Rain Up Mc Presentation
Rain Up Mc PresentationRain Up Mc Presentation
Rain Up Mc Presentationguest1c3c761
 
Metodologias de Design de Interação
Metodologias de Design de InteraçãoMetodologias de Design de Interação
Metodologias de Design de InteraçãoUTFPR
 
Mastering CSS3 gradients
Mastering CSS3 gradientsMastering CSS3 gradients
Mastering CSS3 gradientsLea Verou
 
Drupal 6 Theming using the Zen Theme
Drupal 6 Theming using the Zen ThemeDrupal 6 Theming using the Zen Theme
Drupal 6 Theming using the Zen Themeinfowonders
 

Viewers also liked (14)

Social Networks Ev.Liotzis
Social Networks Ev.LiotzisSocial Networks Ev.Liotzis
Social Networks Ev.Liotzis
 
Turning to the client side
Turning to the client sideTurning to the client side
Turning to the client side
 
Google Application Engine
Google Application EngineGoogle Application Engine
Google Application Engine
 
Kapou Gr
Kapou GrKapou Gr
Kapou Gr
 
Azure
AzureAzure
Azure
 
Antonis Plessas Podcamp Music Use Licencing
Antonis Plessas Podcamp Music Use LicencingAntonis Plessas Podcamp Music Use Licencing
Antonis Plessas Podcamp Music Use Licencing
 
Drupal Introduction
Drupal IntroductionDrupal Introduction
Drupal Introduction
 
Programming Humans
Programming HumansProgramming Humans
Programming Humans
 
Rain Up Mc Presentation
Rain Up Mc PresentationRain Up Mc Presentation
Rain Up Mc Presentation
 
Metodologias de Design de Interação
Metodologias de Design de InteraçãoMetodologias de Design de Interação
Metodologias de Design de Interação
 
Mastering CSS3 gradients
Mastering CSS3 gradientsMastering CSS3 gradients
Mastering CSS3 gradients
 
Object Oriented CSS
Object Oriented CSSObject Oriented CSS
Object Oriented CSS
 
Drupal 6 Theming using the Zen Theme
Drupal 6 Theming using the Zen ThemeDrupal 6 Theming using the Zen Theme
Drupal 6 Theming using the Zen Theme
 
Intro to HTML 5 / CSS 3
Intro to HTML 5 / CSS 3Intro to HTML 5 / CSS 3
Intro to HTML 5 / CSS 3
 

Similar to Colors In CSS3

Photo echance. Problems. Solutions. Ideas
Photo echance. Problems. Solutions. Ideas Photo echance. Problems. Solutions. Ideas
Photo echance. Problems. Solutions. Ideas Andrew Nikishaev
 
css trasition explanation about our project
css trasition explanation about our projectcss trasition explanation about our project
css trasition explanation about our projectDivPatel17
 
Web Design Workshop
Web Design WorkshopWeb Design Workshop
Web Design WorkshopSuseZ
 
app/assets/stylesheets - How to not make a mess
app/assets/stylesheets - How to not make a messapp/assets/stylesheets - How to not make a mess
app/assets/stylesheets - How to not make a messjasnow
 
CSSO – compress CSS (english version)
CSSO – compress CSS (english version)CSSO – compress CSS (english version)
CSSO – compress CSS (english version)Roman Dvornov
 
CSS3: Ripe and Ready
CSS3: Ripe and ReadyCSS3: Ripe and Ready
CSS3: Ripe and ReadyDenise Jacobs
 
Y Pipes Mashup Camp
Y Pipes Mashup CampY Pipes Mashup Camp
Y Pipes Mashup CampJinho Jung
 
Write LESS. DO more.
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.Eugene Nor
 
HTML5 and CSS3 for Teachers
HTML5 and CSS3 for TeachersHTML5 and CSS3 for Teachers
HTML5 and CSS3 for TeachersJason Hando
 
CSS Less framework overview, Pros and Cons
CSS Less framework overview, Pros and ConsCSS Less framework overview, Pros and Cons
CSS Less framework overview, Pros and ConsSanjoy Kr. Paul
 

Similar to Colors In CSS3 (20)

Photo echance. Problems. Solutions. Ideas
Photo echance. Problems. Solutions. Ideas Photo echance. Problems. Solutions. Ideas
Photo echance. Problems. Solutions. Ideas
 
Css3 color
Css3 colorCss3 color
Css3 color
 
Css3 color
Css3 colorCss3 color
Css3 color
 
css trasition explanation about our project
css trasition explanation about our projectcss trasition explanation about our project
css trasition explanation about our project
 
Web Design Workshop
Web Design WorkshopWeb Design Workshop
Web Design Workshop
 
Css gradients
Css gradientsCss gradients
Css gradients
 
Professional Css
Professional CssProfessional Css
Professional Css
 
app/assets/stylesheets - How to not make a mess
app/assets/stylesheets - How to not make a messapp/assets/stylesheets - How to not make a mess
app/assets/stylesheets - How to not make a mess
 
Artdm171 Week6 Images
Artdm171 Week6 ImagesArtdm171 Week6 Images
Artdm171 Week6 Images
 
CSSO – compress CSS (english version)
CSSO – compress CSS (english version)CSSO – compress CSS (english version)
CSSO – compress CSS (english version)
 
CSS3: Ripe and Ready
CSS3: Ripe and ReadyCSS3: Ripe and Ready
CSS3: Ripe and Ready
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
PNGHack 1.0 Presentation
PNGHack 1.0 PresentationPNGHack 1.0 Presentation
PNGHack 1.0 Presentation
 
Y Pipes Mashup Camp
Y Pipes Mashup CampY Pipes Mashup Camp
Y Pipes Mashup Camp
 
Write LESS. DO more.
Write LESS. DO more.Write LESS. DO more.
Write LESS. DO more.
 
HTML5 and CSS3 for Teachers
HTML5 and CSS3 for TeachersHTML5 and CSS3 for Teachers
HTML5 and CSS3 for Teachers
 
pastel
pastelpastel
pastel
 
pastel
pastelpastel
pastel
 
CSS Less framework overview, Pros and Cons
CSS Less framework overview, Pros and ConsCSS Less framework overview, Pros and Cons
CSS Less framework overview, Pros and Cons
 
Tools for Modern Web Design
Tools for Modern Web DesignTools for Modern Web Design
Tools for Modern Web Design
 

Recently uploaded

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
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
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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 SavingEdi Saputra
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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 FMESafe Software
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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, ...apidays
 
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 TerraformAndrey Devyatkin
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
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
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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, ...
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Colors In CSS3

  • 1. Colors in CSS3 A presentation by Lea Verou
  • 2. Color formats in CSS2 • Hex format – #RRGGBB • Shorthand hex format - #RGB • rgb() format – rgb(red, green, blue) • Named colors – white, black, beige etc
  • 3. New color formats in CSS3 • HSL – hsl(hue, saturation, lightness) • CMYK – cmyk(cyan, magenta, yellow, black) • HSLA – hsl(hue, saturation, lightness, alpha) • RGBA – rgba(red, green, blue, alpha)
  • 4. HSL • HSL stands for Hue, Saturation, Lightness. • A format that is easier for humans to understand and manipulate. • HSL makes it much easier to create color palettes: You just use a color picker for the basic colors of the palette and not for the lighter/darker variants.
  • 5. CMYK • CMYK stands for Cyan, Magenta, Yellow, blacK • Easier for most people to understand and manipulate. • Easier to produce good-looking colors • Allows us to define precisely how our colors will get printed • Graphic designers are already accustomed to it so it will be easier for them to switch to Web design • Smaller color gamut than RGB • Not supported yet by any browser 
  • 6. RGBA and HSLA • RGBA and HSLA allow for a fourth parameter – Alpha. • Alpha defines the transparency of the color – where 1 is fully opaque and 0 is fully transparent. • This brings a revolution in web design that many designers are still unaware of.
  • 7. Isn’t opacity enough? • No! Opacity is very useful but it’s not enough • Opacity allows us to make the whole container semi-transparent, including it's contents • RGBA/HSLA allow us to make only the border/background/text color/etc semi transparent which opens up great possibilities in web design
  • 9. Browser support for RGBA/HSLA/HSL • Mozilla Firefox 3+ • Opera 10+ (still in Alpha) • Apple Safari 3+ • Google Chrome
  • 10. RGBA backgrounds: workarounds • RGBA backgrounds are the easiest ones for compatibility workarounds. • They are based on the fact that if a browser doesn’t understand RGBA, it ignores the declaration that contains RGBA values completely. • They are used like this: /* Workarounds here */ background: rgba(255,0,80,0.5); • Important! The declaration that contains the RGBA value should always come after the workarounds.
  • 11. RGBA backgrounds: workarounds • IE gradient filter • 1x1 png images: – As external files – Embedded in the CSS via Data URIs
  • 12. Workaround for IE: Gradient filter • IE supports a proprietary “extended hex” format in the parameters of some of it’s filters. • In that format the Alpha parameter is converted to the range 00-FF and concatenated in front of a normal hex value, which results to #AARRGGBB • We can use the gradient filter to simulate RGBA backgrounds for IE, which looks like this: filter:progid:DXImageTransform.Microsoft.grad ient(startColorstr=#CC000000, endColorstr=#CC 000000); That's equivalent to: background:rgba(0,0,0,0.8);
  • 13. Problems with the filter workaround • Filters make the text aliased:
  • 14. Problems with the filter workaround Filters are lengthy and add lots of non-standard clutter in our CSS: -ms-filter:quot;progid:DXImageTransform.Microsoft.grad ient(startColorstr=#CC000000, endColorstr=#CC000000) quot;; /* For IE8 beta */ filter:progid:DXImageTransform.Microsoft.gradient(st artColorstr=#CC000000, endColorstr=#CC000000); zoom:1; /* To give the element “layout” */ O_o!!
  • 15. Problems with the filter workaround Doesn't play along well with other workarounds, since it doesn't modify the background of the element.
  • 16. More problems with the filter workaround • Filters are slow • Filters are only for IE. What about Firefox 2- , Opera 9.6-? • To use that method, RGBA values need to be converted to hex values. Too much of a hassle.
  • 17. PNGs via Data URIs • Data URIs allow us to embed a file inside our CSS • They look like this: background: url(data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAA fFcSJAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/w D/oL2nkwAAAA1JREFUCNdjYGBgOAMAANEAzdAP7 DMAAAAASUVORK5CYII=);
  • 18. Disadvantages of Data URIs • IE7- doesn’t support Data URIs, so if we use them, the filter method and all it’s disadvantages should be used as well in order to support IE7-. • Not easily changeable, you will need a converter of some sort to change the color even a little bit. • Clutter in our CSS file. Lots of clutter! • The image itself cannot be cached.
  • 19. Advantages of Data URIs • Less external http requests = faster website • The png image loads instantly, since it’s embedded in the CSS file. Not a single glimpse of containers without backgrounds!
  • 20. External png images • You don’t need to create them yourself, let PHP do the hard work! • You can find a script of mine that does exactly that here: http://leaverou.me/2009/02/bulletproof- cross-browser-rgba-backgrounds/ • It’s used like this: background: url(rgba.php?r=255&g=0&b=80&a=50); or background: url(rgba.php?name=white&a=50);
  • 21. RGBA/HSLA in other CSS properties • RGBA/HSLA is not only useful for backgrounds! Backgrounds are just the easiest to workaround and the most frequently needed to. • For solid borders, you can use 2 containers with an appropriate padding and background. • For text color, in most cases opacity (or the alpha filter for IE) is sufficient.
  • 22. Detect RGBA via JavaScript • Try to assign an RGBA value to a CSS property that accepts color values (e.g. color, background-color, border-color etc) on any element . • If the browser is not RGBA capable, it will do nothing, and may also throw an error (IE) • Otherwise the value will be applied
  • 23. RGBA detection: code function supportsRGBA() { var elem = document.getElementsByTagName('script')[0], prevColor = elem.style.color; try { elem.style.color = 'rgba(1,5,13,0.44)'; } catch(e) {} var result = elem.style.color != prevColor; elem.style.color = prevColor; return result; }
  • 24. RGBA detection: improvements • Performance: Cache the result • Accuracy: What happens if the element already has that rgba color? • Completeness: We can detect HSL, HSLA and CMYK in the exact same way.
  • 25. Thank you! You can find me at: • http://leaverou.me • http://twitter.com/LeaVerou • leaverou@fresset.gr