{"id":119758,"date":"2013-08-13T11:30:27","date_gmt":"2013-08-13T15:30:27","guid":{"rendered":"http:\/\/wpmu.org\/?p=119758"},"modified":"2013-08-12T21:40:37","modified_gmt":"2013-08-13T01:40:37","slug":"make-images-in-wordpress-circular-with-css","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/make-images-in-wordpress-circular-with-css\/","title":{"rendered":"2 Easy Steps to Giving Images in WordPress a Circular Look with CSS"},"content":{"rendered":"<p>While not new by any means, circular images definitely seem to be in style these days. Wherever you look, it seems circular images are all around.\u00a0 \u2026 But then again, what else could they be? :)<\/p>\n<div class=\"image-grid cgrid-row\">\n<div class=\"cgrid-col cgrid-col-span-full\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-ratio-large wp-image-119760\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/08\/round-image-700x624.jpg\" alt=\"round-image\" width=\"700\" height=\"624\" \/><\/div>\n<\/div>\n<h2><b>Step 1 \u2013 Insert Code in CSS File<\/b><\/h2>\n<p>If you\u2019d like some of your images to take a circular style (as above), it\u2019s not so hard to do. You\u2019ll just need to add a few lines to your CSS file, and then you\u2019ll just need to apply a little bit of code to whichever images you\u2019d like.<\/p>\n<p>Of course it\u2019s always best to make changes to your CSS file <a href=\"https:\/\/wpmudev.com\/blog\/how-to-create-a-wordpress-child-theme-in-3-steps\/\" target=\"_blank\">by using a child theme<\/a> (or a special CSS area that your theme might designate for such additions).<\/p>\n<p>In your CSS file (Appearance &gt; Editor &gt; Stylesheet \u2013 style.css), place the following code and save your file.<\/p>\n<pre>.circular-image img {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 width: 300px;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 height: 300px;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -webkit-border-radius: 150px;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -moz-border-radius: 150px;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -ms-border-radius: 150px;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -o-border-radius: 150px;\r\n                border-radius: 150px;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/pre>\n<p>The reason for all those different 150px lines is to account for different browsers. Some say that these days you only need &#8220;border-radius: 150px;&#8221; but if you want to be extra sure, you can include them all.<\/p>\n\n<h2><b>Step 2 \u2013 Wrap Images with DIVs<\/b><\/h2>\n<p>Once that\u2019s set, go ahead and upload your image as you normally would and place it wherever you\u2019d like (centered, aligned right, etc.).<\/p>\n<p>Once your image is in place, switch to the \u201cText\u201d view of your editor, place the following around the code you see for your image:<\/p>\n<p>{code type=php}<\/p>\n<div class=\"circular-image\">code-for-image<\/div>\n<p>&nbsp;<\/p>\n<p>In other words, in all its glorious messiness, it will look something like this:<\/p>\n<div class=\"image-grid cgrid-row\">\n<div class=\"cgrid-col cgrid-col-span-full\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-ratio-large wp-image-119767\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/08\/code-700x275.jpg\" alt=\"code\" width=\"700\" height=\"275\" \/><\/div>\n<\/div>\n<p>You\u2019ll notice that the div class (\u201ccircular-image\u201d) is the same as the identifier in your CSS file. It doesn\u2019t matter what you name it as long as they\u2019re both the same. And of course you\u2019ll want to pick a name that isn\u2019t going to conflict with something already in your CSS file, so just make sure it\u2019s at least a little bit unique.<\/p>\n<p>Save your post, and that should give you a circular image.<\/p>\n<h2><b>Important Notes, and an Alternative Method<\/b><\/h2>\n<p>There are a few important things to cover about the code above. I made the image you see above a perfect circle by setting the height and width in my CSS file \u2013 300px by 300px. And then I set the border radius as half that\u2014150px. You can change these dimensions if you want something larger or smaller. Just keep the ratio the same\u2014i.e. if you make the size 400px by 400px, make the radius half that by bumping it up to 200px.<\/p>\n<p>Some of\u00a0 you may already be asking: Can\u2019t I just make the image circular and not set the size? In other words, can\u2019t I let the actual size of the image dictate the size of the circular image?<\/p>\n<p>Well, yes and no \u2026 maybe.<\/p>\n<h2><b>Squares vs. Rectangles<\/b><\/h2>\n<p>It all comes down to the shape of your original image. Is it already a perfect square, or is it a rectangle?<\/p>\n<p>Because my original image was a rectangle, if I hadn\u2019t set the exact height and width, it would have come out oblong \u2013 which might be cool too. We\u2019ll go over that as well.<\/p>\n<p>First, however, let\u2019s take a look at what I mean. Here\u2019s my original image without the special CSS code applied to it. You\u2019ll see that the original image is a rectangle, not a perfect square.<\/p>\n<div class=\"image-grid cgrid-row\">\n<div class=\"cgrid-col cgrid-col-span-full\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-ratio-large wp-image-119761\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/08\/rectangle-700x523.jpg\" alt=\"rectangle\" width=\"700\" height=\"523\" \/><\/div>\n<\/div>\n<p>Now if I wanted to, I could just roll with a border radius of 50% and let the original image size dictate the size of the final circular image. I could put this in my CSS file.<\/p>\n<pre>.circular-image img {\r\n-webkit-border-radius: 50%;\r\n-moz-border-radius: 50%;\r\n-ms-border-radius: 50%;\r\n-o-border-radius: 50%;\r\nborder-radius: 50%;\r\n}<\/pre>\n<p>When I do that, here\u2019s the result I get. You\u2019ll notice the image is more oval-shaped\/oblong than the first one, which was a perfect circle.<\/p>\n<div class=\"image-grid cgrid-row\">\n<div class=\"cgrid-col cgrid-col-span-full\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-ratio-large wp-image-119762\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/08\/oblong-700x601.jpg\" alt=\"oblong\" width=\"700\" height=\"601\" \/><\/div>\n<\/div>\n<p>For a better view, here are the two side by side.<\/p>\n<div class=\"image-grid cgrid-row\">\n<div class=\"cgrid-col cgrid-col-span-full\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-ratio-large wp-image-119763\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/08\/side-by-side-700x312.jpg\" alt=\"side-by-side\" width=\"700\" height=\"312\" \/><\/div>\n<\/div>\n<p>Some may actually prefer that look. Or some may prefer one look for some things and the other look for other things. If that\u2019s the case, then just make two different classes and apply them as you like.<\/p>\n\n<h2><b>More or Nothing<\/b><\/h2>\n<p>The CSS code for images can get much more complicated than what\u2019s mentioned here\u2014well beyond my understanding\u2014but the above should do the job for many who just want a quick, neat little trick to give their posts a little more variety.<\/p>\n<p>If you want to get into more advanced tricks, then just hit up Google for CSS and images. Once you have the basics above in place, it shouldn\u2019t be hard to test other things out.<\/p>\n<p>Of course you might be thinking that one way to get circular images is to just make them that way in a graphics program. And of course you can do that. But if one day the circular craze gets to be a little too much, and you want to revert back to good old-fashioned squares and rectangles, all you need to do is go into your CSS file and put the kibosh to your code.<\/p>\n\n<p>Photo credit: <a href=\"http:\/\/www.flickr.com\/photos\/garlandcannon\/6090983235\/\" target=\"_blank\">garlandcannon<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This little trick gives you stylish, rounded images in your posts. <\/p>\n","protected":false},"author":84404,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[16],"tutorials_categories":[],"class_list":["post-119758","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-images"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/119758","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/84404"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=119758"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/119758\/revisions"}],"predecessor-version":[{"id":204519,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/119758\/revisions\/204519"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=119758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=119758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=119758"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=119758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}