Search code examples
cssiconsbootstrap-5

Bootstrap 5 svg icons do not appear


I have added a footer from bootstrap official docs examples but the social icons do not seem to appear . I have added these cdns :

<link rel="preconnect" href="//fonts.gstatic.com" crossorigin>
<link href="//fonts.googleapis.com/css2?family=Cairo:wght@200;300;400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">
<script src="//cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>


 <div class="container">
  <footer class="d-flex flex-wrap justify-content-between align-items-center py-3 my-4 border-top">
    <div class="col-md-4 d-flex align-items-center">
      <a href="/" class="mb-3 me-2 mb-md-0 text-muted text-decoration-none lh-1">
        <svg class="bi" width="30" height="24"><use xlink:href="#bootstrap"></use></svg>
      </a>
      <span class="text-muted">© 2021 Company, Inc</span>
    </div>

    <ul class="nav col-md-4 justify-content-end list-unstyled d-flex">
      <li class="ms-3"><a class="text-muted" href="#"><svg class="bi" width="24" height="24"><use xlink:href="#twitter"></use></svg></a></li>
      <li class="ms-3"><a class="text-muted" href="#"><svg class="bi" width="24" height="24"><use xlink:href="#instagram"></use></svg></a></li>
      <li class="ms-3"><a class="text-muted" href="#"><svg class="bi" width="24" height="24"><use xlink:href="#facebook"></use></svg></a></li>
    </ul>
  </footer>
</div>

enter image description here

and this is the part of the code : enter image description here


Solution

  • To be able to use the SVG sprite, you need to include the sprite and reference it in the <use> xlink href. See the example from the documentation:

    <svg class="bi" width="32" height="32" fill="currentColor">
      <use xlink:href="bootstrap-icons.svg#heart-fill"/>
    </svg>
    <svg class="bi" width="32" height="32" fill="currentColor">
      <use xlink:href="bootstrap-icons.svg#toggles"/>
    </svg>
    <svg class="bi" width="32" height="32" fill="currentColor">
      <use xlink:href="bootstrap-icons.svg#shop"/>
    </svg>
    

    The above code assumes that you have the bootstrap-icons.svg file at the same location than the HTML file which contains the code. If not, you need to adapt the path in the href.

    The SVG you can grab here: https://github.com/twbs/icons/blob/main/bootstrap-icons.svg

    If you installed Bootstrap Icons via NPM, you can find the file in:

    node_modules/bootstrap-icons/bootstrap-icons.svg