Have you ever wanted to render your images or text such that they appear as though they are circular or have a circular border? This is how to do it.

CSS Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#circle{ 
	position:relative;
  	overflow:hidden;
	background: #ffffff; 
	width: 300px; 
	height: 300px; 
        border-radius: 150px;
        -moz-border-radius: 150px;
        -webkit-border-radius: 150px;
	border: .5px solid #1a1a1a; 
	box-shadow: 5px 5px 2px #23282d;
	margin-bottom: 15px;
	margin-top: 30px;
}
#circle div { 
	position:absolute;  
	top: 15%; 
	width: 300px; 
	height: 300px; 
	background-color: white; 
	text-align:center; 
	transition: all .2s ease-in-out;
}
#circle div:hover { 
	transform: scale(1.1);
}

HTML Code for showing text in a circle

1
2
3
4
5
6
      <!--Code to render text in a circle-->
      <div id="circle">
         <div>
            My Text
         </div>
      </div>

My Text

HTML Code for showing image in a circle

1
2
3
4
5
6
      <!--Code to render image in a circle-->
      <div id="circle">
         <div>
            <img style="border: none;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/22/Twemoji2_1f633.svg/200px-Twemoji2_1f633.svg.png" />
         </div>
      </div>

Full HTML code with css comments

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<html>
   <head>
      <style>
         #circle{ /*css for the outer div*/
         position:relative; /* Position wrt to inner div */
         overflow:hidden; /* Make sure inner div does not flow over the outer div */
         background: #ffffff;
         /* width, height and radius i.e. width divided by 2, you can change this if needed, just make sure to change same in #circle div as well! */
         width: 300px; 
         height: 300px; 
         border-radius: 150px;
         -moz-border-radius: 150px;
         -webkit-border-radius: 150px;
         border: .5px solid #1a1a1a; /* Border of the outer circle */
         box-shadow: 5px 5px 2px #23282d; /* Adding lifting shadow effect to the circle, optional! */
         margin-bottom: 15px; /* wrt other elements, optional */
         margin-top: 30px; /* wrt other elements, optional */
         }
         #circle div { /*css for the inner div*/
         position:absolute; /* position wrt to outer div */ 
         top: 15%; /* do top, left adjustments incase the text or image are not centered in the circle */
         width: 300px; 
         height: 300px; 
         background-color: white; 
         text-align:center; 
         transition: all .2s ease-in-out; /* Adding some cool transition, optional */
         }
         #circle div:hover { 
         transform: scale(1.1); /* Adding some cool transition on mouse over, optional */
         }
      </style>
   </head>
   <body>
      <!--Code to render text in a circle-->
      <div id="circle">
         <div>
            My Text
         </div>
      </div>
      <!--Code to render image in a circle-->
      <div id="circle">
         <div>
            <img style="border: none;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/22/Twemoji2_1f633.svg/200px-Twemoji2_1f633.svg.png" />
         </div>
      </div>
   </body>
</html>

A personal technical diary… To the point… Precise