Complexity is a decisive feature of tax systems and a recent body of evidence reveals that it induces taxpayers to misperceive taxes, in particular their marginal tax rates. Building on these studies, we develop a behavioral model of optimal taxation à la Mirrlees (1971) in which the government faces an equity-efficiency trade-off. Misperception of the tax schedule reduces the efficiency costs of taxation and allows an inequality averse government to increase redistribution and social welfare. However, misperception generates utility misoptimization costs which are heterogenous across taxpayers. More able workers are relatively more stricken and thus willing to pay more attention to the tax schedule (e.g. turn to tax advisors). Accounting for the endogeneity of attention reduces the government's ability to exploit misperceptions through tax increases. Nevertheless, our numerical simulations show that optimal tax rates are still higher than with fully-attentive taxpayers. Surprisingly, tax complexity may be welfare-improving and becomes a natural instrument for the government to fuel and exploit taxpayers misperceptions. Instruments multiplicity may generate inattention towards tax instruments with lower rates, while the obfuscation of tax rules and the use of highly non-linear schedules may increase the cost of attention.