We study the spherical collapse of an over-density of a barotropic fluid with linear equation of state in a cosmological background. Fully relativistic simulations are performed by using the Baumgarte–Shibata–Shapiro–Nakamura formalism jointly with the Valencia formulation of the hydrodynamics. This permits us to test the universality of the critical collapse with respect to the matter type by considering the constant equation of state parameter ω as a control parameter. We exhibit, for a fixed radial profile of the energy-density contrast, the existence of a critical value ω ∗ for the equation of state parameter under which the fluctuation collapses to a black hole and above which it is diluting. It is shown numerically that the mass of the formed black hole, for subcritical solutions, obeys a scaling law M∝ | ω- ω ∗| γ with a critical exponent γ independent on the matter type, revealing the universality. This universal scaling law is shown to be verified in the empty Minkoswki and de Sitter space-times. For the full matter Einstein-de Sitter universe, the universality is not observed if conformally flat sub-horizon initial conditions are used. But when super-horizon initial conditions computed from the long-wavelength approximation are used, the universality appears to be true.