How to set border to an image in an HTML page

HTML Image Border Using CSS

The CSS border property is used to set a border to an image in a webpage.

It is used to specify the width, style and color of the border around the image in a webpage.

Example of Border of Image

Create an HTML <img> element and add src="logoimage.jpg" attribute to the image element to specify the relative URL of the image.

Add CSS inline style style="border:1px solid red;" in the HTML <img> element.

Here "border" is the CSS property name and the value of the property "1px solid red" refers that the border width is 1px solid in style and color of the border is red.

Have a closer look at the following example:

Example of HTML Image Border


Output of the above example

Example of Image Border in a Webpage


xFactor School Logo

In the above example, CSS inline style is used to set border to the image.

style="border: 1px solid red;" is the css border style. Here the color of border line is red, line style is solid and width is 1px.

Live Code Playground

In the following HTML code editor, you can practice the above code by changing the value of CSS border property. Click on the 'Run Code' button to render the code; the rendered page will be displayed in the following HTML Code Output frame. Practice until you become comfortable and proficient with your code.

HTML logo HTML Online Editor
HTML Code Output