How to create contact chips with CSS?


Contact chips can be considered as a small contact card on a web page. If you want to list multiple support staff or team members on a web page, then to align the details properly, use the contact chips. It only includes a small profile image with the name. Let us see how to create contact chips on a web page with HTML and CSS.

Create containers

For the contact chips, create individual containers. First, include the profile image using the <img> element. Add the image source for the profile image using the src attribute −

<div class="chip">
   <img src="https://www.tutorialspoint.com/assets/profiles/123055/profile/200_187394-1565938756.jpg" alt ="Amit">
   Amit Diwan
</div>
<div class="chip">
   <img src="https://cdn.pixabay.com/photo/2014/03/24/17/19/teacher-295387__340.png" alt="Britney">
   Britney Smith
</div>

Position the contact chip

To position the contact chips, the optimal solution is to set the display property to inline-block. To design the contact chips, use the border-radius property −

.chip {
   display: inline-block;
   padding: 0 25px;
   height: 50px;
   font-size: 20px;
   font-weight: bold;
   line-height: 50px;
   border-radius: 25px;
   background-color: #6a0074;
   color: white;
}

Position the contact image

The profile image on the contact chip is floated left using the float property with the value left. Also, the border-radius plays a key role again to shape the image −

.chip img {
   float: left;
   margin: 0 10px 0 -25px;
   height: 50px;
   width: 50px;
   border-radius: 50%;
}

Example

To create contact chips with CSS, the code is as follows −

<!DOCTYPE html>
<html>
<head>
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <style>
      body{
         font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
         margin:25px;
      }
      .chip {
         display: inline-block;
         padding: 0 25px;
         height: 50px;
         font-size: 20px;
         font-weight: bold;
         line-height: 50px;
         border-radius: 25px;
         background-color: #6a0074;
         color: white;
      }
      .chip img {
         float: left;
         margin: 0 10px 0 -25px;
         height: 50px;
         width: 50px;
         border-radius: 50%;
      }
   </style>
</head>
<body>
   <h1>Contact chip Example</h1>
   <div class="chip">
      <img src="https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909__340.png">
      James Anderson
   </div>
   <div class="chip">
      <img src="https://cdn.pixabay.com/photo/2014/03/24/17/19/teacher-295387__340.png">
      Britney Smith
   </div>
</body>
</html>

Updated on: 14-Dec-2023

695 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements