How can CSS OpenType be used to substitute a specific letter throughout the text with a character from Stylistic Set 1, while ensuring the rest of the letters remain

Our Objective:
We aim to swap out the two-story lowercase "g" with the single-story version across our entire website text.

https://i.sstatic.net/mqpP9.png

Challenge:
The Rotunda font we use (Rotunda from TipoType Foundry) includes a Stylistic Set 1 with various alternate characters. However, we specifically want to change the lowercase "g" without affecting any other letters.
https://i.sstatic.net/AgumS.png

Paths We've Explored:
While there are CSS OpenType features that promise to target individual letters, our attempts have fallen short. A Reddit post we stumbled upon also grappled with the same issue and proposed a potential solution:

If your font only has one stylistic set, ss01, and you want to change only the lowercase "g" out of the ss01 set, you can use the font-variant-alternates property in CSS. This property allows you to access alternate glyphs in a font.

You can use the following CSS code to access the alternate "g" in the ss01 set:

selector { font-variant-alternates: "ss01" 1; }

You can replace selector with the selector for the element you want to apply the style to. The "ss01" value refers to the ss01 stylistic set of the font. The 1 value refers to the index of the alternate "g" glyph in the ss01 set.

However, determining the actual index number of the lowercase "g" remains a puzzle for us.

An additional resource here suggests using "font-variant-alternates" (stylistic(feature-value-name)), but seems to target letters through selectors like "inscriptional-g". The specific selector for the lowercase in Rotunda font is not known to us.

Our intuition tells us that the solution lies within the font-variant-alternates parameter, yet we struggle to piece together the correct CSS.

---

We experimented with a Javascript approach of wrapping all instances of the lowercase "g" in a span tag to target the character. However, this method proves inefficient and causes a brief "flash" on the page during character replacement. We are in pursuit of a safe, cross-browser (CSS) solution to accomplish this.

Answer №1

Utilizing an alternate style sets can be achieved through @font-feature-values or font-feature-settings.

By leveraging the "IBM Plex Serif" font as an example, we can substitute all instances of "g" with alternate glyphs by opting for the ss02 style set – while keeping "a" occurrences untouched.
This method is effective because the font offers a specific set of alternate glyphs for "g" (including g-diacritics).

In simpler terms: it's not possible to target/replace individual glyphs. If your font only contains a set of alternates – all glyphs within that set will be replaced (including "a" and "g"). Wrapping all "g" instances is the only solution in this scenario.

Exploring stylistic sets

These style sets are not standardized and differ across fonts - hence, you might need to opt for a different style set, such as ss01. You can use the wakamai fondue tool to identify the desired stylistic set along with all alternate features.

https://i.sstatic.net/iX0ZJ.png

@font-face{
  font-family: 'Plex Serif';
  font-weight: normal;
  font-style: normal;
  src : url('https://mdn.github.io/css-examples/font-features/fonts/plex/IBMPlexSerif-Regular.woff')
}

body{
font-family: 'Plex Serif';
font-size:10vmin;
}

@font-feature-values "Plex Serif" {
  @styleset { alt-a: 1; alt-g: 2; }
}

.alt-g{
  font-variant-alternates: styleset(alt-g);
}

.alt-g2{
  font-feature-settings: 'ss02' 1;
}

.alt-a{
  font-variant-alternates: styleset(alt-a);
}

.alt-a2{
  font-feature-settings: 'ss01' 1;
}
<p class="">Hamburg (all standard)</p>

<h3>@font-feature-values</h3>
<p class="alt-a">Hamburg (a alt)</p>
<p class="alt-g">Hamburg (g alt)</p>

<h3>font-feature-settings</h3>
<p class="alt-a2">Hamburg (a alt)</p>
<p class="alt-g2">Hamburg (g alt)</p>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Connecting to a particular destination on an external site

Can I add a link on my website that directs users to a specific location on another website, similar to an anchor tag but without creating the anchor point myself? I have a feeling it might not be possible, but perhaps there is a clever workaround. ...

Modify the styling of the Checkbox within the script template

I am currently working with a list that contains checkboxes, but they are displaying with the default CSS style. How can I change the CSS style of the checkboxes? Below is the code I am using, and I need to modify the CSS of the checkboxes. <div id ...

What is the best way to turn off default CSS styling in KendoUI?

