Civil Code section 1717
(a)
In any action on a contract, where the contract specifically provides that attorney’s fees and costs, which are incurred to enforce that contract, shall be awarded either to one of the parties or to the prevailing party, then the party who is determined to be the party prevailing on the contract, whether he or she is the party specified in the contract or not, shall be entitled to reasonable attorney’s fees in addition to other costs.(b)
(1)The court, upon notice and motion by a party, shall determine who is the party prevailing on the contract for purposes of this section, whether or not the suit proceeds to final judgment. Except as provided in paragraph (2), the party prevailing on the contract shall be the party who recovered a greater relief in the action on the contract. The court may also determine that there is no party prevailing on the contract for purposes of this section.(2)
Where an action has been voluntarily dismissed or dismissed pursuant to a settlement of the case, there shall be no prevailing party for purposes of this section.(c)
In an action which seeks relief in addition to that based on a contract, if the party prevailing on the contract has damages awarded against it on causes of action not on the contract, the amounts awarded to the party prevailing on the contract under this section shall be deducted from any damages awarded in favor of the party who did not prevail on the contract. If the amount awarded under this section exceeds the amount of damages awarded the party not prevailing on the contract, the net amount shall be awarded the party prevailing on the contract and judgment may be entered in favor of the party prevailing on the contract for that net amount.
Source:
Section 1717, https://leginfo.legislature.ca.gov/faces/codes_displaySection.xhtml?lawCode=CIV§ionNum=1717.
(accessed Apr. 24, 2025).