Correlating the structures and properties of a polymer to its monomer sequence is key to understanding how its higher hierarchy structures are formed and how its macroscopic material properties emerge. Carbohydrate polymers, such as cellulose and chitin, are the most abundant materials found in nature whose structures and properties have been characterized only at the submicrometer level. Here, by imaging single-cellulose chains at the nanoscale, we determine the structure and local flexibility of cellulose as a function of its sequence (primary structure) and conformation (secondary structure). Changing the primary structure by chemical substitutions and geometrical variations in the secondary structure allow the chain flexibility to be engineered at the single-linkage level. Tuning local flexibility opens opportunities for the bottom-up design of carbohydrate materials.