How to Add a Border Around an Image in WordPress

Adding a border around images can help make them stand out on your WordPress site. A subtle border adds separation between the image and the surrounding content, while a bolder border can emphasize the image.

But borders aren‘t just decorative – they also have technical benefits for better image formatting.

In this comprehensive guide as a WordPress expert of over 15 years, I‘ll share some insider tips to help you add borders around images in WordPress.

Here‘s what I‘ll cover:

  • Key reasons to use image borders
  • Choosing the right border style
  • Automating borders with plugins
  • How to code borders with CSS
  • Creative border effects
  • Troubleshooting problems
  • Image and accessibility considerations

Let‘s dive in!

Why You Should Be Adding Borders Around Images

Before we get into the how of adding image borders, let‘s look at some key reasons why you should use them:

Draws Attention to Important Images

A border adds definition that makes an image stand out on the page. This subtly draws the viewer‘s eye to the image.

Borders are great for emphasizing important graphics like infographics or product photos without being too distracting.

Pro Tip: To make an image really grab attention, combine a border with the CSS box-shadow property to add a subtle shadow effect.

Improves Separation for Better Scanning

White space and borders improve separation between images and surrounding text content.

This makes your pages more scannable so users can easily distinguish images from text when scanning the page.

According to Nielsen Norman Group, 79% of users scan web pages rather than thoroughly reading. So optimizing scannability with borders is essential.

Adds a Decorative Styling Element

Creative border styles like rounded corners or drop shadows can add an artistic touch to your pages. Borders complement the overall visual design.

This is especially true for photography sites or portfolios where a bordered gallery layout fits the aesthetic.

Provides Visual Connection

Borders also visually connect a group of related images. For example, adding matching borders to an image gallery or product catalog gives cohesion.

This connects the images and communicates they are part of a set.

Improves Accessibility

Borders add contrast between images and the background which improves accessibility for low vision users. This makes it easier to distinguish image shapes and contents.

Now that you know the benefits, let‘s look at how to add those image borders in WordPress.

Choosing the Right Border Style for Your Images

When adding a border, there are a few style factors to consider:

Border Width

Thin 1-2 pixel borders add just a subtle separation. Thicker 3-5 pixel borders make the image stand out more.

Wider borders can be visually striking for hero images. But use thinner borders for galleries to avoid dominating the page.

Pro Tip: Use CSS media queries to adjust your border widths for different device sizes.

/* Wide borders on desktop */
@media (min-width: 1024px) {
  .image {
    border: 4px solid #333; 
  }
}

/* Thinner borders on mobile */
@media (max-width: 480px) {
  .image {
    border: 2px solid #333;
  }
}

Border Style

The style – solid, dashed, dotted, double, groove, ridge etc. – sets the overall look and feel.

Solid borders work best for a bold framed effect. For a more subtle feel, try dashed or dotted styles.

Border Color

Black and white are classic border colors that work for any site style. Match darker borders with lighter backgrounds and vice versa for contrast.

To integrate your brand, use a signature brand color for your image borders.

Border Radius

Adding a border-radius subtly rounds the corners for a softer effect. Set the radius value higher for more dramatic curved edges.

Now that we‘ve covered the key border style factors, let‘s look at the various methods for adding borders to WordPress images.

Method 1: Using a Plugin to Automatically Add Borders

The easiest way to add image borders, especially for WordPress beginners, is by using a plugin.

The WP Image Borders plugin lets you add stylish borders with no coding required. Here‘s how it works:

Install and Activate WP Image Borders

First, install and activate the plugin on your WordPress site. You can search for it via Plugins > Add New and then click install.

Once activated, the plugin will automatically add borders to all images in your posts and pages.

Customize the Border Settings

Next, go to Settings > WP Image Borders to customize your desired border style. Here you can configure:

  • Border style – solid, dotted, dashed etc.
  • Border color
  • Border width
  • Border radius/roundness
  • Padding and margins
  • Drop shadow effects

Set these options to your preferred image border styling. Then click Save Changes.

The plugin will now apply these borders around all inserted images across your site.

