How to add border to an image CSS?

Member

by sabryna , in category: HTML/CSS , 2 years ago

How to add border to an image CSS?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by Ekaterina_90 , 2 years ago

@sabryna  Use the border property to add a border to an <img> element:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <style>
      img {
        border: 2px solid blue;
      }
    </style>
  </head>
  <body>
    <img src="image/2.png" />
  </body>
</html>
by yadira.tillman , a year ago

@sabryna 

To add a border to an image using CSS, you can do the following:

  1. First, select the image element by using the CSS selector.
  2. Then, use the border property to specify the border attributes. For example, you can use the following CSS code to create a border of 2 pixels solid #000 color:
1
2
3
img {
  border: 2px solid #000;
}


You can customize this code to set your preferred border thickness, style, and color.

  1. Save the CSS file and upload it to your website or web page.


The image will now have a border around it.