{"id":8570,"date":"2015-04-13T11:00:48","date_gmt":"2015-04-13T16:00:48","guid":{"rendered":"https:\/\/getflywheel.com\/?p=8570"},"modified":"2024-09-29T12:37:40","modified_gmt":"2024-09-29T17:37:40","slug":"color-opacity-rgba-css","status":"publish","type":"resource","link":"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/","title":{"rendered":"How To Control Color Opacity With RGBA in CSS"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When it comes to specifying colors in CSS, the RGB color model has enjoyed immense popularity for many years now. The designer uses a combination of red, green, and blue to achieve the required tone. It\u2019s a rather simple color model that works well.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, the RGB color model offers tones that are flat and solid, nothing else. What if you wanted to set a color and also specify its opacity (or transparency, whichever way you want to put it)? Let\u2019s talk about CSS RGBA colors, an extension of the RGB color model. The A stands for Alpha, which refers to the level of transparency or opacity of the color.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The theory behind the RGB model<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Basically, the RGB color model is used to describe a color purely in terms of red, green, or blue. For pure blue, we will go with 100% blue and 0% of red and green. But for fuchsia, we will use 100% red with 100% blue, and 0% green.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2015\/04\/art1.jpg\" alt=\"RGBA opacity. an artists brush sits on a white paper next to small piles of dry pigment\" class=\"wp-image-9296\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">And if we wanted to create black, basic color theory states that the absence of any color is black. Therefore, we\u2019ll go with 0% of red, green, and blue. So RGB is sort of like mixing watercolors to arrive at a desired shade.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why would you use RGBA?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In CSS3, RGBA is comparable to Layers in Photoshop. RGBA allows you to achieve not just the flat blue or fuchsia or black colors talked about earlier, but also a level of transparency. Think of that transparency as an additional element to use in your design. To be clear, though, CSS already has had an opacity property. You can easily specify the opacity of the entire element and everything contained within it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, RGBA allows you to go beyond that\u2014you can control the opacity of individual colors, rather than the entire element. You have the flexibility to adjust the transparency or opacity of just the background or just the foreground or both, depending on your requirements.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2015\/04\/art2.jpg\" alt=\"RGBA opacity. blue paint pigments are being mixed to create a new hue\" class=\"wp-image-9297\"\/><\/figure>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">How do you use RGBA?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Fortunately, it\u2019s pretty simple to make use of RGBA. First, let\u2019s talk about the syntax. Generally, an RGBA notation looks pretty much like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[code]\nrgba (red, green, blue, alpha)\n[\/code]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Just like RGB, the first three values (red, green, and blue) can either be integers between 0 or 255 or percentages ranging from 0% to 100%. Also just like RGB, these values specify the amount of red, green, and blue in the desired shade. Therefore, the syntax for a pure red should look like:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[code]\nrgba (255, 0, 0, 1);\n[\/code]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">or<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[code]\nrgba (100%, 0%, 0%, 1);\n[\/code]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The fourth value denotes alpha and needs to be between 0.0 (absolute transparency) and 1.0 (absolute opacity). For example, 0.5 would be 50% opacity and 50% transparency.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Is RGBA browser compatible?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Virtually every modern web browser nowadays supports RGBA color model, so there\u2019s not much for you to fear in the way of compatibility. However, we recommend specifying solid RGB colors as a fallback for RGBA. You\u2019ll be on the safe side, but there\u2019s also not much effort involved for the extra step.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/getflywheel-images.s3.us-east-2.amazonaws.com\/uploads\/2015\/04\/art3.jpg\" alt=\"RGBA opacity. different green, yellow, and purple paint swatches in a pile\" class=\"wp-image-9300\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To specify a solid fallback color, I rely on hexadecimal color notations. Take white, for example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[code]\ncolor: #ffffff;\n[\/code]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The above hex code will render a pure opaque white. Now, here\u2019s how I would add 50% opacity to this in RGBA:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[code]\ncolor: rgba(255, 255, 255, 0.5);\n[\/code]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">All done! Again the fallback in hexadecimal is something of a personal practice for me. RGBA has been around since 2011, so basically any web browser released after IE9 can support it. And if hexadecimal isn\u2019t your thing, you can still fall back to RGB from RGBA, using RGB notation itself. In that case, you can specify RGB colors for older browsers and RGBA colors for browsers capable of interpreting them. For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[code]\ncolor: rgb (0, 0, 0);\ncolor: rgba (0, 0, 0, 0.5);\n[\/code]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Of course, if you\u2019re working with a background and transparency is something that you really must have, you also have the option of falling back on a PNG using an alpha channel. I don\u2019t recommend using this method unless you absolutely have to. A PNG background is significantly less flexible than CSS, and you might end up using a separate PNG image for each level of transparency that you require.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, the logic here is simple too: Specify a background using PNG that every browser can comprehend and then overwrite it using the RGBA notation. Here is how:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[code]\nbackground: transparent url (something.png);\nbackground: rgba (0, 0, 0, 0.5) none;\n[\/code]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, the RGBA color model allows you to create graphically rich designs with ease, thanks to its flexibility with precision opacity and transparency. Hopefully, this article will help you use RGBA colors in your projects and designs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;re looking to make <a href=\"https:\/\/wpengine.com\/wordpress-hosting\/\" target=\"_blank\" rel=\"noreferrer noopener\">hosting your WordPress sites<\/a> as easy as your RGBA notations, check our <a href=\"https:\/\/wpengine.com\/plans\/\" target=\"_blank\" rel=\"noreferrer noopener\">WP Engine&#8217;s plans<\/a> to find the one that suits your needs!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When it comes to specifying colors in CSS, the RGB color model has enjoyed immense popularity for many years now. The designer uses a combination of red, green, and blue to achieve the required tone. It\u2019s a rather simple color model that works well. However, the RGB color model offers tones that are flat and<span class=\"tile__ellipses\">&hellip;<\/span><span class=\"tile__ellipses--animated\"><\/span><\/p>\n","protected":false},"author":1,"featured_media":140176,"template":"","resource-topic":[1396],"resource-role":[1397],"resource-type":[916],"class_list":["post-8570","resource","type-resource","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to control color transparency with RGBA in CSS<\/title>\n<meta name=\"description\" content=\"The RGBA color model allows you to create graphically rich designs with ease. This guide can help you learn the basics.\" \/>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to control color transparency with RGBA in CSS\" \/>\n<meta property=\"og:description\" content=\"The RGBA color model allows you to create graphically rich designs with ease. This guide can help you learn the basics.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Engine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/wpengine\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-29T17:37:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2015\/04\/rgb-header.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@wpengine\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/\",\"url\":\"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/\",\"name\":\"How to control color transparency with RGBA in CSS\",\"isPartOf\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\"},\"datePublished\":\"2015-04-13T16:00:48+00:00\",\"dateModified\":\"2024-09-29T17:37:40+00:00\",\"description\":\"The RGBA color model allows you to create graphically rich designs with ease. This guide can help you learn the basics.\",\"breadcrumb\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wpengine.com\/case-studies\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Resources\",\"item\":\"https:\/\/wpengine.com\/case-studies\/resources\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How To Control Color Opacity With RGBA in CSS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\",\"url\":\"https:\/\/wpengine.com\/case-studies\/\",\"name\":\"WP Engine\",\"description\":\"Managed Hosting for WordPress\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/f5301455463371a10d1fc290e9ad0085\",\"name\":\"WP Engine\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g\",\"caption\":\"WP Engine\"},\"sameAs\":[\"https:\/\/wpengine.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to control color transparency with RGBA in CSS","description":"The RGBA color model allows you to create graphically rich designs with ease. This guide can help you learn the basics.","robots":{"index":"noindex","follow":"follow"},"og_locale":"en_US","og_type":"article","og_title":"How to control color transparency with RGBA in CSS","og_description":"The RGBA color model allows you to create graphically rich designs with ease. This guide can help you learn the basics.","og_url":"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/","og_site_name":"WP Engine","article_publisher":"https:\/\/www.facebook.com\/wpengine","article_modified_time":"2024-09-29T17:37:40+00:00","og_image":[{"width":1100,"height":500,"url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2015\/04\/rgb-header.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@wpengine","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/","url":"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/","name":"How to control color transparency with RGBA in CSS","isPartOf":{"@id":"https:\/\/wpengine.com\/case-studies\/#website"},"datePublished":"2015-04-13T16:00:48+00:00","dateModified":"2024-09-29T17:37:40+00:00","description":"The RGBA color model allows you to create graphically rich designs with ease. This guide can help you learn the basics.","breadcrumb":{"@id":"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wpengine.com\/case-studies\/resources\/color-opacity-rgba-css\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wpengine.com\/case-studies\/"},{"@type":"ListItem","position":2,"name":"Resources","item":"https:\/\/wpengine.com\/case-studies\/resources\/"},{"@type":"ListItem","position":3,"name":"How To Control Color Opacity With RGBA in CSS"}]},{"@type":"WebSite","@id":"https:\/\/wpengine.com\/case-studies\/#website","url":"https:\/\/wpengine.com\/case-studies\/","name":"WP Engine","description":"Managed Hosting for WordPress","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/f5301455463371a10d1fc290e9ad0085","name":"WP Engine","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d8770fe9625ca7c4601f13d9d0ab86565a6dac8cd6a77bfe2ada6d83c6837870?s=96&d=mm&r=g","caption":"WP Engine"},"sameAs":["https:\/\/wpengine.com"]}]}},"acf":[],"grid_image_url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2015\/04\/rgb-grid.png","media-type":{"term_id":916,"name":"Article","slug":"article"},"role":"<strong>Roles:<\/strong> Designer","topic":"<strong>Topics:<\/strong> Design","_links":{"self":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource\/8570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource"}],"about":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/types\/resource"}],"author":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/users\/1"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media\/140176"}],"wp:attachment":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media?parent=8570"}],"wp:term":[{"taxonomy":"resource-topic","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-topic?post=8570"},{"taxonomy":"resource-role","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-role?post=8570"},{"taxonomy":"resource-type","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-type?post=8570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}