Target Specific Images

You can also use the plugin settings to target borders only to specific images.

Under "Target Images", check the option "Add borders to images with CSS class".

In the input, enter a class like .border-img

Then when inserting images into posts/pages, edit the image settings and add this class to only the images you want to have a border.

This gives you more fine-grained control compared to adding borders to every image.

The key benefit of using WP Image Borders or a similar plugin is it requires zero coding knowledge. The borders are added automatically based on your configured style.

However, one downside is limited customization options compared to manually coding the CSS yourself.

Next let‘s look at how to code borders around images with CSS.

Method 2: Using CSS to Add Borders Around Images

Hard-coding borders using CSS gives you more advanced flexibility compared to plugins.

When you insert an image into WordPress, it outputs HTML like:

<img src="image.jpg" alt="alt text" width="200" height="300">

You can then add custom CSS styling to this image to create borders and other effects.

There are a few approaches:

Inline CSS Borders

For one-off images, you can use inline CSS styles added directly in the HTML:

<img src="image.jpg" alt="alt text" width="200" height="300" 
style="border: 2px solid #333;">

This will uniquely style just this image with the defined 2px black border.

But inline CSS can get messy if you need to add it to many images. Next we‘ll look at a better way.

Borders Via Theme Stylesheet

For a consistent border around all images across your site, add the CSS in your theme stylesheet (style.css or a child theme CSS file).

Some examples:

All Images

To add a border around every image:

img {
  border: 2px solid #333;
}

Left/Right Aligned Images

To target floated left or right aligned images:

img.alignleft { 
  float: left;
  margin-right: 20px;
  border: 1px solid #999; 
}

img.alignright {
  float: right;
  margin-left: 20px;
  border: 1px solid #999;
}

Centered Images

For centered images:

img.aligncenter {
  display: block; 
  margin: 20px auto;
  border: 1px solid #999;
}

No Alignment Class

In case the image has no alignment class:

img.alignnone {
  border: 1px solid #999;
} 

This applies the border style uniformly to all images across all pages and posts.

The advantage is you don‘t have to manually code each image. The downside is less selective control.

Next we‘ll go over how to use CSS classes for optimal border control.

Adding Borders with CSS Classes

For maximum flexibility, you can use custom CSS classes to apply targeted borders only to specific images.

First, add this sample CSS:

/* Border class */
img.border-img {
  border: 2px dashed #333;
  padding: 5px; 
}

/* No border class */
img.no-border {
  border: none;
}

Now when inserting images into the editor, add a class like .border-img only to the images you want to have a border.

Add .no-border to images you want borderless.

The benefits of this method:

  • Apply borders only to specific images rather than globally.
  • Use multiple classes for different border styles.
  • Override with .no-border class for borderless images.
  • Change styling by editing CSS, not each image.

This gives you the most fine-grained control over image borders in WordPress.

Now that we‘ve covered the key technical aspects of adding borders with CSS, let‘s look at some creative styling ideas.

Creative Border Styling for Visual Impact

By creatively using CSS properties, you can add some visual flair to your image borders.

Let‘s look at some examples you can use for inspiration.

Rounded Corner Borders

A simple way to soften borders is adding rounded corners with the border-radius property:

.round-border {
  border: 2px solid #333;
  border-radius: 10px;  
}

Bump up the pixel value for more dramatically curved corners.

According to Backlinko, images with rounded corners can increase conversion rates by up to 24%.

Drop Shadow Borders

The box-shadow property adds a subtle shadow behind the image:

.shadow-border {
  border: 2px solid #FFF;
  box-shadow: 3px 3px 10px rgba(0,0,0,0.4); 
}

Adjust the blur, spread distance, and opacity to taste.

Drop shadows add depth and make images visually pop off the page.

Double Borders

You can layer two borders by adjusting the border-width:

.double-border {
  border: 4px solid #333;
  border-width: 4px 2px;
}

Set differing widths and colors for the two borders to customize the effect.

Groove and Ridge Borders

Groove and ridge borders create inset and outset 3D effects:

