Skip to content

Default CSS for glyphicons produces conflict with bootstrap5 components (with potential solution) #1820

Closed

Description

@baender

Describe the bug
Manually adding a bootstrap5 modal to the html body results in wrong position of the modal (see screenshots at the end).

To Reproduce

import folium

my_map = folium.Map()

# Adding modal from https://www.w3schools.com/bootstrap5/bootstrap_modal.php
my_map.get_root().html.add_child(folium.Element("""
<!-- Button to Open the Modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#myModal">
  Open modal
</button>

<!-- The Modal -->
<div class="modal" id="myModal">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Modal Heading</h4>
        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
      </div>

      <!-- Modal body -->
      <div class="modal-body">
        Modal body..
      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
      </div>

    </div>
  </div>
</div>
"""))

my_map.save(outfile="map.html")

Expected behavior
The modal should appear in the same way as in the bootstrap5 modal example on w3schools.

Environment:

  • OS: macOS 14.0
  • Browser: Firefox 118.0.1
  • Python version: 3.10.7
  • folium version: 0.14.0
  • branca version: 0.6.0
  • Plain .py, no Jupyter Notebook

Possible solutions
This issue is resolved when uncommenting the stylesheet on netdna for bootstrap 3.0.0, however, I cannot tell what the implications to other functions of folium that would have (e.g. glyphicons).

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.9.3/dist/leaflet.css"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css"/>
<!--    <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"/>-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.2.0/css/all.min.css"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.css"/>

Screenshots
Wrong: with default CSS <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"/>
folium_bs5_modal_wrong

Correct: without default CSS <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"/>
folium_bs5_modal_correct

Activity

  1. adarshsm commented on Jul 30, 2026

    @adarshsm
    Contributor

    This still reproduces on main, and I think the root cause is narrower than it first looks — worth writing down before anyone fixes it.

    The migration to Bootstrap 5 removed the worst of the old conflict (folium no longer loads the full Bootstrap 3 bootstrap.min.css). But one Bootstrap 3 stylesheet is still injected into every map, in folium/folium.py:

    # glyphicons came from Bootstrap 3 and are used for Awesome Markers
    (
        "glyphicons_css",
        "https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css",
    ),

    Despite the name, that file is not glyphicons-only — it's a full Bootstrap 3 base stylesheet. Alongside the @font-face/.glyphicon* rules it also ships a normalize reset and global element styles, including:

    body { margin: 0; }
    body { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
           font-size: 14px; line-height: 1.428571429; color: #333333;
           background-color: #ffffff; }

    It's linked after the Bootstrap 5 CSS, so those body rules (and the reset) win over BS5's Reboot for anything the user adds to the page — which is exactly the modal/layout shift in the screenshots above.

    folium only actually needs the @font-face + .glyphicon* rules from that file (for Icon(prefix="glyphicon", ...) / Awesome Markers). So the fix I'd propose is to stop pulling the whole BS3 base and instead ship a minimal glyphicons-only stylesheet — just the font-face and .glyphicon classes, with an absolute font URL — the same way leaflet.awesome.rotate.min.css is already vendored under folium/templates/. That keeps glyphicon markers working while removing the global body/reset pollution.

    Before I open a PR: does that direction sound right to you, or would you rather drop the Bootstrap-3 glyphicon dependency entirely (Awesome Markers can use Font Awesome, which folium already loads)? Happy to implement whichever you prefer.

  2. hansthen commented on Jul 31, 2026

    @hansthen
    Collaborator

    Both would be fine with me. Your first proposed approach sounds like less work than totally dropping the Bootstrap-3 glyphicon dependency. Would the second approach also entail a customer facing change?

  3. adarshsm commented on Jul 31, 2026

    @adarshsm
    Contributor

    Thanks @hansthen! Yes — the second approach (dropping the Bootstrap-3 glyphicon dependency in favour of Font Awesome) would be customer-facing: anyone using folium.Icon(prefix="glyphicon", icon=...) relies on the Glyphicons Halflings font that this CSS provides, so removing it would break their existing markers.

    The first approach avoids that entirely — a vendored glyphicons-only stylesheet keeps prefix="glyphicon" working exactly as it does today and only drops the unintended body/normalize/reset rules that are leaking onto the page. So it's not a customer-facing change; the only visible difference is that folium stops overriding the host page's body styles.

    I'll go with the first approach and open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy