Square and circular images in CSS and Elementor

In this tutorial, you will learn how to put images into a circle or a square using aspect ratio in Elementor Pro (or Elementor FREE) and CSS!

Keep reading or watch the video below:

I am using Elementor Pro version that enables me to directly put my CSS code in the widget section.

If you are using Elementor FREE version, you can use one of the free plugins to put your CSS code there. Like this Simple Custom CSS and JS plugin.

Now let’s see how to make our images square or circular!

1. Start by using the image widget

Place your photo using the image widget and setting the ‘image size’ to ‘full’.

2. Go to ‘Custom CSS’ field if you are using Elementor Pro

If you are using Elementor Pro, go to the ‘Custom CSS’ field of the ‘Advanced’ section of your image widget. If you are not using Elementor Pro, but a free version, you can add this code through a plugin, such as Simple Custom CSS and JS plugin.

In this ‘Custom CSS’ field, let’s add the following code to create a SQUARE image:

selector img{
	width: 400px;
	aspect-ratio: 1;
	object-fit: cover;
}

Let’s see what these lines of code mean. You can set the ‘width’ to any size you want. ‘Aspect-ratio’ is set to 1, which means that the sides are equal. This will create the actual square. The ‘object-fit’ property set to cover will make sure that the image is not distorted or deformed and that it will keep its original proportions. Setting it to ‘cover’ means that it will fit the width of the container. We can also set it to ‘contain’ which will fit the height of the image to the height of the container.

To make the image ROUND and put it in a circle, we simply need to add ‘border-radius’ property set to 50%. This is how the code would look like in that case:

selector img{
	width: 400px;
	aspect-ratio: 1;
	object-fit: cover;
	border-radius: 50%;
}

Now we have a circular image!

3. If you are using Elementor FREE…

What happens if you are using Elementor FREE version? In that case, the ‘Custom CSS’ field will be disabled. That means that you should place your CSS code through a plugin such as Simple Custom CSS and JS plugin.

4. Give your image a CSS class

Go to the ‘Advanced’ tab of your image widget and ‘CSS classes’ field. Simply give your image class a name and type it here without a dot (‘.’) and spaces. So it can be something like ’rounded-image’ or any other name you like.

5. Style this class using a CSS code through a plugin

Remember this class name and use a plugin I suggested to input your CSS code (Simple Custom CSS and JS plugin). After installing and activating this plugin, go to your Custom CSS and simply add the code from above, just instead of ‘selector’, use your class name with a dot (‘.’) before it.

In case of the class name ’rounded-image’, the code would look like this:

.rounded-image img{
	width: 400px;
	aspect-ratio: 1;
	object-fit: cover;
	border-radius: 50%;
}

And that’s it! Now you can go ahead and apply this class to multiple images on your website. You are able to then simply change the width from a single place and make all those images rounded and circular by simply giving those images this class name!

Online course

Ready to Learn CSS?

A step-by-step basic online course for beginners and non-coders with 50+ practical exercises to get you started with CSS.

CSS-online-course-for-beginners-banner-illustration

Download Elementor Pro here.

*This post may contain affiliate links. If you click on a link and make a purchase, I will receive a commission from the sale, with no extra cost to you. That way you are supporting my blog and allowing me to keep making videos and posts like this. I only promote products that I use, have experience with and support, such as Elementor Pro.

Share this post:

Leave a Comment

Related posts:

General instructions:

  1. Open the exercise in your browser and read the task and the content on the left side of the screen. 
  2. You will be editing the content on the right side of the screen.
  3. In order to do that, right click on the exercise page that you opened and go to ‘Inspect’.
  4. Go to ‘Sources’ in the top bar and if you cannot see an empty CSS sheet where you can type the code, press Ctrl + P and start typing ‘styl’ in the search bar. Then press enter to open the CSS sheet.
  5. Follow the notes on the left and start typing your CSS code to see the changes online!
  6. Important! Do not refresh the page while you are editing the code, as these changes are in preview mode only and you can see them immediately, as soon as you write a line of functioning code.
  7. Use the custom classes in the notes on the left side of the screen, as well as ‘Elements’ on the top bar of the ‘Inspect’ to target and style the classes and elements. For example, you can enable the small icon on the top left of the ‘Inspect’ window (‘Select an element in the page to inspect it’) to find the default class name of the element you want to edit, while you are in the ‘Elements’ tab.

Tips:

  1. If the code is not showing any changes, try adding the !important tag at the end of the line before closing it (before the “;” symbol) and see if it works then.
  2. Don’t forget there are usually more ways to achieve the same result. Be creative!
  3. If you get stuck, write your email address in the form on the left side of the screen and you will get the solution (CSS code) in your email.

Sources:

  1. You can find a lot of tutorials on my youtube channel. 
  2. Watch the tutorial on how to solve these exercises here.

Please check your email and stay tuned for updates on the course.

We will notify you shortly when it’s available for presale.