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 https://i.sstatic.net/I2rPp.png

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

Certain rows appear to be missing even though they are present in both the webpage and its corresponding source code

I am facing a CSS issue that I am unable to resolve. I have 20 results that should be displayed on my website, but only 14 of them are appearing. The other ones are visible in the source code when inspected. When I move the position of the menu up or down, ...

"Troubleshooting: Why isn't my Tailwindcss box shadow

I'm currently incorporating Tailwindcss into a React project to recreate the Star Wars website mobile menu. However, I am facing an issue where the box shadow added to the hamburger icon segments is not visible when the navigation drawer is opened. A ...

Arranging React Grid Items with Stylish Overlapping Layout

Is there a way to create a react-grid-layout with 100 grid points width, while ensuring that the grid items do not overlap? (Reducing the number of columns can prevent overlap, but sacrifices the 100-point width resolution for grid placement) import Butto ...

Using jQuery to make an element follow you as you scroll down a page inside a div

I've made some progress on my code: HTML <div id="header"></div> <div id="content"> <div class="sidebar-wrapper"></div> </div> <div class="session-wrapper"></div> <div id="footer"></div> ...

Struggling to add custom styles to an Ionic radio button

I'm struggling to adjust the position of the icon in an Ionic radio button so that it sits a bit higher, but I can't seem to figure out how to do it. Below is the code snippet for reference: // HTML <ion-radio class="radio-input" mo ...

Optimizing HTML/CSS performance: Comparing flexbox and tables for handling extensive datasets

Creating a React table component with hundreds of lines and variable cell widths can be complex. Would it be better to implement this using flexbox or a traditional table structure in HTML/CSS? ...

Creating a radial gradient texture using CSS

I'm encountering an issue with my radial gradient and texture combination. Here is the code snippet I am using: background-image: url('../img/texture.png'); /* fallback */ background: -moz-radial-gradient(rgba(253,253,253,0.1) 0%, rgba(2 ...

CSS3 rotation animation - begins to rotate and then halts at a specific angle

I attempted to develop a function that initiates a spin, replaces an image, and then stops the spin. However, when I remove the spin class, it jerks abruptly. How can I halt the spinning smoothly at a specific frame? setTimeout(function() { $('. ...

Switch up text using jQuery on css-tricks.com

I am having trouble with the code I found on a page about toggling text using jQuery from this link. Could someone please explain to me the significance of ':visible'? Thank you. Here is the fiddle link, and below is the code that I copied. Vi ...

Aligning three hyperlinks evenly to spread across the webpage

My professor provided the class with an image that may resemble something he could ask us to recreate on an upcoming exam. He suggested we try replicating it at home to study. I have most of it figured out, but there are three links positioned perfectly ac ...

In Android Kitkat 4.4.4, the Ionic navbar displays icons vertically when using the <ion-buttons end> feature

When viewing in the browser with ionic serve, everything looks fine. However, on an Android Kitkat device running version 4.4.4, the buttons on the right side of the navbar are displaying vertically instead of horizontally. <ion-navbar> <ion-ti ...

How can you adjust the width of the Material UI Select component?

Trying to customize the width of the Material UI Select component can be a bit tricky. To set the desired width, you need to assign a specific class to the FormControl component. This class, such as mw-120, should define the minimum width as 120px in your ...

What is the best way to maintain the position of components (such as a Card component) when one is expanded in a Material-UI and ReactJS project

Currently, I am working with an expandable Card component from Material-UI and using flex for aligning the components. However, when one card expands, it affects the positioning of the other components in the row: https://i.stack.imgur.com/vGxBU.png What ...

Switching the background image upon hover while incorporating a subtle fade transition in HTML and CSS

Is there a way to set two background images on a div and have them change when hovering with a fade effect? Similar to the example shown. .kid { max-width:50%; position:relative; } .kid img { display:block; opacity:1; height: auto; transition:.6s ease; ...

Triangles without their pointed tips

The left arrows next to the carousel blocks are missing their tips. I'm not sure what else needs to be added in the CSS to complete the triangle shape. Here is the live URL: (located next to the large image, specifically in the information carousel) ...

Sidebar collapse using Bootstrap

I have been working on creating a collapsible sidebar that pushes the content on the right, but I'm facing issues with responsiveness. When I display the sidebar, the content is getting compressed instead of pushed. I tried adding flex-shrink-0 to the ...

Unexpected Results from Div Positioning

Here is the PHP code snippet I am working on: <?php include 'header-adminpanel.php'; ?> <div class="container"> <div class="body-content"> <div class="side-left"><?php include 'adminproduct_sidebar.ph ...

Attempting to position items within a container

Currently, I am in the process of creating a list of job opportunities to be displayed on a side bar of our careers page. Each job listing should include the job title along with an apply button enclosed within a rounded grey box that allows for some spaci ...

The CSS properties intended for ion-button elements are not taking effect

I'm attempting to set a background color when a ion-button is clicked or maintain the ion-ripple effect after it has filled the button in Ionic 4. I experimented with applying custom CSS states in global.scss, but encountered issues where the active ...