Is there a Carto CSS Gallery which also contains code?

Unfortunately, there isn't one yet.

I've asked myself the same thing occasionally but I've found a handful of examples through the years that I've drawn some inspiration and learned through. Unfortunately, most authors aren't putting their all or some of their work public. Also, there's been a couple small changes in carto, some of the code may not be 100% up to date or may not take advantage of carto's current capabilities and you'll also have to change things as people use different data types (postgis queries, shapefiles, json, etc) for your needs.

https://github.com/andrewharvey/osm-hybrid-carto

https://github.com/aaronlidman/Toner-for-Tilemill

https://github.com/ajashton/simple-osm

nice Transit map by Code for america participant jlord - https://github.com/codeforamerica/Transit-Map-in-TileMill

https://github.com/mapbox/osm-bright - A great way to start learning carto. This is what really helped me to learn carto and I often use it as a base layer for projects or begin with it for a project. A fork of it.

LA Times' 'Quiet LA' Map style

Pandonia - style made by flickr

https://github.com/wboykinm/geosprocket-carto

Some examples from Dane Springmeyer, Tilemill and mapnik developer These are very experimental and push the bounds of what can be done in Carto.

A mapping style for humanitarian contexts from HOT, the humanitarian openstreetmap team.

Additionally, the cartocss port of the OSM default style mentioned by maning is a nice work.

Lastly, this one in my github repo is a decent take off of osm-bright as well:

Experimenting with these styles and modifying them will really help you learn.


Carto is also used in Mapbox-Studio-Classic (aka tilemill2) but the processing of source data is different because it uses vector tiles. You have to first convert your data source into a vector tile source before using it.

The following styles, written for use in Mapbox-Studio, use Mapbox-Streets as the source data unless noted.

High-contrast black and white style similar aesthetics to Ello - viewable here

Vetiver

An orienteering map made by Rafa of Mapbox - uses external data sources

Darkly-Neon, from Stephen Smith

n\|/0, a Halloween-themed carto style that I made that uses numerous regular expressions. If you're looking to understand how to use regular expressions in Carto, this can help. Viewable here.

Lastly, as you experiment with Mapbox-streets as a data source, you'll also learn that some assumptions are baked into the data source. For example, you cannot display some POIs that are nodes in the #poi_label at a zoom level below 15 or 16.


Check this CartoCSS port of the OpenStreetMap default style.

https://github.com/gravitystorm/openstreetmap-carto


There is also a list of CartoCSS map styles on the OpenStreetMap wiki.