Assuming that you have already included the link rel="stylesheet" in the head section of your HTML document, here is the most recent version that you should use:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
I also tested it with an older version and it worked fine as well.
To create a customized Bootstrap 5 dropdown, I added a custom-dropdown class to the existing dropdown:
<div class="dropdown custom-dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
In your CSS file, add the following styling for the custom dropdown:
.custom-dropdown .dropdown-toggle::after {
content: '\f1b2'; /* Replace this with the desired Font Awesome icon code */
font-family: 'Font Awesome 5 Free'; /* Specify the Font Awesome font-family */
font-weight: 900; /* Adjust the font weight if needed */
border-top: 0;
vertical-align: middle;
}
If you encounter a white bar above the icon, you can remove it by using the following CSS:
.custom-dropdown .dropdown-toggle::after {
display: none;
}
Then, you can place the icon within the dropdown button like this:
<div class="dropdown custom-dropdown">
<button className="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
<i class="fa-solid fa-cube"></i>
</button>
<ul className="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a className="dropdown-item" href="#">Action</a></li>
<li><a className="dropdown-item" href="#">Another action</a></li>
<li><a className="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
Make sure everything is functioning as expected after changing the icon, and if it meets your requirements, feel free to mark this answer as correct :)