We have analyzed the properties of a sample of 33 groups and clusters of galaxies for which both optical and X-ray data were available in the literature . This sample was built to examine the baryon content and to check for trends over a decade in temperature down to 1 keV . We examine the relative contribution of galaxies and ICM to baryons in clusters through the gas-to-stellar mass ratio ( M _ { gas } / M _ { * } ) . We find that the typical stellar contribution to the baryonic mass is between 5 and 20 % , at the virial radius . The ratio ( M _ { gas } / M _ { * } ) is found to be roughly independent of temperature . Therefore , we do not confirm the trend of increasing gas-to-stellar mass ratio with increasing temperature as previously claimed . We also determine the absolute values and the distribution of the baryon fraction with the density contrast \delta with respect to the critical density . Virial masses are estimated from two different mass estimators : one based on the isothermal hydrostatic equation ( IHE ) , the other based on scaling law models ( SLM ) , the calibration being taken from numerical simulations . Comparing the two methods , we find that SLM lead to less dispersed baryon fractions over all density contrasts and that the derived mean absolute values are significantly lower than IHE mean values : at \delta = 500 , the baryon fractions ( gas fractions ) are 11.5–13.4 % ( 10.3–12 % ) and \sim 20 \% ( 17 % ) respectively . We show that this is not due to the uncertainties on the outer slope \beta of the gas density profile but is rather indicating that IHE masses are less reliable . Examining the shape of the baryon fraction profiles we find that cluster baryon fractions estimated from SLM follow a scaling law . Moreover , we do not find any strong evidence of increasing baryon ( gas ) fraction with temperature : hotter clusters do not have a higher baryon fraction than colder ones , neither do we find the slope \beta to increase with temperature . The absence of clear trends between f _ { b } and M _ { gas } / M _ { * } with temperature is consistent with the similarity of baryon fraction profiles and suggests that non-gravitational processes such as galaxy feedback , necessary to explain the observed luminosity–temperature relationship , do not play a dominant rôle in heating the intra-cluster gas on the virial scale .