Starting with a brief introduction into the basics of relativistic fluid dynamics, I discuss our current knowledge of a relativistic theory of fluid dynamics in the presence of (mostly shear) viscosity. Derivations based on the generalized second law of thermodynamics, kinetic theory, and a complete second-order gradient expansion are reviewed. The resulting fluid dynamic equations are shown to be consistent for all these derivations, when properly accounting for the respective region of applicability, and can be applied to both weakly and strongly coupled systems. In its modern formulation, relativistic viscous hydrodynamics can directly be solved numerically. This has been useful for the problem of ultrarelativistic heavy-ion collisions, and I will review the setup and results of a hydrodynamic description of experimental data for this case.