Subscribe

CSS Logos: Instagram logo

โœ๏ธ

Let's recreate the Instagram logo in CSS

18 Jun, 2022 ยท 4 min read

Iโ€™m pretty sure everyone has seen this one before, the Instagram logo.

For reference, itโ€™s the modern one that looks like this:

Instagram logo

Iโ€™ll be honest that the logo looked way easier to create than it was.

You might wonder whatโ€™s so tricky about it? And itโ€™s all in the background, youโ€™ll see that even my version is not perfect, but every sample image out on the internet has a different background gradient.

When you look closely, you see itโ€™s not one particular gradient. Itโ€™s kind of overlapping gradients.

Letโ€™s dive into it, and Iโ€™ll show you how I created my version.

I make it extra challenging by only using one div and doing everything from that one element.

<div class="instagram"></div>

Letโ€™s start by setting some variables weโ€™ll use.

:root {
  --size: 50vmin;
  --white: #fff;
  --blue: #3051f1;
  --purple: #c92bb7;
  --red: #f73344;
  --orange: #fa8e37;
  --yellow: #fcdf8f;
  --yellow_to: #fbd377;
}

Then letโ€™s move to creating the basic outline of the box. Iโ€™ll use em units as they allow for better scaling of the borders.

.instagram {
  font-size: var(--size);
  width: 1em;
  aspect-ratio: 1;
  border-radius: 0.2em;
  background: var(--purple);
}

Iโ€™ve temporarily set the background to purple so you can see what we have so far.

Instagram logo outline shape

Now letโ€™s dive into these gradients. Itโ€™s a bit tricky as there is an overlapping gradient.

Luckily for us, CSS gradients allow for multiple instances that can overlap in one background. For example, this is valid code:

background: linear-gradient(45deg, blue, transparent), radial-gradient(red, transparent);

This would give us something like this:

CSS overlapping gradients

Now letโ€™s see how we can start. I decided to start with the blue/purple background gradient.

linear-gradient(145deg, var(--blue) 10%, var(--purple) 70%)

This result in the following output.

CSS linear gradient

Now the tricky part is to have the yellow, orange, and red gradients overlap. To achieve that, we must ensure that the gradient sits on top of the linear one we just created.

background: radial-gradient(
    circle farthest-corner at 28% 100%,
    var(--yellow) 0%,
    var(--yellow_to) 10%,
    var(--orange) 22%,
    var(--red) 35%,
    transparent 65%
  ), linear-gradient(145deg, var(--blue) 10%, var(--purple) 70%);

With this in place, we should get the following result.

Stacked gradients in CSS

And thatโ€™s it, to me, that looks super close to the actual logo.

Note: You could enhance this by using multiple radial gradients stacked on top of each other.

The next thing we need is the camera outline icon, and since we are out of elements, we have to use the :before and :after selector again.

Letโ€™s start with the outline.

.instagram:before {
  content: '';
  color: var(--white);
  position: absolute;
  border-radius: inherit;
  aspect-ratio: 1;
  border: 0.05em solid;
  width: 65%;
}

Instagram outline border in CSS

Then for the inside, we simply use the after selector.

.instagram:after {
  content: '';
  color: var(--white);
  position: absolute;
  border-radius: inherit;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0.05em solid;
  width: 35%;
}

Instagram circle logo addition in CSS

As you can see, both the before and after are very similar. We simply make the one more rounded and smaller.

I hear you wonder, but what about the little dot? We donโ€™t have any selectors left. And thatโ€™s true, but we have our good friend the box-shadow we can use for this.

.instagram:after {
  box-shadow: 0.22em -0.22em 0 -0.18em;
}

With that in place, we should see the result you see in this CodePen.

See the Pen CSS Logos: Instagram logo by Chris Bongers (@rebelchris) on CodePen.

Thank you for reading, and letโ€™s connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter

Spread the knowledge with fellow developers on Twitter
Tweet this tip
Powered by Webmentions - Learn more

Read next ๐Ÿ“–

CSS Logos: Vue logo

22 Jun, 2022 ยท 3 min read

CSS Logos: Vue logo

CSS Logos: Strava logo

21 Jun, 2022 ยท 5 min read

CSS Logos: Strava logo

Join 2099 devs and subscribe to my newsletter