So this is what I want to do :

I have a regular rectangle image, and I want to be displayed as a rounded image. How can I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I hope I got this right:
you have a rectangular non-square image, something like this
(width > height) or like this
(height > width)
and you want to display it in a circle without distorting it,
probably as much as you can display of it and the central part,
something like this:
Solutions:
2023 solution
Give the image either a
widthor aheightanaspect-ratioof1(square) and setobject-fit: coveron it.Original 2012 solutions, preserved for web history reasons, but please don’t do this nowadays anymore
When you know the size of the image it is really simple: you put it in a wrapper, give a wrapper a
widthand aheightthat are both equal to the minimum between thewidthand theheightof the image itself. You then give the wrapperborder-radius: 50%;andoverflow: hidden;.Next, you position the image such that the central part is visible.
widthof the image is greater than itsheight(landscapeimage), then you set its left margin to be
(height-width)/2heightof the image id greater than itswidth(portrait image), then you set its top margin to be
(width-height)/2demo
Relevant HTML:
Relevant CSS for landscape image (dimensions:
468pxx159px):Alternatively, you could use a JavaScript solution (I’m suggesting this because you list javascript among the tags) if you don’t know anything about the orientation (portrait or landscape) of your image or about its dimensions.
demo
I’ve used a few images of different orientations sizes for testing. The HTML for one:
Relevant CSS:
JavaScript: