CSS – Make a rounded image with the help of CSS3

Here is a simple method to create a circular effect on an image with the use of CSS3. As an example, I’ll use the image below with basic html code and CSS:

new_image

<div class="img-circular"></div>

I’ll now add style for the class “img-circular”:

.img-circular{
width: 300px; 
height: 300px; 
background-image: url('http://michaelsavin.com/wp-content/uploads/2014/09/new_image.jpg');
background-size: cover; 
display: block; 
}

The background-size is a new CSS3 property which lets you manipulate dimensions of a background. You can find more info here. To make the image circular (rounded) we’ll add the border-radius property to our CSS class which essentially lets us round the corners of al element. To create a perfect circle you’ll need to use values which are half the initial image size values. More info on border radius can be found here. Your new property will look like this:

border-radius: 150px;
-webkit-border-radius: 150px;
-moz-border-radius: 150px; 

 

And your new class will therefore look like this:

.img-circular{
width: 300px; 
height: 300px; 
background-image: url('http://michaelsavin.com/wp-content/uploads/2014/09/new_image.jpg');
background-size: cover; 
display: block; 
border-radius: 150px;
-webkit-border-radius: 150px;
-moz-border-radius: 150px; 
}

As a result of using the border-radius property, your image will be perfectly rounded with the minimal effort. It’s worth adding at this point that you can creatively manipulate the radius of your corners to give it any shape you wish.

Michael Savin

My name is Michael Savin. I've been contributing to the Internet for over ten years and have been a London based Magento freelancer for the last six.

I build eCommerce websites for varied companies worldwide and enjoy a close relationship with many brands, freelancers and studios. Work aside I enjoy cycling, reading and long walks in sunny days.

2 Comments

  1. Nice one.
    If you use percentage widths for the border radius ( {border-radius: 50%;} ) then the class will adapt to the height and width and you can re-use the class for images of any size. It’ll even create ellipses if the height and width are not equal.

    1. Hey Darren that’s a nice tip, thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *