Section 3040 sets the sequence in which custody is considered, always according to the best interest of the child as defined in §§ 3011 and 3020. Subdivision (a)(1) puts custody to both parents jointly, or to either parent, first; in making an order to either parent the court must consider, among other factors, which parent is more likely to allow the child frequent and continuing contact with the other, and may in its discretion require the parents to submit a plan for implementing the order. Paragraph (2) comes next: if to neither parent, to the person or persons in whose home the child has been living in a wholesome and stable environment. Paragraph (3) is the residual: to any other person deemed suitable and able to provide adequate and proper care and guidance.
The section then removes several considerations from the calculation. Subdivision (b) provides that the immigration status of a parent, legal guardian or relative does not disqualify them from receiving custody. Subdivision (c) forbids the court from considering the sex, gender identity, gender expression or sexual orientation of a parent, guardian or relative in determining best interest. Subdivision (d) deals with mental illness: where the court finds the effects of a person's history of or current mental illness are a factor, it must both provide a list of local mental health resources and state its reasons in writing or on the record, without displacing the child's health, safety and welfare as the primary concern.
Subdivision (e) is the sentence most often quoted out of context: the section establishes neither a preference nor a presumption for or against joint legal custody, joint physical custody or sole custody, but allows the court and the family the widest discretion to choose a parenting plan in the child's best interest. There is no default 50/50 in this section. What arrangement fits a particular family is exactly what a family lawyer and, where the court orders it, custody mediation are for.