I’ve just added a bonus lecture to my course on client side programming with Leaflet. I had a student ask about creating legends for Leaflet maps and I agreed that this was an important missing piece that I had neglected in the main part of the course. I want this course to be comprehensive and so my intention is to continue adding and updating content as needed to provide the best value for my students.
Legends in Leaflet are not straightforward. There are no plug-ins that I am aware of that create them automatically as you can do in a desktop GIS package. But it is possible to create very complex, dynamic legends with a bit of HTML, CSS, and JavaScript. There are a number of methods which I discuss in this video but I focus on using SVG graphics because Leaflet actually uses SVG graphics to render geospatial data and thus it is relatively simple to exactly match the symbology of your data.