Search code examples
htmlcsscss-shapes

How to recreate 2020 Google Maps icon's shape without SVG?


I'm trying to recreate Google Maps's icon (2020). The colorful background and the donut hole are easy enough: I just need some gradients and a mask.

Here's a snippet that shows my current efforts (and a codepen, if you want to play with it):

:root {
  --1-3: calc(100% / 3);
  --2-3: calc(100% / 3 * 2);
  --sqrt-2: 1.4142135624;
  
  --hole-diameter: calc(100% / var(--sqrt-2) / 3);
  
  --red: #ea4335;
  --yellow: #fbbc04;
  --green: #34a853;
  --blue: #1a73e8;
  --azure: #4285f4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

#wrapper {
  margin: 3em auto;
  width: 10em;
  background: linear-gradient(90deg, #c0392b, #8e44ad);
}

#icon {
  --mask: radial-gradient(
    circle at center,
    transparent calc(var(--hole-diameter) - 1px),
    #000 calc(var(--hole-diameter) + 1px)
  );
  
  border-radius: 50% 50% 50% 0;
  aspect-ratio: 1 / 1;
  background:
    linear-gradient(
      180deg,
      var(--red) var(--1-3),
      var(--yellow) var(--1-3) var(--2-3),
      var(--green) var(--2-3)
    ),
    linear-gradient(
      180deg,
      var(--blue) var(--1-3),
      var(--azure) var(--1-3) var(--2-3),
      var(--green) var(--2-3)
    ) calc(100% - 1px);
  background-size: 50% 100%;
  background-repeat: no-repeat;
  -webkit-mask: var(--mask);
  mask: var(--mask);
  rotate: -45deg;
}
<div id="wrapper">
  <div id="icon"></div>
</div>

However, I can't wrap my head around its peculiar shape. Is it possible to create such a shape with CSS only?

It should be obvious that I'm not looking for an SVG-based solution. I'm doing this as a pet project, so I just need something that works in at least one browser.


Solution

  • An approximation with one element that should work in all the browsers:

    .logo {
      width: 200px; /* control the size */
      aspect-ratio: .7;
      background:
       linear-gradient(130deg,#0000 53%,#34a853 53.5%),
       conic-gradient(from 40deg at 36% 26%, #4285f4 25%,#fbbc04 0 50%,#ea4335 0 75%, #1a73e8 0);
      -webkit-mask:
        radial-gradient(#000 69%,#0000 71%) 
         bottom/10% 9% no-repeat,
        radial-gradient(92% 173% at 100% 116%,#0000 98%,#000) 
         100% 97%/50% 18% no-repeat,
        radial-gradient(92% 173% at 0%   116%,#0000 98%,#000) 
         0%   97%/50% 18% no-repeat,
        conic-gradient(from -35deg at 50% 90%,#000 70deg,#0000 0)
         bottom/100% 43% no-repeat,
        radial-gradient(#0000 27%,#000 28% 70%,#0000 71%)
         top   /100% 70% no-repeat;
      
      display: inline-block;
    }
    
    html {
      min-height: 100%;
      background: repeating-linear-gradient(-45deg, #fff 0 20px, #f9f9f9 0 40px);
      text-align: center;
    }
    <div class="logo"></div>
    
    <img src="https://upload.wikimedia.org/wikipedia/commons/a/aa/Google_Maps_icon_(2020).svg" width="200">