Kerning, the process of adjusting the spacing between individual characters in text, is a subtle yet powerful typographic tool that can greatly enhance the readability and aesthetic appeal of web content. While modern web browsers and fonts provide reasonable default kerning, designers and developers often seek more precise control to achieve a polished look, especially for headings, logos, or custom typography. This article explores how to use CSS for custom kerning on websites, diving into what kerning is, why it matters, and practical techniques to implement it effectively.
What is Kerning?
Kerning refers to the adjustment of space between pairs of characters to improve visual harmony. Unlike letter-spacing, which uniformly increases or decreases the space between all characters in a block of text, kerning targets specific pairs of letters. For example, in the word “AVOID,” the space between “A” and “V” might look too wide due to their shapes; kerning adjusts this spacing so these letters appear visually balanced.
Traditionally, kerning was done manually by typographers when setting print type. Today’s digital fonts often include built-in kerning tables with predefined adjustments for common letter pairs. However, these automatic adjustments may not always suit every design context or font choice.
Why Kerning Matters on the Web
Good kerning improves legibility and the overall aesthetic quality of text:
- Enhances Readability: Proper spacing prevents characters from appearing cramped or excessively spaced apart, making reading more comfortable.
- Improves Visual Flow: Balanced letter pairs create a smoother rhythm in text that guides the reader’s eye naturally.
- Elevates Brand Identity: Custom kerning helps create a distinct look for logos and headlines that reinforces brand personality.
- Supports Typography Artistry: Designers can express creativity through nuanced spacing choices for decorative or expressive typography.
Ignoring kerning can lead to awkward letter combinations that distract readers or diminish professionalism. On the web, where fonts may render differently across devices and browsers, achieving consistent kerning presents unique challenges.
CSS Properties Related to Kerning
CSS provides several properties related to controlling spacing between characters:
1. letter-spacing
This property adjusts space uniformly between all characters in an element.
css
p {
letter-spacing: 0.05em; /* Adds slight space between letters */
}
While useful for general tracking (overall character spacing), letter-spacing is not suitable for fine-tuned pair-specific kerning because it applies globally.
2. font-kerning
The font-kerning property controls whether the browser applies font-based kerning information embedded in the font file:
“`css
h1 {
font-kerning: normal; / Enables built-in font kerning /
}
h2 {
font-kerning: none; / Disables font kerning /
}
“`
Values include:
auto: Default behavior; browser decides whether to apply kerning.normal: Explicitly enables font kerning.none: Disables built-in font kerning.
Enabling font-kerning allows fonts with embedded kerning pairs to adjust spacing automatically but does not allow designers to customize individual pair spacing.
3. text-rendering
While not directly controlling kerning, this property hints to the browser how to optimize rendering for legibility or speed:
css
h1 {
text-rendering: optimizeLegibility;
}
Using optimizeLegibility can enable advanced typographic features such as ligatures and kerning in some browsers.
4. OpenType Features via font-feature-settings
OpenType fonts include advanced typographic features like kerning (kern) that can be toggled with this CSS property:
css
p {
font-feature-settings: "kern" 1;
}
Note that support varies across browsers, but enabling this can ensure OpenType kerning is applied if available.
Techniques for Custom Kerning in CSS
Since CSS lacks a native mechanism for targeting specific character pairs with different spacing values, designers must use creative workarounds for custom kerning.
1. Use of span Elements with Adjusted Margins
One common method involves wrapping problematic letter pairs or individual letters in <span> elements and applying margin adjustments:
“`html
AVOID
“`
css
.kerned {
margin-left: -0.1em; /* Move letter closer to previous one */
}
Pros:
- Precise control over specific pairs.
- Simple implementation with basic CSS.
Cons:
- Increases HTML markup complexity.
- Not scalable for large amounts of text.
- May introduce accessibility concerns if overused.
2. Using CSS Variables and JavaScript for Dynamic Kerning
For larger bodies of text or dynamic content, wrapping every pair manually is impractical. JavaScript can assist by automatically scanning text nodes and injecting spans around specified pairs:
“`js
const kernPairs = [‘AV’, ‘To’, ‘WA’]; // Example pairs
document.querySelectorAll(‘h1’).forEach(el => {
let html = el.innerHTML;
kernPairs.forEach(pair => {
const regex = new RegExp(pair, ‘g’);
html = html.replace(regex, <span class="kerned">${pair}</span>);
});
el.innerHTML = html;
});
“`
Then apply CSS as before with margin adjustments.
Pros:
- Automates pair identification.
- Allows dynamic updates based on content changes.
Cons:
- Adds processing overhead.
- Can cause flicker during page load.
- Complexity increases maintenance effort.
3. SVG Text with Manual Kerning
When ultimate control is needed—such as for logos or branding—using SVG <text> elements allows explicit control over each glyph’s position using attributes like dx:
svg
<svg width="200" height="50" xmlns="http://www.w3.org/2000/svg">
<text x="0" y="40" font-family="Arial" font-size="40">
<tspan>A</tspan>
<tspan dx="-5">V</tspan>
<tspan dx="3">O</tspan>
<tspan>I</tspan>
<tspan>D</tspan>
</text>
</svg>
Pros:
- Pixel-perfect control over positioning.
- Ideal for logos and graphic text.
Cons:
- Not practical for body text.
- Less accessible and harder to style responsively.
4. Variable Fonts with Custom Axis Controls
Variable fonts sometimes include axes that influence character spacing dynamically. By adjusting these axes via CSS (where supported), designers can manipulate spacing subtly:
css
h1 {
font-variation-settings: 'wdth' 90; /* Narrower width might affect perceived spacing */
}
While not direct kerning, this technique can complement spacing adjustments by changing glyph widths or weights.
Browser Support and Limitations
Kerning support varies across browsers:
- Modern browsers like Chrome, Firefox, Safari, and Edge generally support
font-kerning, though default values may differ. - The
font-feature-settingsproperty is widely supported but requires knowing specific OpenType feature tags. - Manual span-based approaches work universally but are labor-intensive.
As always, testing across multiple devices and screen resolutions is essential to ensure consistent appearance.
Best Practices for Using Custom Kerning on Websites
-
Enable Built-in Font Kerning: Start by enabling
font-kerning: normaland using high-quality fonts with good built-in tables. -
Limit Manual Adjustments: Reserve manual kerning tweaks for prominent headers or branding elements rather than body copy.
-
Use Semantic Markup Carefully: When injecting extra spans for styling, do so without disrupting accessibility or SEO semantics.
-
Test Responsively: Kerning effects may look different at various screen sizes; verify legibility on mobile devices as well as desktops.
-
Combine Techniques: Use a combination of CSS properties (
font-feature-settings,font-kerning, etc.) alongside manual tweaks when necessary. -
Consider Performance: Avoid excessive JavaScript DOM manipulation that could slow down page rendering.
-
Leverage Variable Fonts: When possible, use variable fonts that provide flexible control over character widths and weights as part of your design system.
Conclusion
Custom kerning remains an essential aspect of refined typographic design on the web. While CSS provides some native properties like font-kerning and letter-spacing, true pair-specific tuning requires creative solutions such as wrapping letters in spans or leveraging SVG text elements. By understanding both the capabilities and limitations of CSS concerning kerning—and combining these with thoughtful design practices—web designers can produce visually harmonious and readable typography that enhances user experience and brand identity alike.
Investing time in custom kerning pays off particularly in large-format headings, logos, and display texts where subtle spacing nuances significantly impact aesthetics. As web typography continues evolving with technologies like variable fonts and advanced OpenType support, future tools may simplify custom kerning workflows further—bringing professional typesetting quality fully into reach of everyday web design projects.
Related Posts:
Kerning
- Tools Every Designer Needs for Perfect Kerning
- How to Measure Kerning Effectively in Digital Fonts
- Best Practices for Kerning in Logo Design
- Using Kerning to Improve Print Layouts
- Advanced Techniques for Perfecting Kerning in Text Design
- How to Automate Kerning Adjustments in Design Software
- Automating Kerning Adjustments in Design Software
- What Is Kerning in Typography?
- Common Kerning Mistakes and How to Avoid Them
- How Kerning Affects User Experience in Mobile Apps
- The History and Importance of Kerning in Typography
- How to Fix Kerning Issues in Adobe Photoshop
- How to Balance Tracking and Kerning for Better Text Appearance
- Kerning Settings for Serif vs Sans Serif Fonts
- The History and Evolution of Kerning in Typography
- How to Use Kerning for Professional Print Layouts
- Optimal Kerning Settings for Different Font Types
- How to Fix Common Kerning Problems Fast
- How to Measure and Test Kerning Accuracy
- How to Teach Kerning Basics to Beginner Designers
- Kerning Tips for Effective Mobile App Design
- How to Use CSS for Custom Kerning on Websites
- Kerning Techniques for Digital Fonts
- Improving User Experience with Proper Kerning
- The Impact of Kerning on Logo Design
- How to Improve Website Typography with Proper Kerning
- Advanced Kerning Methods for Professional Designers
- Best Tools for Kerning Text in Graphic Design
- How to Teach Kerning to Beginner Typography Students
- How to Adjust Kerning for Better Readability