Multivalent CT or MR contrast agents and methods of making and using thereof are described herein. The agents contain a moiety, such as a polymer, that provides multivalent attachment of CT or MR contrast agents. Examples include, but are not limited to, multivalent linear polymers, branched polymers, or hyperbranched polymers, such as dendrimers, and combinations thereof. The dendrimer is functionalized with one or more high Z-elements, such as iodine. The high Z-elements can be covalently or non-covalently bound to the dendrimer. The dendrimers are confined in order to enhance CT contrast. In some embodiments, the moiety is confined by encapsulating the dendrimers in a material to form particles, such as nanoparticles. In other embodiments, the dendrimer is confined by conjugating the moiety to a material, such as a polymer, which forms a gel upon contact with bodily fluids.