Require that double-width unicode symbols are displayed as double-width in Markdown or CSS

I am seeking a solution to manage the visual width of double-width unicode characters like the LARGE ORANGE SQUARE 🟧 within Github-flavored Markdown. I am open to using either Markdown code or Html/CSS for this purpose.

An illustration of the issue can be seen in the following Markdown code snippet, which fails to display correctly on Brave browser running on MacOS (Chromium 105, MacOS 12.6 as of 2022-09-27):

                        1 3 5 7 9
single width reference  ↓ ↓ ↓ ↓ ↓
double width unicode    đŸŸȘđŸŸ«đŸŸ©đŸŸȘđŸŸ«đŸŸ©đŸŸȘđŸŸ«đŸŸ©
double width reference  ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
                        1 2 3 4 5 6 7 8 9

The double-width characters appear misaligned within the monospaced grid, making them unsuitable for use in box drawing or game rendering within this context.

While these characters render correctly in system terminals like iTerm2 or the VSCode terminal, they encounter issues when viewed in web browsers, suggesting a Markdown/CSS/Html discrepancy likely related to website fonts and browser settings.

Inquiries:

  1. How can I exert precise control over the width of double-width Unicode strings within Markdown code sections?
  2. Are there alternative methods to ensure proper rendering, particularly on platforms like Github?

Answer №1

Insights

Up to October 2022, there appears to be no direct method for controlling the width of rendered fonts. However, there are potential workarounds available.

Through various comments and feedback, the following observations and current state have been noted:

  • In terminals, characters are always rendered onto a grid, regardless of their actual width. If a character has a length greater than 1, it may occupy more than one grid unit.
  • Web browsers render characters based on their visual length, even within <pre> tags and when using monospaced fonts.

Both in browsers and terminals, font sizes can impact grid behavior, leading to unpredictable rendering of wider unicode characters in code, gaming, or artistic sections.

Examples of misaligned block characters next to correctly rendered "↑ " indicators in monospaced format are provided below:

Font Size Rendering
"h1"

đŸŸȘđŸŸ«đŸŸ©đŸŸȘđŸŸ«đŸŸ©đŸŸȘđŸŸ«đŸŸ©

↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑

"p"

đŸŸȘđŸŸ«đŸŸ©đŸŸȘđŸŸ«đŸŸ©đŸŸȘđŸŸ«đŸŸ©

↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑

"sup"
đŸŸȘđŸŸ«đŸŸ©đŸŸȘđŸŸ«đŸŸ©đŸŸȘđŸŸ«đŸŸ©

↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
Reference Image

It appears that smaller font sizes adhere better to the grid defined by standard monospaced characters. Nevertheless, this is not a guaranteed solution.

Solutions

Opt for single-width alternatives. Avoid non-standard width characters in your code, games, or artwork. Many emoji characters display well in monospaced text, ensuring compatibility across terminals and browsers. For instance, use common single-width characters like ░ ▒ ▓ █ instead of irregular-width options. Terminal coloring with escape codes can enhance visual appeal.

Avoid mixing widths. Stick to characters of consistent visual width when creating art or designs. For example, the đŸŸȘ blocks align nicely with the double-width space character  :

đŸŸȘđŸŸȘđŸŸȘă€€đŸŸ©đŸŸ©đŸŸ©
đŸŸȘă€€ă€€ă€€ă€€đŸŸ©

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

Utilizing CSS in Angular applications

I am currently working on an Angular 2 application and I am fairly new to Angular. I am facing an issue where my CSS does not seem to be applying properly. There are three key files involved: landing.component.html landing.component.scss landing.compone ...

Header text aligned with image to accommodate parent size

Having trouble aligning an image/logo next to my header text while maintaining its aspect ratio and fitting within the container size. The goal is to have both the text and image horizontally centered. The parent div cannot have a fixed height as it needs ...

Eliminate any unnecessary spaces in the text of a link following the breaking of a word

While working on a navigation menu, I noticed that in large screens the navigation looks fine but in laptop view, the words are breaking up and it's acceptable. However, I want to remove the extra spacing after the text. In the large screen: In the ...

Utilize a personalized container for the slider's thumb within a React application

Is it possible to replace the slider thumb with a custom container/div in React instead of just styling the thumb or using a background image? I have found a codepen example that demonstrates what I am trying to achieve, but unfortunately I am having trou ...

