TFs contain DNA-binding domains (DBDs) that allow them to bind to specific DNA sequence (a recognition sequence) or have a general affinity to DNA. These DBDs are an independently folded protein domain which contains at least one motif that recognizes double or single stranded DNA.
DBDs are often part of a large protein containing additional domains with different functions. These additional domains often regulate the activity of the DBD and the function of DNA binding is either structural or transcriptional regulation, with the two roles sometimes overlapping.
Some examples of DBDs include the zinc finger, leucine zipper and winged helix.
Proteins that bind to DNA can be divided into two groups: those that bind to a specific DNA sequence and those that bind non-specifically. Proteins that bind to specific DNA sequences are often activators or repressors involved in regulating gene expression. These are proteins that interact with a short, well-defined, nucleotide sequence found near the start site for transcription. Proteins in the latter category include those required for DNA replication, repair, and recombination, as well as packaging proteins like the histones.
Now, here's the important point: all specific DNA binding proteins also bind DNA non-specifically. In many cases it's part of the search mechanism for the specific binding site. In the case of lac repressor, for example, the protein binds to any old place on the DNA molecule and slides along the DNA searching for a specific binding sequence. After sliding for a second or so it falls off and re-binds to another part of the DNA molecule.