Use HTML in Folium Maps: A Comprehensive Guide for Data Scientists
Learn Step-by-Step How to Add Dynamic Images, Links, Text, and Tables to Folium Map Pop-ups Using HTML

Table of Contents:
· Introduction · Part I: HTML Basics ∘ What is HTML? ∘ Tags and Attributes ∘ A Simple Construction of an HTML Page ∘ How to Add Text, Links, Images, and Tables in HTML
· Part II: Create Customized Folium Popup Using HTML ∘ Import libraries and Read Data ∘ Create a Basic Folium Map ∘ Create an HTML Page for Each Marker ∘ Pass HTML to Folium Map Markers · Closing Thoughts · References and Data Source
Introduction
You may wonder: as a data scientist, not a web developer, why do I need to learn and understand HTML? Is it beneficial for me to invest my precious time to learn the basics of it? Will I ever come across a situation where I need to use it in my work and be glad for having taken the time to learn it?
I had the same question and doubt until I encountered my first geospatial project a few months ago. In that project, I needed to pass HTML to a Folium map as markers and struggled for making it look and work the way I want. I did extensive research online but couldn’t find a good resource page that puts the core concepts and codes in one place and explains them in detail with the data science context.
That’s the motivation behind this post. In this post, I want to first walk you through the core concepts of HTML from a complete beginner’s view. Then we will put the knowledge to use and learn how to construct an HTML webpage by adding headings, images, links, and tables to it. Lastly, we will pass the HTML to folium map markers and add it to the pop-up window, as shown in the screenshot below.

Part I: HTML Basics
Before we get hands-on and create a folium map with the pop-ups shown in the image above, let’s first spend some time learning the basics of HTML. By doing so, you will have a much easier time understanding the code written in Part II and be able to make use of them effectively in the future. So if you are completely new to HTML, please don’t skip this section.
What is HTML?
HTML is a language that’s widely used to create web pages. You may also have heard of CSS. CSS is different from HTML. CSS is the code used to assist HTML to make the web pages visually appealing. In this post, we will mainly focus on HTML.
Here is a short description of HTML from Wikipedia:
The HyperText Markup Language, or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript.
Tags and Attributes
HTML is a markup language that computers use to interpret and control how text, images, or other objects are processed and presented in web browsers. To do this, HTML uses Tags and Attributes - the two most important concepts you need to understand which serve the basis of HTML.
What are Tags?
HTML elements are the building blocks of HTML pages and tags are used to mark up the start of an HTML element.
Tags are written in angle brackets and the vast majority of them come in pairs like the example below. It has an opening tag and a closing tag and some element information such as a title placed between the tags. There are some exceptions though: for example, tags are unpaired and do not have the closing tag. Tags can also be nested within tags.

What are Attributes?
Attributes provide additional information for tags and are placed in the opening tag only. Look at the example below in which we created an image tag . Within the tag, image source (src), alt text (alt), width, and height are all the attributes of this tag.

A Simple Construction of an HTML Page
The image below demonstrates a simple construction of an HTML page.
HTML documents are required to start with a Document Type Declaration using the tag, which specifies the language we will write on the page (HTML 5).
The tag indicates where we start to write in HTML code and is used as a container for all of the HTML of an entire document.
The tag is a container for metadata (data about data) such as document titles etc.
The tag contains the content of the web page.

How to Add Text, Links, Images, and Tables in HTML
Add Text in HTML: Use tag
to add text or a paragraph.

Add links in HTML: Use tag to add links

Add images in HTML: Use tag to add images

Add tables in HTML:
Adding tables in HTML is slightly more complicated in syntax compared to adding text, links, or images. We use tag to create a table and inside the tag, we specify the number of rows using and columns (cells) using
| . |

Part II: Create Customized Folium Popup Using HTML
Now we have learned the basics of HTML, we are ready to apply what we just learned in a real-world use case. Let’s say we want to build a college selection tool. In the tool, we want to create an interactive map and add markers of the U.S. universities to the map. When a user clicks a marker, a pop-up window appears which displays the university’s logo image, website URL, and some additional information in a table.
Import libraries and Read Data
Let’s first import all the necessary libraries and read the data into a pandas data frame. For ease of demonstration, I created a very small sample dataset that includes only 5 universities, from the original dataset that can be downloaded from DATA.ED.GOV (U.S. Department of Education). This is an open dataset that does not require a license to use. I have also saved all the image files in the same folder of my python code file.