/* Groove border */
.groove-border {
  border: 4px groove #333;
}

/* Ridge border */
.ridge-border {
  border: 4px ridge #333;
}

These borders styles add more visual interest.

Feel free to mix and match border properties like radius, shadow, width, and colors to invent your own unique border styles.

Next let‘s go over some handy tools for adding creative borders to images.

Tools for Adding Stylish Image Borders

While coding borders gives you the most flexibility, you can also use graphic design tools for quick and easy border styling:

Canva

Canva has tons of templates with pre-made borders you can drag images into. Then export and upload to WordPress.

PicMonkey

Lets you add various border effects like frames, shadows, and patterns to images. Saves you coding time.

Photopea

This free Photoshop alternative has customizable border options like size, color, and style built into the editing tools.

Lunapic

A free online photo editor with a border tool offering various shapes, widths, opacities, and textures.

These graphics tools provide user-friendly interfaces for styling borders if you prefer a visual workflow.

The benefit is you avoid manually coding CSS. The drawback is less customization flexibility.

Now let‘s go over some best practices and troubleshooting for working with image borders.

Border Troubleshooting Tips

Here are some tips to handle common issues that may arise when adding borders:

Borders Not Showing Up

If borders aren‘t displaying, check that:

  • The image CSS class name matches your stylesheet rule.
  • There aren‘t other CSS rules overriding the border styling.
  • Your theme‘s stylesheet is being loaded properly.
  • Try adding !important to force border styling.

Weird Spacing Issues

If border spacing seems off, try adding these styles:

img {
  display: inline-block;
  vertical-align: top; 
}

This overrides default browser alignment and spacing.

Don‘t Forget Padding!

Add some padding to prevent text from butting up against the border:

img {
  border: 1px solid #333;
  padding: 5px; /* Add padding */
}

Border Radius Crops Corners

If rounded corners get cropped off, make sure the parent container doesn‘t overflow the image dimensions.

Images Seem Distorted

Borders should not distort image sizing. Make sure to crop and optimize images before uploading.

Properly handling borders does require some CSS knowledge and troubleshooting. But the visual payoff for your images is worth it!

Important Considerations When Using Borders

Let‘s wrap up with a few key technical considerations when using image borders:

Theme Support

Some themes have limited CSS support which may prevent applying borders. Always test border styles to make sure they work in your theme.

Using a page builder or custom theme gives you maximum CSS control for borders.

Image File Type

Border styles like drop shadows and rounded corners work best with JPG or PNG image types. SVG and GIF files have fewer styling options.

Accessibility

While borders improve visibility, ensure there is sufficient contrast between the border color and background color by testing contrast ratios.

Don‘t apply borders to purely decorative images. Add null alt text alt="" so borders are ignored by screen readers.

Performance

Too many large, high-resolution images with complex borders can impact page load speed. Consider limiting borders only to your most important images.

By keeping these factors in mind, you can add beautiful borders without compromising accessibility or performance.

Recap and Final Tips

We‘ve covered a ton of ground around adding borders to WordPress images:

  • Borders draw attention, improve separation, and enhance styling. But use thempurposefully.

  • The border style – width, color, radius, etc. – determines the look and impact.

  • Plugins like WP Image Borders provide automatic borders with no coding needed.

  • CSS gives you fine-grained control over border styling for any image.

  • Get creative with borders using rounded corners, drop shadows, groove patterns, and more.

  • Watch for spacing quirks, image distortion, and accessibility issues when using borders.

A few parting tips:

  • Experiment with different border styles and assess the visual impact.

  • Be strategic – add borders only to your most important images.

  • Use CSS media queries so your borders look great on all device sizes.

  • Check for theme support and test border styling thoroughly.

  • Analyze page speed to optimize image file sizes and resolutions.

With these border techniques at your disposal, you can frame any image beautifully in WordPress!

So put these skills into practice and let me know if you have any other border styling questions!

Written by Jason Striegel

C/C++, Java, Python, Linux developer for 18 years, A-Tech enthusiast love to share some useful tech hacks.