Most broadly, there were two orders of dinosaurs in existence: bird-hipped and lizard-hipped. The bird-hipped dinosaurs (ornithiscians) consisted of diverse herbivores including Stegosaurus, Triceratops, Ankylosaurus hadrosaurs (duck-billed dinosaurs), and thick-headed dinosaurs such as Dracorex. The lizard-hipped dinosaurs (saurischians) included the theropods, which included every carnivorous dinosaur, and the sauropods, which were the largest animals ever to walk the Earth.
The dinosaur evolved from archosaur ancestors in the middle Triassic period, about 230 million years ago, not long after the greatest mass extinction in the Earth's history. Archosaurs are the group that includes modern-day birds and crocodiles, but at the time, they had a universally reptilian appearance. Common features of archosaurs include teeth set in sockets, special holes in the skull to reduce weight, and extra notches on the femur for muscle attachments. Dinosaurs are essentially just archosaur reptiles with limbs held erect beneath the body.
Quickly, dinosaurs diversified into a range of body types. The earliest dinosaur is thought to have been a small, bipedal predator. About 215 million years ago, an extinction event wiped out many of the dinosaurs' biggest competitors, which included basal archosaurs and the ancestors of mammals, therapsids. Before this extinction, dinosaurs made up only 1-2% of land animals, and after it, they represented 50-90%. Dinosaurs diversified to fill the empty niches, including medium-sized predator, large predators, medium-sized herbivores, large herbivores, etc.
Though dinosaurs diversified early, they didn't balloon in size until after the Triassic-Jurassic extinction 200 million years ago, which even more aggressively wiped out the remaining dinosaur competitors. The earliest dinosaurs were "small" (up to 20 ft) sauropods, which had long necks and walked on four legs, eating plants, and carnivorous theropod dinosaurs (with a body plan superficially similar to T. rex that were only about the size of humans.
Throughout the Jurassic Period, dinosaurs diversified even more impressively. The interplay between predators and prey gave rise to many adaptations on both sides: herbivorous dinosaurs acquired either extreme size or unique arrangements of armor or weapons, such as tail clubs or spikes. Predators got larger and smarter, with bigger teeth, stronger jaws, and a longer head to hold them in. This culminated in giants like T. rex.