
1 Cal.3d 266 (1969)
461 P.2d 33
81 Cal. Rptr. 849
ECCO-PHOENIX ELECTRIC CORPORATION, Plaintiff and Appellant,
v.
HOWARD J. WHITE, INC., Defendant and Appellant. (Two Cases.)
Docket Nos. S.F. 22663, 22664.
Supreme Court of California. In Bank.
November 20, 1969.
*270 COUNSEL
Robert O. Wilhelm and Melvin B. Gross for Plaintiff and Appellant.
Crist, Peters, Donegan & Brenner, Colin M. Peters and Beverly A. Gregerson for Defendant and Appellant.
OPINION
MOSK, J.
Plaintiff, Ecco-Phoenix Electric Corporation, an electrical contractor, entered into a written subcontract agreement with defendant Howard J. White, Inc., a general contractor, under which plaintiff agreed to install the electrical system in a building to be constructed by White on the Stanford University campus.
Following completion of the work, plaintiff demanded of defendant additional payment for "extras," work assertedly performed outside the scope of the contract. Defendant denied liability for such payments, and there ensued this litigation, in which plaintiff sought an award of $14,684.23, plus interest. Defendant conceded liability for only $3,084.76, and the jury found plaintiff was entitled to $11,464.97.
Under a clause of the subcontract providing that "Should litigation be necessary to enforce any term or provision of this agreement, then all litigation and court costs and reasonable attorney's fees shall be borne wholly by the Sub-Contractor," the trial court awarded costs and attorney's fees to defendant. Including costs and fees on appeal, which the trial court added in a later order, plaintiff was required to pay to defendant a total of $6,091.10, more than half of plaintiff's award on the merits of its claim.
In S.F. 22663 defendant appeals from the judgment on the merits and plaintiff appeals from the award of costs and attorney's fees at trial. In S.F. 22664 plaintiff appeals in a separate action from the award of costs and fees on appeal. We shall treat these as a single action for purposes of this opinion, and we conclude that the judgment for plaintiff on the merits must be affirmed, but the awards of costs and attorney's fees to defendant must, at least in part, be reversed.

Defendant's Appeal on the Merits
(1) Defendant cites as prejudicial misconduct requiring reversal a statement by plaintiff's counsel during argument referring to a favorable verdict he had received in a previous case in the same court. Assuming that this isolated aside was misconduct, although it was neither emphasized nor *271 repeated and was terminated by defendant's timely objection, it could not have been prejudicial. In addition to the seemingly innocuous nature of the remark, any possible prejudice was surely removed by the trial court's immediate and proper admonition to the jury that they must "disregard any reference to any other case." (See Sabella v. Southern Pac. Co. (1969) 70 Cal.2d 311, 318 [74 Cal. Rptr. 534, 449 P.2d 750], and cases cited therein.)
(2) One Davey, an electrical contractor called as an expert witness by plaintiff, was asked several hypothetical questions framed in terms of "who should pay"  the general contractor or the subcontractor  for certain types of work. The trial court properly sustained defendant's objections to this approach and limited the questions to the existence of a "custom and usage" in the electrical contracting business. (3) Defendant asserts that custom or usage is inadmissible to vary the terms of a written contract (see C.J. Wood, Inc. v. Sequoia Union High School Dist. (1962) 199 Cal. App.2d 433, 436 [18 Cal. Rptr. 647]); but it refers us to no specific provisions in the voluminous general contract  incorporated by reference in the subcontract  which are purportedly varied by the testimony of the witness. If there was a custom or usage which was admissible in evidence, Davey, as an unchallenged expert witness, could properly testify to its existence, even if his testimony thereby "embrace[d] the ultimate issue to be decided by the trier of fact." (Evid. Code, § 805.)
(4) Finally, defendant complains that the trial court erroneously instructed the jury that "Any loss arising from errors and ambiguity in the plans and specifications occasioned by the acts of the owner's architect shall fall upon the general contractor and not upon the subcontractor, as between the general contractor and the subcontractor." This is said to be too broad a generalization, as the general contractor would not be liable if, for example, the extra work was due to the subcontractor's negligence in assessing the plans, and in any event it would not be liable unless it had "ordered, directed, or authorized" the subcontractor to do the extra work.
Although the instruction complained of, if isolated, might be erroneous, a reading of the entire charge to the jury reveals that this broad statement was qualified substantially. The jury was instructed, inter alia, that the subcontractor could not recover for work included under the contract; that it could not recover for extras occasioned by incomplete or confusing plans if reasonable care would have put it on notice of the error or confusion; and that recovery could be had only for extra work ordered by the general contractor in writing, unless this requirement had been waived. Viewing the questioned instruction in context, we perceive no error.


*272 Costs and Attorney's Fees

