All states use a "best interest of the child" standard in disputed custody cases. This is a rather amorphous standard, and one that lends itself to judges' subjective beliefs about what's best for children. There are some factors, though, that you can expect a judge to consider.
Although the "tender years" doctrine has long been officially out of fashion, some judges still believe that younger children should live with their mothers, especially if the mother has been the primary caregiver. (Certainly, a nursing baby will do so.)
There's a bit of a chicken-and-egg dilemma surrounding the issue of where parents live and how that affects custody. Sometimes, the parent who stays in the family home is granted custody of the children because it allows the children stability and continuity in their daily lives. Sometimes, the parent with custody is awarded the family home, for the same reason. If you are crashing in your best friend's guest room while you get back on your feet after the divorce, don't expect to get primary custody of your kids. If you truly want to spend a significant amount of time with your children, make sure your living situation reflects that. The proximity of your home to your spouse's may also factor in to the judge's decision. The closer you are, the more likely the judge will order a time-sharing plan that gives both parents significant time with the kids. The location of their school and their social and sports activities may also matter.
The judge will look at your record of cooperating—or not— with your spouse about your parenting schedule. The judge might also want to know things like whether you bad-mouth your spouse in front of the kids or interfere with visitation in any way. The more cooperative parent is going to have an edge in a custody dispute—and a parent who's obviously trying to alienate a child from the other parent will learn the hard way that courts don't look kindly on that type of interference.
It sometimes happens that parents who haven't been much involved with their kids' lives suddenly develop a strong desire to spend more time with the children once the marriage has ended. In many cases, this desire is sincere, and a judge will respect it, especially if the parent has been dedicated to parenting during the separation period. But the judge will definitely take some time to evaluate a parent's change of heart and ensure that the custody request isn't being made primarily to win out over the other parent.
If children are old enough—usually, older than 12 or so—a judge may talk to them to find out their preferences about custody and visitation. Some states require courts to consider kids' views, but others disapprove of bringing the kids into it at all. The judge also may learn about the children's preferences from a custody evaluator.
When it comes to children, judges are big on the status quo, because most of them believe that piling more change on top of the traumatic transition of divorce generally isn't good for kids. So if you're arguing that things are working fine, you've got a leg up on a spouse who's arguing for a major change in the custody or visitation schedule that's already in place.
If you're in a same-sex marriage in Connecticut, the District of Columbia, Iowa, Massachusetts, New Hampshire, New York, or Vermont, or in a domestic partnership or civil union in California, Hawaii, Illinois, Nevada, New Jersey, Oregon, Rhode Island, or Washington State, and you and your partner are both legal parents of your kids, your sexual orientation will have no impact on the court's consideration of custody and visitation matters. The same standards that apply to all divorcing couples will apply to you. Certain other states have laws that forbid judges from using sexual orientation alone to deny custody or limit visitation. That doesn't mean you won't come up against a homophobic judge, even in those states. And in some states, courts are allowed to, and do, consider sexual orientation as a major factor in custody and visitation decisions. It's quite common in those states for judges to rule that a parent's same-sex partner can't be around when children are visiting, or that the parent can't expose the kids to a "gay lifestyle." And in the worst-case scenario, parents can be denied all contact with their children on the basis of their sexual orientation. The same can be true for transgender parents, who may face even more prejudice than same-sex parents, as well as a lack of knowledge in many courts about the transgender experience.
Obviously, if there's clear evidence that either parent has abused or neglected the children, a judge will limit that parent's contact with the children.
Every situation is different, so the judge may consider other factors in deciding custody in your case.
(To learn more about child custody in your state, see Child Custody: The Best Interests of the Child).