Open In App

How to add a Circle around a Number in CSS ?

In the article, we will learn how to add a Circle around a number in CSS. We can easily add a circle around the number by setting the border-radius property to 50% of a specified element. Here, we will understand two methods for achieving a circle around a number:

We will explore the above approaches with the help of examples.

Circle having the same length

Example: The below example illustrates adding a circle around a number in CSS.






<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width,
                   initial-scale=1.0">
    <title>
          How to Add a Circle
        Around a Number in CSS
    </title>
    <style>
        .container {
            display: flex;
            justify-content: space-evenly;
        }
  
        .numbers {
            width: 50px;
            line-height: 50px;
            border-radius: 50%;
            text-align: center;
            background-color: rgb(7, 122, 7);
            color: white;
        }
  
        h1 {
            color: green;
            text-align: center;
        }
  
        p {
            text-align: center;
  
        }
    </style>
</head>
  
<body>
    <h1>GeeksForGeeks</h1>
    <p>How to Add a Circle
        Around a Number in CSS</p>
    <div class="container">
        <p class="numbers">1</p>
        <p class="numbers">10</p>
        <p class="numbers">100</p>
        <p class="numbers">1000</p>
        <p class="numbers">10000</p>
    </div>
</body>
  
</html>

Output:

 

Circle having varying length

Example: The below example shows how to add a circle around a number with varying lengths in CSS.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width,
                   initial-scale=1.0">
    <title>
          Circle around the Numbers
        with varying length
    </title>
    <style>
        h1 {
            color: green;
            text-align: center;
        }
  
        p {
            text-align: center;
  
        }
  
        .container {
            display: flex;
            align-items: center;
            justify-content: space-evenly;
        }
  
        .circle {
            display: inline-block;
            line-height: 0px;
            border-radius: 50%;
            font-size: 32px;
            background-color: green;
            color: white;
        }
  
        .circle span {
            display: inline-block;
            padding-top: 50%;
            padding-bottom: 50%;
            margin-left: 8px;
            margin-right: 8px;
        }
    </style>
</head>
  
<body>
    <h1>GFG</h1>
    <p>
        Circle around the Numbers
        with varying length
    </p>
    <div class="container">
        <span class="circle">
            <span>1</span>
        </span>
        <span class="circle">
            <span>10</span>
        </span>
        <span class="circle">
            <span>100</span>
        </span>
        <span class="circle">
            <span>1000</span>
        </span>
        <span class="circle">
            <span>1000000000</span>
        </span>
    </div>
</body>
  
</html>

Output:

 


Article Tags :