Both anime and cartoons are considered forms of animation but they are also considered subcategories. Cartoons and anime have their own unique characteristics which sets them apart from other type of animation. It's the same idea between the difference of 2D animation and CGI animation.
With cartoons, the images that make up the animation are almost always 2D. Most people think that cartoons only mean childish shows that are targeted towards children like SpongeBob SquarePants or Dora the Explorer. That's not the case though. Cartoons were originally meant for humor, appearing as illustrations as inflamatory propaganda or comic strips like the Peanuts. People can see this in trend has continued with popular shows that fall into the cartoon category. Shows like Family Guy, Futurama, and the Simpsons. They aren't always what people would consider child appropriate cartoons but not all cartoons are meant for that.
With anime on the other hand, the style people usually see is bigger eyes, intense fight scenes, and an aesthetic that usually falls into 'cool' or 'cute'. This is for anime with a younger target audience population though. Shows with tropes like 'magical girl' or 'the power of friendship will defeat our enemies.' In darker animes though, ones like Death Note, Tokyo Ghoul, and Attack on Titan and considerably tame for some of the dark and emotional animes that exist.
These two categories exist because despite the fact they are similar and take many different forms, at their core there's a different focus. Cartoons all contain a comedic aspect to them, whether it's mild humor or dark humor. It's supposed to make people smile or laugh. With anime on the other hand, the focus is more emotional.