The chemical reactions and pathways involving thymine, 5-methyluracil, one of the two major pyrimidine bases present (as thymidine) in DNA but not found in RNA other than (as ribothymidine) in transfer RNA, where it is a minor base.