--- { title: "Figma to Compose: Line Height & Baseline Grids", description: "A detailed guide on how to make text in Jetpack Compose match your mockups, and why baseline grids are not all that they're hyped up to be.", published: "2023-11-09T04:45:30.247Z", authors: ["edpratti"], tags: ["android", "design"], attached: [], license: "cc-by-nc-sa-4" } --- > **This is an update to an existing article:** > If you haven't yet, check the original article below. > > **[Hard grids & baselines: How I achieved 1:1 fidelity on Android](hard-grids-and-baselines-android-design-fidelity)** For years, the difference between web and native line heights has been a problem for designers. Figma behaves similarly to the web, which ended up being an issue when designing for Android and iOS. In this article I’ll cover how you can now fix this in Jetpack Compose, and make your Android app `TextViews` match your Figma mockups. # Preface For the entirety of this article, I have defined 3 different concepts that will help illustrate the differences between how Figma and Compose draw their text. - `Text vector bounds:` The minimum height required for the text vector. - `Line height:` Defines the height of the line. Figma and Compose perform this differently. - `Text container:` The outer bounds of the text. --- # How Compose works We’ll start with Compose, as it contains more features. Compose has a `lineHeight` attribute, and an `alignment` attribute. These function, by default, as follows.  **From this example, we can notice the following:** 1. If the `lineHeight` value is **smaller** than the minimum bounds of the text vector, it is ignored. In the example above, the minimum height for the text is `24sp`. 2. If the `lineHeight` value is **larger** than the minimum bounds of the text, space is added to fill the desired line height. 3. This extra space can be redistributed with the `alignment` attribute. Compose provides `TOP`, `CENTER` and `BOTTOM` alignment options. --- # How Figma works Here's how setting a line height to a text box behaves in Figma:  1. The line height in Figma can be smaller than the minimum bounds of the text. 2. **Setting a line height in Figma causes the minimum bounds of the text to change to the desired value.** 3. A manually resized text container in Figma, which lets users change the alignment of the line. Let’s look at it further. ## Alignment in Figma In Figma, all text boxes are set to `Hug` by default. This means the text container size is determined by the line height, unlike Compose. **Alignment options have no effect unless the outer container height and the line height differ.** In the example below, we have a text container size that is smaller than the line height.  --- # Baseline grids I [**previously suggested**](/posts/hard-grids-and-baselines-android-design-fidelity) using `firstBaselineToTopHeight` and `lastBaselineToBottomHeight` to apply baseline grid alignment and build matching Figma components. > **I now advise against it.** Originating in print design, baseline grids were useful to define text spacing for a pleasant vertical rhythm. Designers quickly went on the pursuit of baseline alignment and baseline-relative spacing in UIs. > In practice, it means a ton of legwork to move, **at best**, 3 pixels. But let's say you've done the work, and you've now set up all of your text components and paddings in developer handoffs, and you're good to go. What does that mean for your UI? ## Baseline grid alignment with icons To illustrate one of the issues with baseline alignment, let's look at an example where a designer would like to place a baseline-aligned `TextView` next to an icon. The icon is set to `24dp` and the text is set to `16sp`, which, when baseline shifted, gives an overall height of `20sp`. In order to center the label with the icon, the text must be top-aligned.  The problem with this is that, whilst the icon is set to `dp`, the `TextView` scales with text size. When scaled, this is the result.  In most cases, developers will account for this by centering the `TextView` within the layout.  This essentially nullifies the baseline alignment that was put in place. Developers ***can*** fix this by setting the icon to scale off the text size. ## Baseline grid alignment in containers Containers with single-line labels also suffer from visual misalignment when dealing with baselines. Here's a button with all three alignment options; **bottom baseline, line height centering, and top baseline**.  You'll notice that, when dealing with baselines, you may be given situations where it is impossible to maintain alignment while following a baseline grid. These edge cases can be handled individually, but once again, they take significant amount of effort on the part of both designers and developers to fix. The over-engineering for the sake of `~3px` is simply not worth it. **No platform has baseline grid or baseline spacing APIs**, and everything you interact with on a daily basis has been built without it. Baseline grids in interfaces are a solution looking for a problem. ## Takeaways Knowing this, here's a summary of what you should keep in mind when deciding whether to use baseline grids. | Methods | Cons | Pros | |---|---|---| | **Baseline grid alignment** |