3040. Order of preference
(a) Custody should be granted in the following order of preference according to the best interest of the child as provided in Sections 3011 and 3020:
(1) To both parents jointly pursuant to Chapter 4 (commencing with Section 3080) or to either parent. In making an order granting custody to either parent, the court shall consider, among other factors, which parent is more likely to allow the child frequent and continuing contact with the noncustodial parent, consistent with Sections 3011 and 3020, and shall not prefer a parent as custodian because of that parent's sex. The court, in its discretion, may require the parents to submit to the court a plan for the implementation of the custody order.
(2) If to neither parent, to the person or persons in whose home the child has been living in a wholesome and stable environment.
(3) To any other person or persons deemed by the court to be suitable and able to provide adequate and proper care and guidance for the child.
(b) The immigration status of a parent, legal guardian, or relative shall not disqualify the parent, legal guardian, or relative from receiving custody under subdivision (a).
(c) This 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 that is in the best interest of the child.
(d) In cases where a child has more than two parents, the court shall allocate custody and visitation among the parents based on the best interest of the child, including, but not limited to, addressing the child's need for continuity and stability by preserving established patterns of care and emotional bonds. The court may order that not all parents share legal or physical custody of the child if the court finds that it would not be in the best interest of the child as provided in Sections 3011 and 3020.