Melanin is primarily produced in the epidermis of the skin, specifically within the melanocytes. These cells are located in the basal layer of the epidermis. Melanocytes have dendritic processes that extend to keratinocytes, transferring melanin to them.