Adding a circle around a number can be easily done with CSS. This can be done using the border-radius property.
In this snippet, you can also find a way of adding a circle around numbers having one to four digits.
Now, we’ll show the process step by step.
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<div class="circle">1</div>
</body>
</html>.circle {
border-radius: 50%;
width: 34px;
height: 34px;
padding: 10px;
background: #fff;
border: 3px solid #000;
color: #000;
text-align: center;
font: 32px Arial, sans-serif;
}Now we can see the full example.
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.circle {
border-radius: 50%;
width: 34px;
height: 34px;
padding: 10px;
background: #fff;
border: 3px solid #000;
color: #000;
text-align: center;
font: 32px Arial, sans-serif;
}
</style>
</head>
<body>
<div class="circle">1</div>
</body>
</html>Next, we are going to show an example where we use circles around numbers with one to four digits. This example can be used for any amount of text and any size circle.
Here, we’ll use the line-height property. Note that the width and line-height properties must be of the same value.
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.circle {
width: 120px;
line-height: 120px;
border-radius: 50%;
text-align: center;
font-size: 32px;
border: 3px solid #000;
}
</style>
</head>
<body>
<div class="circle">1</div>
<div class="circle">100</div>
<div class="circle">10000</div>
<div class="circle">1000000</div>
</body>
</html>In our last example, we use -moz- and -webkit- prefixes with the border-radius property. Here, we also use the display property set to "inline-block" to represent the element as an inline-level block container.
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
span.circle {
background: #e3e3e3;
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
color: #6e6e6e;
display: inline-block;
font-weight: bold;
line-height: 40px;
margin-right: 5px;
text-align: center;
width: 40px;
}
</style>
</head>
<body>
<span class="circle">1</span>
</body>
</html>