To use the mailto functionality in Bootstrap 5, you can combine Bootstrap classes with a standard HTML anchor tag.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 5 MailTo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
</head>
<body>
<div>
<a href="mailto:example@example.com" class="btn btn-primary">
<i class="bi bi-envelope-fill me-2"></i>Email Us
</a>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
crossorigin="anonymous"></script>
</body>
</html>
- The
<a>
tag is used with thehref
attribute set tomailto:example@example.com
. - The
class="btn btn-primary"
applies Bootstrap’s button styling - An icon is added using Bootstrap Icons (assuming you’ve included the Bootstrap Icons library).
- The
me-2
class adds a small margin to the right of the icon.
Create a Mailto Links and Email Lists with Bootstrap 5
<div>
<!-- Basic text link -->
<p>Send us an email at <a href="mailto:info@example.com">info@example.com</a></p>
<!-- List group with email links -->
<ul class="list-group mb-3">
<li class="list-group-item">
<a href="mailto:sales@example.com" class="text-decoration-none">
<i class="bi bi-envelope me-2"></i>Sales Department
</a>
</li>
<li class="list-group-item">
<a href="mailto:marketing@example.com" class="text-decoration-none">
<i class="bi bi-envelope me-2"></i>Marketing Department
</a>
</li>
</ul>
</div>
Card with email link
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Contact HR</h5>
<p class="card-text">For all HR related inquiries, please email us.</p>
<a href="mailto:hr@example.com" class="btn btn-outline-secondary">
<i class="bi bi-envelope me-2"></i>Email HR
</a>
</div>
</div>