In this article, we propose a method to incorporate fabrication cost in the topology optimization of light and stiff truss structures and periodic lattices. The fabrication cost of a design is estimated by assigning a unit cost to each truss element, meant to approximate the cost of element placement and associated connections. A regularized Heaviside step function is utilized to estimate the number of elements existing in the design domain. This makes the cost function smooth and differentiable, thus enabling the application of gradient-based optimization schemes. We demonstrate the proposed method with classic examples in structural engineering and in the design of a material lattice, illustrating the effect of the fabrication unit cost on the optimal topologies. We also show that the proposed method can be efficiently used to impose an upper bound on the allowed number of elements in the optimal design of a truss system. Importantly, compared to traditional approaches in structural topology optimization, the proposed algorithm reduces the computational time and reduces the dependency on the threshold used for element removal.