CSS WG Invited Expert
author (ETA Q4 2014)
PhD
candidate
-webkit-font-smoothing: subpixel-antialiased;
-webkit-font-smoothing: antialiased; /* greyscale anti-aliasing */
-webkit-font-smoothing: none; /* NO anti-aliasing! */
-moz-osx-font-smoothing: grayscale;
-moz-osx-font-smoothing: auto; /* subpixel anti-aliasing */
Please, avoid.
No, really.
= 28 states
= 256 states
= 0-255 range
= 24 bits per pixel
= 3 bytes per pixel
(in uncompressed images)
= 256³ possible colors
=
Red: 255
Green: 0
Blue: 90
#rrggbb
Confusing and cryptic >:(rgb()
Better, but still confusing :/#rgb
Shorter, but still confusing :/orange
named color Are you kidding me?!function Color(rgba) {
if (!(this instanceof Color)) return new Color(rgba);
this.rgba = rgba || [0,0,0,1];
};
Color.prototype = {
get rgb () { return this.rgba.slice(0,3) },
set rgb(arr) {
this.rgba = arr.concat(this.alpha);
}
get alpha () { return this.rgba[3] },
set alpha (a) { this.rgba[3] = a }
}
var magenta = new Color([255, 0, 127, 1]);
var magenta = new Color();
magenta.rgb = [255, 0, 127];
// Example method
Color.prototype.invert = function () {
this.rgb = this.rgb.map(function(c) {
return 255 - c;
});
};
multiply: function(dest) { this.rgb = this.rgb.map(function(c,i) {
return 255 * (this.rgb[i]/255) * (dest.rgb[i]/255);
}); }
var red = Color([255,0,0]), blue = Color([0,0,255]); red.multiply(blue);
// -> black
A color space has
when the perceptual similarity of two colors
is measured by the distance between them.
RGB is not perceptually uniform.
Neither is HSL, as it’s just a transformation of RGB.
el.style.background = color;
el.style.color = color.lightness > 50?
'black' : 'white';
get lightness () {
var max = Math.max.apply(Math, this.rgb),
min = Math.min.apply(Math, this.rgb);
return Math.round((min + max)/2.55/2);
}
get luminance () { // Formula from WCAG 2.0
var rgb = this.rgb.map(function(c){
c /= 255; // to 0-1 range
return c < .03928 ?
c / 12.92 :
Math.pow((c+.055)/1.055, 2.4);
});
return 21.26 * rgb[0] + // red
71.52 * rgb[1] + // green
7.22 * rgb[2]; // blue
}
Color.prototype.contrast = function(color) {
var l1 = this.luminance;
var l2 = color.luminance;
var ret = (l1 + .05) / (l2 + .05);
return ret < 1? 1 / ret : ret;
};
hsl()
Better, but not great :/rgba()
and hsla()
Badly needed :)currentColor
Cool, but limited :)
gray()
with SASS@function gray($l, $alpha: 1) {
@return rgba($l, $l, $l, $alpha);
}
background: gray(50%); /* → #7f7f7f */
background: gray(255, .2);
/* → rgba(255, 255, 255, 0.2); */
@function hwb($hue, $w, $b) {
$base: hsl($hue, 100%, 50%);
@return $base * (1 - ($w + $b)/100%)
+ 255*$w/100%;
}
body {
background: hwb(335, 20%, 20%); // #cc3372
}
@function hwb($hue, $w, $b) {
$base: hsl($hue, 100%, 50%);
@if ($w + $b > 100%) {
$factor: 100%/($w + $b);
$w: $w * $factor;
$b: $b * $factor;
}
@return $base * (1 - ($w + $b)/100%)
+ 255*$w/100%;
}
red
green
blue
alpha
rgb
hue
h
saturation
s
lightness
l
whiteness
w
blackness
b
tint
shade
blend
blenda
contrast
@function tint($color, $amount) {
@return mix(white, $color, $amount);
}
@function shade($color, $amount) {
@return mix(black, $color, $amount);
}
background: tint(red, 10%); /* → #ff1919 */
background: shade(red, 10%); /* → #e50000 */
Note: tint()
& shade()
are already included in Bourbon
gray()
#rgba
and #rrggbbaa
hwb()
color()
<angle>
in hsl()
rgb()
and hsl()
will accept alpha values