Create a Mac App Icon with Pure HTML and CSS
+Create a Mac App Icon with Pure HTML and CSS
+2021-04-13
-I have always been a huge fan of Bogdan's work on Dribbble and was recently inspired to see if I could replicate one of his awesome icon designs with only HTML & CSS. What was the outcome? I think it's a half-way decent copy - of course the original will always look significantly better.
-Don't care about reading through the tutorial? No problem! You can jump right down to the live demo
-The Comparison
-Let's take a look at the original Dribbble shot:
- -And now let's see what we will be creating with only HTML & CSS:
- + +I have always been a huge fan of Bogdan’s work on Dribbble and was recently inspired to see if I could replicate one of his awesome icon designs with only HTML & CSS. What was the outcome? I think it’s a half-way decent copy - of course the original will always look significantly better.
+ +Don’t care about reading through the tutorial? No problem! You can jump right down to the live demo
+ +The Comparison
+ +Let’s take a look at the original Dribbble shot:
+ +And now let’s see what we will be creating with only HTML & CSS:
+Like I said - far from perfect but still a fun experiment!
-The HTML
-Let's jump right in and build out the main skeleton of our project:
-<div class="white-square"></div>
-<div class="blue-square">
- <div class="row">
- <div class="item"></div>
- <div class="item"></div>
- </div>
- <div class="row">
- <div class="item"></div>
- <div class="item"></div>
- </div>
- <div class="row">
- <div class="item"></div>
- <div class="item"></div>
- </div>
- <div class="row">
- <div class="item"></div>
- <div class="item"></div>
- </div>
- <div class="row">
- <div class="item"></div>
- <div class="item"></div>
- </div>
- <div class="row">
- <div class="item"></div>
- <div class="item"></div>
- </div>
- <div class="row">
- <div class="item"></div>
- <div class="item"></div>
- </div>
-</div>
-<div class="play-button">
- <div class="triangle"></div>
-</div>
+
+The HTML
+
+Let’s jump right in and build out the main skeleton of our project:
+
+<div class="white-square"></div>
+<div class="blue-square">
+ <div class="row">
+ <div class="item"></div>
+ <div class="item"></div>
+ </div>
+ <div class="row">
+ <div class="item"></div>
+ <div class="item"></div>
+ </div>
+ <div class="row">
+ <div class="item"></div>
+ <div class="item"></div>
+ </div>
+ <div class="row">
+ <div class="item"></div>
+ <div class="item"></div>
+ </div>
+ <div class="row">
+ <div class="item"></div>
+ <div class="item"></div>
+ </div>
+ <div class="row">
+ <div class="item"></div>
+ <div class="item"></div>
+ </div>
+ <div class="row">
+ <div class="item"></div>
+ <div class="item"></div>
+ </div>
+</div>
+<div class="play-button">
+ <div class="triangle"></div>
+</div>
- - The white-square
element is the white, rounded square in the background
- - The blue-square
is the main blue square of the icon
- - The row
elements inside the blue-square
will be our individual lines spread across the icon
- - The play-button
is obviously - the play button
- Right now it will look like nothing, but we can change that by adding the most important part...
-The CSS
-Pasting the entire CSS styling here would end up looking a little daunting. Instead, I'm just going to breakdown each individual section to make things more digestible.
-Defaults & the White Square
+
+
+The white-square
element is the white, rounded square in the background
+The blue-square
is the main blue square of the icon
+The row
elements inside the blue-square
will be our individual lines spread across the icon
+The play-button
is obviously - the play button
+
+Right now it will look like nothing, but we can change that by adding the most important part…
+
+
+The CSS
+
+Pasting the entire CSS styling here would end up looking a little daunting. Instead, I’m just going to breakdown each individual section to make things more digestible.
+
+Defaults & the White Square
+
* {
box-sizing: border-box;
}
:root {
--row-distance: 42px;
}
-
-.white-square {
+
+.white-square {
background: white;
border-radius: 105px;
box-shadow: inset 0 -5px 8px rgba(0,0,0,0.25), 0 12px 10px rgba(0,0,0,0.15), 0 2px 4px rgba(0,0,0,0.1);
@@ -94,7 +105,9 @@
width: 420px;
}
+
See that --row-distance
variable? That will come into play a bit later. For now, we want to lay the Blue Square on top of this newly creating White Square:
+
.blue-square {
background: linear-gradient(#04BDFD 0%, #0585E4 100%);
border-radius: 105px;
@@ -107,8 +120,11 @@
width: 420px;
}
-Targeting the Inner Rows
-So far so good. The next part looks like a lot, but I assure you it's fairly straightforward. We need to include each row inside the Blue Square like in the original Dribbble shot (7 total). First we start with the parent row
styling:
+
+Targeting the Inner Rows
+
+So far so good. The next part looks like a lot, but I assure you it’s fairly straightforward. We need to include each row inside the Blue Square like in the original Dribbble shot (7 total). First we start with the parent row
styling:
+
.blue-square .row {
display: flex;
height: 20px;
@@ -118,7 +134,9 @@
width: 100%;
}
+
Now we style each individual row item via the nth-of-type
attribute:
+
.blue-square .row:nth-of-type(2) { margin-top: var(--row-distance); }
.blue-square .row:nth-of-type(2) .item:nth-of-type(odd) {
width: 85px;
@@ -172,9 +190,13 @@
width: calc(100% - 55px);
}
-Take a few moments to read everything over - it will help you better understand what's going on. Basically, we are adding two inner elements to each row element. We calculate the margin-top
distance by using that --row-distance
variable I mentioned earlier. The inner elements are then styled based on their placement inside the row (nth-of-type
).
-The Play Button
+
+Take a few moments to read everything over - it will help you better understand what’s going on. Basically, we are adding two inner elements to each row element. We calculate the margin-top
distance by using that --row-distance
variable I mentioned earlier. The inner elements are then styled based on their placement inside the row (nth-of-type
).
+
+The Play Button
+
Now we finish things off with a much simpler element to style:
+
.play-button {
backdrop-filter: blur(6px);
border-radius: 9999px;
@@ -189,7 +211,7 @@
.play-button::before {
background: rgba(255,255,255,0.9);
border-radius: 9999px;
- content:'';
+ content:'';
filter: blur(40px);
height: 150%;
left: -25%;
@@ -208,7 +230,7 @@
}
.triangle:before,
.triangle:after {
- content: '';
+ content: '';
position: absolute;
background-color: inherit;
}
@@ -230,17 +252,24 @@
transform: rotate(135deg) skewY(-45deg) scale(.707,1.414) translate(50%);
}
-Thanks to meduz for pointing out the backdrop-filter
property. This allows for a frosted glass look on Chromium & Safari (although sadly not on Firefox). The triangle
element could also be improved by using an embedded SVG
but I was determined to use only CSS for this experiment :P
-That's really all there is to it! You can see the embedded CodePen example below or check it out directly here →
-
-Special Thanks
+
+Thanks to meduz for pointing out the backdrop-filter
property. This allows for a frosted glass look on Chromium & Safari (although sadly not on Firefox). The triangle
element could also be improved by using an embedded SVG
but I was determined to use only CSS for this experiment :P
+
+That’s really all there is to it! You can see the embedded CodePen example below or check it out directly here →
+
+
+
+Special Thanks
+
Thanks to Bogdan for letting me butcher the original Dribbble shot :D
+
-
-Live Demo (CodePen)