I am facing an issue in my application where I am using global CSS definitions for "INPUT", "SELECT", and other elements. The problem arises when I try to incorporate KendoUI widgets, as they override my default CSS styles. For instance, my CSS code looks ...

Setting table row styles for odd and even rows, based on user clicks of an <input type="file"> button

I'm currently working on a feature that allows users to upload files to a page using an button. Each file is displayed in a table as a new row. I am looking for a way to set the background color differently for odd and even rows. As of now, I am usin ...

Python - Selenium: A guide to locating elements based on color

I have a situation where I need to select only the "Claim" button from the first div, even though both div cases are very similar. Is using background color a good way to identify my element? Or do you have any other ideas? 1. <div class="well well-sm ...

"Enhance your website with a unique Bootstrap 5 carousel featuring multiple

As a beginner in Bootstrap, I am currently working on an ecommerce template to learn about Bootstrap 5. I am interested in creating a carousel that displays multiple slides at once, like a products slider with left and right arrows. Is this possible in Bo ...

The enigmatic borders of a website

While working on a custom Wordpress theme, I encountered an issue where the entire body of the page was slightly pushed down. Using Chrome's inspector tool, I identified the following problematic styles: <style type="text/css" media="screen> ...

Tips on connecting a font directory from FontAwesome

I am currently attempting to incorporate the fonts provided by FontAwesome for their icons, and they specify that a root folder named Fonts is needed. My attempt to link it was using: <link type="text/css" href="/myPath/font" /> ...

displaying the information when we mouse over a specific row in the table

I need to display a pop-up with data from a table row, similar to the image at this URL for CS WHOLESALE GROCERS. I've implemented the following AngularJS code in my controller: app.directive('tooltip', function(){ return { res ...

CSS HTML parent div cannot contain image properly

Creating a website using Bootstrap: <div class="row padding_zero"> <div class="col section px-0"> <img class="img-trans padding_zero" src="./svg/clouds-00.svg" style="margin-top: -150px& ...

How to align a list item to the right using CSS

I'm having trouble aligning items in a list to the right and adjusting their width based on content length. Unfortunately, I haven't been able to make it work despite multiple attempts. Take a look at my code snippet below: .messages { over ...

Discovering the screen width and increasing its value using CSS

Is there a way to determine the screen size and then add 253px to it? For example, in CSS: .element { width: calc(100% + 253px); } What would be the best approach to achieve this? ...

Implement a jQuery slideshow with a full background image, aiming to set up a clickable link on the final image of the

Could someone please help me with a query I have regarding a background image slide show using jQuery code? I have set up a slide show with multiple images and would like to make the last image clickable. Is it possible to achieve this specific functionali ...

Repairing the Left-sided Popup Leaflet

Can someone help me with fixing the positioning of the Popup to the left of the map? Currently, it does not stay aligned to the left edge when moving the map. I tried using position: fixed in my styling, and while everything looks good when zooming, it br ...

Overlaying Div Concealed by Background Video Filter

Whenever we add a filter to our background video, the div overlay ends up moving behind the video and becoming hidden. To see an example of this issue, check out this fiddle showcasing the background video with the text overlay: https://jsfiddle.net/dyrepk ...

Using a background image from your own website does not display anything, but using an image from an

It's really strange from where I'm standing. I'm working on a website and trying to set up a banner with a background image using the background-image property. The issue I'm facing is: when I use two images with the same dimensions, ...

Display an image with only a portion visible, no canvas, no frame, and no need

My dilemma involves an img with a surrounding box div. http://jsfiddle.net/6d4yC/7/ 1) I am seeking to display only a portion of the image (250x150) without generating a white overlay when it is in its large size. Placing a #box1 div around the image has ...

Ionic: Fixed button located at the bottom of a specific ion-slide

I've been creating a series of slides with questions, and the final slide serves as a summary of the previously answered questions. I want to ensure that the submit button is always visible at the bottom of this last slide. However, I've encounte ...

Utilizing a ListView Below a LinearLayout: Step-by-Step Guide

In my Android project, I am working on creating the MyProfile activity. This activity will display a user's profile picture, name, and other bio data on the first screen. Additionally, I would like to make the layout swipeable so that when the screen ...

The simplest method for integrating SASS within your WordPress website

While I usually work with CSS, I've decided to tackle SASS in order to improve my efficiency. I successfully converted a CSS file from .css to .scss and it still works as expected. However, when I added variables, they didn't function properly. ...