Your Web project may include pictures used to illustrate the text. In this case you may want to border these pictures. Adding a border to an image is a simple task using CSS. The next example shows two possible ways to do this:

C# 8.0 and .NET Core 3.0 – Modern Cross-Platform Development: Build applications with C#, .NET Core, Entity Framework Core, ASP.NET Core, and ML.NET using Visual Studio Code, 4th Edition
ASP.NET Core 3 and Angular 9: Full stack web development with .NET Core 3.1 and Angular 9, 3rd Edition
C# in Depth, 4th Edition

File test.css

img {

border-width: 1px;

border-style: solid;

border-color: #000000;



File test.css

img {

border: 1px solid #000000;


You can use the next test file to see how this technique works:


File test.html

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”


<html xmlns=”” lang=”en-US”>


<title>How to add border to images with CSS</title>

<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />

<link rel=”stylesheet” type=”text/css” href=”test.css” />



<img src=”sailboard1.jpg” alt=”sailboard one” />

<img src=”sailboard2.jpg” alt=”sailboard two” />




The next picture shows the result:

Adding border to images with CSS

Adding border to images with CSS