Embedding Empty Characters into HTML and CSS

Several years ago, if you wanted to use invisible or empty characters in your HTML or CSS code, you’d have to convert them into code sequences with other special characters inside of them. But these days, there are built-in characters that you can put right into your coding, which work in all modern browsers and don’t require escaping or conversion.

What are Empty Characters?

In some circumstances, you might need to insert an empty character into a text string. A simple example is when you’re trying to make a word wrap onto two lines. You can accomplish this by inserting an empty space before the word so that it appears on two lines instead of one. But, just because they’re called empty characters doesn’t mean they don’t have meaning. If you don’t insert them correctly, your website may not display properly.

Embedding empty characters in HTML and CSS is possible. However, there are some caveats. First of all, these entities must be encoded as UTF-8. Second of all, you need to use an XML declaration for XHTML documents or a DOCTYPE declaration for HTML5 documents.

Finally, you should ensure that your editor or IDE is configured correctly so that it doesn’t remove these entities during code editing. If you’re looking for more information on encoding entities in general (not just empty ones), we recommend reading our guide on character encoding and decoding in JavaScript. This will also help if you want to work with other entities like soft hyphens or non-breaking spaces.

Embedding Empty Characters in CSS

CSS has a few tricks up its sleeve for embedding invisible characters within a string of text for use with websites. The most common one is empty-cells, which inserts an empty space into your font.

Steps for CSS

  1. Open your site’s CSS file and a new tab for Google Translate. Copy your foreign text into that new tab and translate it into English. Then copy that translated text back over to what you wrote on your original tab (you can ignore errors from Google), then highlight both bits of the text so they’re selected at once. 
  2. Add a colon followed by empty-cells; into your highlighted code. Save the file and refresh your site’s page. If everything goes well, you should see an empty space where there was previously foreign language.
  3. All you have to do is fill out whatever other details are necessary for that element. But before doing so, make sure to remove or alter any spaces or line breaks within or around it because those will be used as delimiters for empty-cells effect. If you’re using a font from Google Fonts, you’ll also need to convert your text into an image by converting its contents into data: URL format.

The most common use of empty-cells is for languages that read right-to-left (RTL), such as Arabic and Hebrew. To embed these characters into your website’s code, just follow steps 1 through 3 above but replace empty-cells with direction: rtl; instead.

Embedding Empty Characters in HTML

While there are many different ways to embed empty characters into HTML, one of the easiest is through a control character. The control character is an invisible non-printing character that alters or controls transmission between devices. The form feed (Control+L or 0x0C) control character inserts page breaks between printouts of data or documents; they also effectively add empty spaces when inserted into web pages.

Steps for HTML

To insert a form feed, simply type Control+L on your keyboard. It will look like nothing happened, but if you open up your text editor again, you’ll see that it has added an extra line break before your cursor position. This means you can now easily create empty lines within your code by using Control+L repeatedly until you get to where you want it to break at.

After inserting multiple form feeds, you may also need to use a carriage return (Control+M or 0x0D). Some web browsers don’t display newlines correctly when they are inserted into tags with attributes unless a carriage return character precedes them.

If you have trouble remembering these codes, just remember Carriage Return as CR and Form Feed as FF. You’ll remember them much easier than Control+L or 0x0C. You can use a quick shortcut like Alt+C for carriage return and Alt+F for form feed if your keyboard supports it.

HTML in Action

Control characters are invisible, but you can still view them using a web browser’s developer tools. Just open up your browser’s developer tools (Command+Option+I on Mac) and click on Console at the top of the screen.

  • In Chrome, go to View > Developer > Developer Tools from Chrome’s menu bar to open up its own console window.
  • In Firefox, press Command + Option + K or Ctrl + Shift + K on Windows/Linux or Command + Option + K on Mac to open up its console window instead.

Test Your Code

Once you’ve created your custom characters, it’s a good idea to test them before publishing them to your site. The easiest way is to use a simple text editor (like Notepad for Windows or TextEdit for Mac) and type out each character one at a time, then save it as a plain text file. You can also run searches for each character on Google. Alternatively, you can upload your files directly onto FontSquirrel or any other font-sharing site. If everything looks correct, it’s ready for prime time.

If something doesn’t look right, you’ll want to go back and try again. It might take several tries until all of your characters look right, but just know that trial and error are part of the learning process in creating empty characters in HTML and CSS.

Leave a Reply

Your email address will not be published.