index.rst (12535B)
1 ========== 2 Edit fonts 3 ========== 4 5 6 This article provides a tour of the Font tools available in the Firefox DevTools. This tool contains several useful features for viewing and manipulating fonts applied to any document loaded in the browser including inspection of all fonts applied to the page, and precise adjustment of variable font axis values. 7 8 9 The Fonts tab 10 ************* 11 12 The Fonts tab is located on the right-hand side of the :doc:`Page Inspector <../../index>` when it is docked to the bottom of the screen. When it is docked to the right or left sides of the screen, the Fonts tab appears beneath the HTML pane. To access it: 13 14 15 1. :doc:`Open the Page Inspector <../open_the_inspector/index>`. 16 2. Select the Fonts tab; the last of the tabs shown in the right-hand side of the CSS pane. 17 18 .. image:: full-fonts-tab-new63.png 19 :class: border 20 21 22 The Fonts tab has three major sections: 23 24 - "Fonts used" by the currently inspected element. 25 - The Fonts Editor. 26 - "All fonts on page" — This section lists all of the fonts in use on the page. 27 28 29 Fonts used 30 ********** 31 32 The top section of the Font Editor shows the fonts used by the currently inspected element, grouped by font family. 33 34 .. image:: fonts-used.png 35 :class: border 36 37 Fonts are considered "used" when there is text content in the inspected element that has the font applied to it. Empty elements will not have any fonts used and will display the message "No fonts were found for the current element." 38 39 Fonts will be included in this section for one of the following reasons: 40 41 42 - They are listed in the element's ``font-family`` CSS declaration value. 43 - They are applied to the element as part of the browser's default styling (Times New Roman for most browsers), and no author-defined font has been supplied. 44 - They are used by a descendant of the inspected element, for example, when it is a container for other elements which have text content with fonts applied. 45 - They are system fallback fonts used when nothing from the ``font-family`` CSS declaration has been applied. 46 47 48 Fonts Editor 49 ************ 50 51 The Font Editor has additional controls for editing the fonts’ characteristics. 52 53 .. image:: fonts-editor-closeup-63-cropped.png 54 :class: border 55 56 57 For standard (static) fonts, you will be able to change the settings listed below 58 59 60 Size 61 ---- 62 63 The `font-size <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-size>`_ for the inspected element. 64 65 .. image:: font-size_cropped.png 66 :class: border 67 68 69 This can be set using ``em``, ``rem``, ``%``, ``px``, ``vh``, or ``vw`` units. You can select values using the slider or enter a numeric value directly into the text box. 70 71 .. note:: 72 If you want to use a different unit such as ``pt`` for ``font-size`` or ``line-height``, you can set the property value applied to the currently inspected element to use that unit via the :ref:`rules view <page_inspector_ui_tour_rules_view>`, and the font editor will automatically pick it up and make it available in the associated units dropdown menu. 73 74 75 Changing the unit of measure converts the numerical value to its equivalent in the new unit, so the same computed value is maintained. 76 77 Example: If ``1rem`` is equivalent to 10 pixels, when you change the unit of measurement from ``rem`` to ``px``, ``2rem`` becomes ``20px``. 78 79 80 Line height 81 ----------- 82 83 The `line-height <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/line-height>`_ of the inspected element. 84 85 .. image:: line-height_cropped.png 86 :class: border 87 88 89 This can be set using unitless, ``em``, *%*, or ``px`` units. You can select values using the slider or enter a numeric value directly into the text box. 90 91 Changing the unit of measure changes the value relative to the ``font-size`` setting. 92 93 Example: If the font is 20 pixels high and the line-height is ``1.5em``, when you change the unit of measure from ``em`` to ``px``, the value will become ``30px``. 94 95 96 Weight 97 ------ 98 99 The `font-weight <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-weight>`_ for the inspected element. 100 101 .. image:: font-weight_cropped.png 102 :alt: Font weight setting 103 :class: border 104 105 106 You can select values using the slider or enter a numeric value directly into the text box. For non-variable fonts the slider ranges from 100 to 900 in increments of 100. 107 108 .. note:: 109 For `variable fonts <https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Fonts/Variable_fonts>`_ (see below) that define a ``wght`` variation axis, this range is custom. 110 111 112 Italic 113 ------ 114 115 The `font-style <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-style>`_ for the inspected element. 116 117 .. image:: font-italic_cropped.png 118 :class: border 119 120 121 This setting toggles between ``italic`` and ``normal`` values for the ``font-style`` CSS property. 122 123 .. note:: 124 125 As you change settings, Firefox applies inline styles to the element to make the changes instantly visible on the page. 126 127 128 All fonts on page 129 ***************** 130 131 The remaining area, at the bottom of the Fonts tab, shows an expandable list of all of the fonts in use on the page. 132 133 .. image:: all-fonts-on-page_new63.png 134 :class: border 135 136 137 The list is useful because you can easily determine whether a font is a web font or a font hosted on your system. 138 139 Each font listed in this section shows you: 140 141 142 - The ``font-family`` identifier and full name of the font. 143 - The URL to the font file in the case of web fonts not available on your system, or "System" in the case of fonts loaded from your computer (either default system fonts, or web fonts that you've also got installed on your system). You can copy the URL to the font file by clicking on the icon to the right of the URL. 144 - The `@font-face <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@font-face>`_ descriptor that loads the font into the page, in the case of web fonts. The descriptor is expandable — when opened it shows its full syntax as defined in the stylesheet. 145 - A text sample, to give you an idea of what the font looks like when rendered. The default text for the sample is "Abc" but the preview text can be edited by clicking on the input field at the top of the section and entering a new value. Once entered, all of the sample text will be set to the same custom value. 146 147 148 Variable font support in Firefox Developer Tools 149 ************************************************ 150 151 You can editing the properties of variable fonts in the Font Editor. 152 153 What are variable fonts? 154 ------------------------ 155 156 `Variable Fonts <https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Fonts/Variable_fonts>`_, or **OpenType Font Variations**, define a new font file format that allows the font designer to include multiple variations of a typeface inside a single font file. That means you no longer have to apply several different web fonts to a single page to represent a complete typeface for which a variable font is available, provided it includes the desired values for the different characteristics you want to vary. 157 158 Variable fonts make it easy to vary font characteristics in a much more granular fashion because their allowable ranges are defined by **axes of variation** (see `Introducing the 'variation axis' <https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Fonts/Variable_fonts#introducing_the_variation_axis>`_ for more information). For example, `font-weight <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-weight>`_ can be set to any value between 1 and 1000 in variable fonts (although it is not guaranteed that a variable font will support this entire range). 159 160 There are several registered axes. Although it isn't required that these axes be defined for every font, if the font designer *does* implement a registered axis, its behavior *must* follow the defined behavior. 161 162 All variable font axes have a four-character axis tag. The CSS `font-variation-settings <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-variation-settings>`_ property uses the tag as part of the key-value pair. For example, to set `font-weight <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-weight>`_ using ``font-variation-settings``, you could do something like this: 163 164 165 .. code-block:: css 166 167 font-variation-settings: "wght" 350; 168 169 170 However, you should only use ``font-variation-settings`` as a last resort if there is no basic font property available for setting those characteristic values (e.g. custom axes). 171 172 .. note:: 173 Font characteristics set using ``font-variation-settings`` will always override those set using the corresponding basic font properties, e.g. ``font-weight``, no matter where they appear in the cascade. 174 175 176 Here are the registered axes along with their corresponding CSS properties: 177 178 179 .. list-table:: 180 :widths: 40 60 181 :header-rows: 1 182 183 * - Axis Tab 184 - CSS Property 185 186 * - "wght" 187 - `font-weight <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-weight>`_ 188 189 * - "wdth" 190 - `font-stretch <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-stretch>`_ 191 192 * - "slnt" (slant) 193 - `font-style <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-style>`_: ``oblique + angle`` 194 195 * - "ital" 196 - `font-style <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-style>`_: ``italic`` 197 198 * - "opsz" 199 - `font-optical-sizing <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-optical-sizing>`_ 200 201 202 Any axis that is not on the list of registered axes is considered a custom axis. Custom axes do not have corresponding CSS font properties. Font designers can define whatever axis they want; each one needs to be given a unique four-character tag. The axis name and its range is up to the font designer. 203 204 .. note:: 205 Registered axis tags are identified using lower-case tags, whereas custom axes should be given upper-case tags. Note that font designers aren't forced follow this practice in any way, and some won't. The important takeaway here is that axis tags are case-sensitive. 206 207 208 .. warning:: 209 In order to use variable fonts, you need to make sure that your operating system is up to date. For example Linux OSes need the latest Linux Freetype version, and macOS prior to 10.13 does not support variable fonts. If your operating system is not up to date, you will not be able to use variable fonts in web pages or the Firefox Developer Tools. 210 211 212 Working with Variable fonts in the Font Editor 213 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 214 215 If the inspected element uses a variable font, the Fonts tab shows the axes that have been implemented for that particular font, providing control to alter the value of each one. This is very useful for quickly finding out what axes are available in a particular font — they can vary quite dramatically as font designers can implement basically anything they like. 216 217 .. image:: v_fonts_example_cropped.png 218 :class: border 219 220 221 You can adjust the axes individually or, if the font designer has included defined instances, you can select one from the "Instance" drop-down list and view the updates live on your page. 222 223 Here are a couple of examples of fonts with different axes defined: 224 225 .. image:: v_fonts-examples_cropped.png 226 :class: border 227 228 229 In the following example, you can see that the font "Cheee Variable" includes settings for Yeast and Gravity. These are custom axes defined by the font designer. 230 231 .. image:: change_font_before_cropped.png 232 :class: border 233 234 235 The first image shows the font as it is used on the page with default settings. The second image shows the same font after selecting the "Hi Yeast Hi Gravity" variation. 236 237 .. image:: change_font_after_cropped.png 238 :class: border 239 240 241 Tips 242 **** 243 244 Finally, here are a few tips for making effective use of the Fonts tab: 245 246 247 - When using the Page Inspector's :doc:`3-pane mode <../../3-pane_mode/index>`, you can view the CSS rules for the inspected element simultaneously alongside the Fonts tab. 248 - If you hover over the `font-family <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/font-family>`_ property in the Rules view, a tooltip shows a sample of the font: 249 250 .. image:: fonts_62_tooltip_cropped.png 251 :class: border 252 253 - You'll also notice in the above screenshot that the font in the ``font-family`` font stack that is actually applied to the inspected element is underlined. This makes it easy to see exactly what is being applied where, when font stacks are specified.