(5a) We turn now to plaintiff's contention that the trial court erred in awarding costs and attorney's fees to defendant, based on its interpretation of the subcontract. As indicated above, the pertinent clause of the contract provides that "Should litigation be necessary to enforce any term or provision of this agreement, then all litigation and court costs and reasonable attorney's fees shall be borne wholly by the Sub-Contractor." (Italics added.) This clause, and in particular the italicized portion, indicates that plaintiff is to bear all costs and reasonable attorney's fees only in litigation necessary to enforce the contract.
We find the clause less than certain on its face, leaving unanswered such questions as "litigation" by whom, and made "necessary" by whom. (6) As no extrinsic evidence was taken to aid the trial court's interpretation of this clause, we are free to adopt our construction as a matter of law. (Parsons v. Bristol Development Co. (1965) 62 Cal.2d 861 [44 Cal. Rptr. 767, 402 P.2d 839].) As this printed form contract was prepared by defendant, and in light of the oppressive nature of a literal interpretation of the clause, we resolve any uncertainties in favor of a fair and reasonable interpretation and against the inflexible construction adopted by the trial court. (See Taylor v. J.B. Hill Co. (1948) 31 Cal.2d 373, 374 [189 P.2d 258]; cf. 3 Corbin on Contracts (1960) § 552, pp. 210-211.)
(5b) If the clause is read literally, plaintiff is to pay the costs and fees incurred whenever any litigation is necessary, regardless of who brings the action and who is responsible for making it necessary. This interpretation is patently inequitable and would be contrary to public policy as encouraging  and in fact indemnifying  vexatious or frivolous litigation, were it not for several qualifications which must be read into the text.
Under a reasonable interpretation of this clause the subcontractor is liable for costs and attorney's fees only if it, the subcontractor, has made the litigation "necessary." Thus the provision is inapplicable if the general contractor invokes frivolous or bad faith litigation, and it is immaterial whether the contentious conduct is prosecutorial or defensive. The litigation for which the defendant general contractor recovers costs and fees must be necessary in the sense that it must be bona fide, and it must have been made necessary by plaintiff.
(7) In the instant case plaintiff demanded and defendant refused payment under the contract. Although the subsequent verdict established that plaintiff was in fact entitled to over $11,000, which we must for present purposes conclude to be the accurate amount owed, defendant had offered a settlement of only $3,101, and at trial admitted liability of only $3,084.76. *273 Plaintiff was thus forced by defendant to pursue its remedy in the courts. The trial court did find that defendant offered and plaintiff declined to attend a settlement conference; the reasons therefor are unclear. Having thus found the litigation necessary because "the parties could not agree as to the amount owed," the trial court found the clause wholly applicable and awarded costs and reasonable fees to defendant. In this the trial court erred.[1]
It was error to conclude that if plaintiff made the litigation necessary "to some degree," plaintiff was liable for all costs and reasonable fees under the clause. The court also appears to have considered it significant that plaintiff did not recover the full amount prayed for, and thus to that limited extent defendant was "successful" and its defense was therefore "necessitated" by plaintiff's excessive demand. The result of this rationale is to transfer to plaintiff the entire responsibility for instituting the litigation either because it refused for reasons unknown to attend a settlement conference following an inadequate compromise bid by defendant, or because it overestimated its prayer for damages  hardly an unusual circumstance in contemporary litigation. On the other hand, the implication is that had plaintiff attended the conference but properly refused to compromise below the amount subsequently awarded, or had the prayer been for the precise amount awarded, the clause would not have applied. We cannot subscribe to this anomalous result.
Both parties refer us to cases in which a court has construed a statute or contract clause providing that fees be paid to the "prevailing" or "successful" party, and in which the defendant was partially successful in offsetting the plaintiff's recovery by means of a cross-complaint. (E.g., Moss Constr. Co. v. Wulffsohn (1953) 116 Cal. App.2d 203 [253 P.2d 483] [only plaintiff considered "successful party" under Code Civ. Proc., § 1032, subd. (a)]; Munier v. Hawkins (1961) 190 Cal. App.2d 655 [12 Cal. Rptr. 274] [defendant considered to have "recovered" to extent of success on cross-complaint].) However, none of the cases deal with a contract clause requiring, under our interpretation, that litigation be made "necessary," *274 regardless of which party prevails. In any event, the effect in this regard of a partially successful cross-complaint may be somewhat different from the effect of a partially successful defense. The former is, in substance, a judgment against plaintiff in a consolidated but separately based cause of action, and indicates that plaintiff was affirmatively indebted or liable to defendant in some amount; whereas the latter, at least in the instant circumstances, constitutes no judgment against plaintiff and indicates not that plaintiff was independently responsible to defendant, but only that plaintiff overestimated the degree to which defendant was liable to it.
As indicated, we read the clause as imposing liability on plaintiff for costs and fees to the extent plaintiff necessitated the litigation. Therefore the most that its "partially successful" defense can avail defendant is the recovery of costs and attorney's fees for that part of its defense which countered plaintiff's invalid claims  i.e., which was successful.[2] In addition, the trial court may take into account the fact that plaintiff refused to attend a settlement conference, but only to the extent that the refusal was in bad faith or without adequate justification and the court finds a substantial likelihood that attendance at such a conference would have resulted in the avoidance of litigation.[3]
To the extent that plaintiff was not responsible for necessitating the litigation, the clause was simply inapplicable and costs should have been awarded in accordance with settled standards, as if there had been no contractual provision in this regard. (See Code Civ. Proc., § 1032.)
(8) A similar analysis must be employed in allocating costs on appeal. The general rule that an agreement for payment of costs or reasonable attorney's fees in conjunction with the enforcement of a contract includes *275 costs on appeal (see, e.g., Wilson v. Wilson (1960) 54 Cal.2d 264, 272 [5 Cal. Rptr. 317, 352 P.2d 725]) is inapplicable here, as the question of the necessity of the litigation must still be answered as a prerequisite to plaintiff's liability. To the extent the appellate litigation undertaken by plaintiff or defendant was ultimately made necessary by plaintiff, defendant is entitled to costs and reasonable attorney's fees. Other than that extent, costs on appeal must be allowed according to Rules of Court, rule 26, as if no contractual provision were extant.
From the record it appears that even if responsibility for the original litigation must be shared to a relatively minor extent by plaintiff, once the jury awarded plaintiff $11,464.97 plaintiff was willing to let the substantive matter rest. Defendant, however, chose to contest the award, and while it had every legal right to do so  in the absence of an indication the appeal was frivolous or in bad faith  it cannot hold plaintiff responsible for "necessitating" the appeal. Here as at trial, where the question is not just one of good faith but also one of necessity, it would seem that the ultimate success or failure of the appeal becomes relevant, if not conclusive, on that issue. We must accept the jury's finding that defendant owed to plaintiff $11,464.97; whatever litigation, including appeal, was required for plaintiff to recover that amount cannot be considered the responsibility of plaintiff. A fortiori defendant's good faith but unsuccessful efforts in contesting that amount, at trial or on appeal, must be considered the responsibility of defendant alone.
As for plaintiff's appeals in S.F. 22663 and S.F. 22664, much if not all responsibility for their necessity can be traced to the uncertainty of the contract clause prepared by defendant. On the other hand, we have allowed that, depending upon the findings of the trial court on remand, plaintiff may be held responsible for a small part of the original litigation, without which, of course, there would have been no need to interpret the clause. More in the interests of a workable solution than by any imposition of technical precision, we believe it best to apply the same allocation to the costs and fees of plaintiff's appeals as that applicable to the trial itself. This will be the degree to which plaintiff's appeals may be considered successful and in that sense necessary.
(9) If the resulting arithmetic is difficult or confusing, it is due to the ambiguity and complexity of the disputed clause. In the computation of the allocation of costs, as in the initial interpretation of the clause, doubts must be resolved against defendant, whose contract is responsible for the existence of the uncertainty.
In S.F. 22663, the judgment on the merits entered on November 17, 1966, is affirmed; the order awarding costs and attorney's fees entered on *276 December 29, 1966, is reversed. In S.F. 22664, the order appealed from is reversed. The causes are remanded to the trial court for further proceedings in conformity with the views expressed herein. In the light of this disposition, the remittitur issued by this court shall omit any provision for costs on appeal.
Traynor, C.J., McComb, J., Peters, J., Tobriner, J., Burke, J., and Sullivan, J., concurred.
NOTES
[1]  The trial court awarded all costs, on trial and appeal, to defendant; however, it awarded defendant only a portion of its attorney's fees, stating that "the amount of attorney's fees awarded were lower than would be the case, the Court having considered the fact that the jury verdict was much closer to the amount demanded by plaintiff than to the amount offered by defendant." It is not clear by what formula the trial court apportioned the fees, but its inclination to do so was correct. Unfortunately, as will be seen, this allocation was in error in at least two respects: costs should also have been apportioned, with defendant liable for costs not chargeable to (as "made necessary" by) plaintiff; and costs and fees on appeal should have been allocated in a similar manner. Most likely the trial court, recognizing the injustice of the situation but believing itself bound by its interpretation of the clause, salvaged what it could from the provision for "reasonable," as opposed to all, attorney's fees.
[2]  This does not necessarily mean a computation according to the ratio of prayer to award, if it can be determined just what part of costs and fees are properly attributable to the part of the litigation "made necessary" by plaintiff. Thus if it is clear from the jury's award which claims by plaintiff were found to be invalid, and if it is possible to determine the relative trial time devoted to defense against those invalid claims, only that part of costs and fees attributable to such time may be assessed against plaintiff. (Cf. Independent Iron Works, Inc. v. County of Tulare (1962) 207 Cal. App.2d 164, 166 [24 Cal. Rptr. 361].) For the same reason, ratio of recovery would be irrelevant if it were found, for example, but clearly not the situation here, that the entire litigation could have been avoided because defendant had made an offer of settlement for the same amount as that eventually recovered, in which event plaintiff would be wholly liable.
[3]  As in the case of the partially successful defense, plaintiff is only responsible for that part of the litigation which would have been avoided by a successful settlement conference. In the instant case, once trial commenced, defendant disputed  and apparently continues to dispute on appeal  all but $3,084.76 of plaintiff's demand, a concession of less than the amount originally offered in settlement. It seems unlikely, therefore, that a settlement conference would have resulted in a substantial concession of liability by defendant.
