Proteins such as FUS phase separate to form liquid-like condensates that can harden into less dynamic structures. However, how these properties emerge from the collective interactions of many amino acids remains largely unknown. Here, we use extensive mutagenesis to identify a sequence-encoded molecular grammar underlying the driving forces of phase separation of proteins in the FUS family and test aspects of this grammar in cells. Phase separation is primarily governed by multivalent interactions among tyrosine residues from prion-like domains and arginine residues from RNA-binding domains, which are modulated by negatively charged residues. Glycine residues enhance the fluidity, whereas glutamine and serine residues promote hardening. We develop a model to show that the measured saturation concentrations of phase separation are inversely proportional to the product of the numbers of arginine and tyrosine residues. These results suggest it is possible to predict phase-separation properties based on amino acid sequences.