Populate the div with the URL parameter only when another span element is empty after a specified time interval using setTimeout

When displaying a person's name on a page, there are two different methods to consider. It can be extracted from the URL or retrieved from an email form in the CMS used. However, these two approaches sometimes conflict with each other. Currently, I h ...

Is there a way to create an input field that accepts only numbers and behaves like a password field simultaneously?

I am attempting to develop an input field for entering a PIN. I would like the PIN to be masked on mobile devices, similar to how passwords are obscured in password input fields. I came across a suggestion on stackoverflow regarding this, but unfortunately ...

Achieving a frosted glass effect for your background without relying on a background image

I am currently working on creating a modal window in React with a blurred backdrop. My goal is to blur the backdrop content while keeping the background image clear, as there is no image behind the modal window, just content. I have explored various soluti ...

Every time I attempt to visit my website on a mobile device, it seems to appear larger than normal, as

After developing a responsive website and adding media queries to make it mobile-friendly, I encountered an issue. Despite my efforts, the website's width is still larger than the mobile viewport, requiring users to zoom out to view it properly as sho ...

Minimize the width to display a scrollbar

Check out this page: where you'll find the same code snippet displayed twice - once through GitHub Gist embedding and the second using Jekyll's internal syntax highlighter Rouge. I'm currently working on styling the second code snippet to m ...

Resolving the issue of the 'Failed to load resource: net::ERR_FILE_NOT_FOUND' error

I'm encountering issues with loading my CSS in different browsers when using the "Copy Path" feature in VSCode. While everything displays correctly in preview mode within VS, none of the styles appear when pasting the path into Chrome or Edge. Below ...

unable to obtain desired font in the final result

I have encountered an issue where the certificate theme I am storing in the database as HTML appears fine in the browser output, but when fetched and displayed in a PDF format, the normal font output is shown instead. I am unsure of what I might be doing w ...

How I made my WordPress columns automatically resize with the help of Bootstrap

Currently, my Wordpress template utilizes Bootstrap 2.3.1 with two areas set up using SPAN4 and SPAN8. The resolution is fixed at 1170px, so there's no need to configure the lg component of Bootstrap. I'm looking for assistance in properly confi ...

What could be the reason for the container div's height not being properly refreshed?

When adding elements to a container div with an initial height of 'auto', I assumed that the height would adjust based on the children elements added. However, this is not happening. Can anyone assist me in ensuring that the container div's ...

CKeditor does not accept special characters or diacritics in keywords

Recently, I came across a helpful code snippet for CKeditor that counts and ranks the most used words in a textarea. This feature is invaluable for generating SEO-keywords suggestions while writing articles. However, there is an issue with non-English char ...

Transitioning the style code from inline to the head of the document disrupts the straightforward JavaScript intended to

As I delve into the world of web development, I encountered a simple issue that has been causing me frustration for the past hour. It involves code to display the border color of a div element using an alert. The code works perfectly fine when the style is ...

Tips for implementing automatic line wrapping in a PDF document using React-PDF

I am experiencing an issue with a PDF rendering where very long words are not wrapping onto a new line, instead overflowing the container and disappearing off the page. Below is the setup causing this problem. The styles are listed followed by the actual ...

What is the reasoning behind utilizing the "&" selector in CSS?

.navigation { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: translation: all ease 0.25s; &.expand { transform: translateX(0); } } JavaScript file: $(document).ready(func ...

What are the reasons behind the ineffectiveness of !important in CSS?

I am looking to increase the font-size of all text on my website to 200%, you can find some test code in this Fiddle link. If it is a PX issue, why does the code work when I add the style to "<h2>"? <div> <h2 class="test" style="font-size:300 ...

What is the best way to change the height of a div element as the user scrolls using JavaScript exclusively?

Coding with JavaScript var changeHeight = () => { let flag = 0; while(flag != 1) { size += 1; return size; } if(size == window.innerHeight/2){ flag == 1; } } var size = 5; document.body.style.height = &qu ...

The white-space property disrupts the normal width of elements

My initial goal was to stack two elements together side-by-side, both taking the full available height. One element has a fixed width of 200px with an image (70px wide) inside, while the other element should only fit one line of text, clipping any overflow ...