Sunday, May 19, 2024
HomeProgrammingHow to handle special characters in HTML?

How to handle special characters in HTML?

When you paste the URL of a news site or the URL of an online shopping product on an SNS, etc., it may contain symbols such as “%20” that were not in the original URL.
This is called “URL encoding”, and character strings that cannot be used in URLs (double-byte characters, double-byte symbols, etc.) are converted by character code.

Characters that may have an adverse effect when trying to be displayed on HTML are called “special characters”.
In order to handle special characters in HTML, tricks such as conversion are required.
This article describes how to handle special characters.

Table of contents

  • What are special characters in HTML?
  • Using special characters as is
  • How to display special characters as letters
  • Correspondence table of special characters and character codes
    • Escaping HTML tags
    • Code used to create website
    • era names and words
    • Character code for macOS
    • Emoji
  • summary

What are special characters in HTML?

As introduced at the beginning, special characters in HTML are characters that adversely affect the syntax of HTML .
In particular

・”<” and “>” included in HTML tags ・Single
-byte spaces that are ignored in HTML code
・Symbols, marks, pictograms

becomes.

Using special characters as is

If you write special characters as they are in HTML, they may not work as HTML syntax.
For example, let’s say you want to display a string like this:

If you write it like this, it will not be displayed correctly.

This is due to the browser’s ability to detect missing closing HTML tags.
In other words, the previous code would be interpreted by the browser as:

Originally, it would be a convenient function to display even if there is a mistake in the HTML description, but if you want to display the tag intentionally, you should not describe it normally.

How to display special characters as letters

HTML has an “escape string” as a way to display special characters as characters .
As in the previous example, if you want to display tags, write as follows.

<div> &lt;p&gt;はparagraphを意味します。</div>

Now you can see the tags.

In this way, HTML has escaped (converted) character codes corresponding to special characters.

Correspondence table of special characters and character codes

Here are some examples of characters and codes that can be used as special characters.

Escaping HTML tags

display characters code
< <
> >
& &
¥ ¥
half-width space  

Code used to create website

We will introduce codes for special characters that are frequently used when introducing products on websites.

display characters code explanation
© © Copywriter
® ® registered trademark
trademark

era names and words

Special characters such as era names and units defined by the character code Shift-JIS are also defined as codes, so you can express them by using them.
However, please note that these symbols may not be displayed correctly in overseas browsers.

display characters code explanation
Meiji Meiji
meter 6e3d05aa50f6d92917476267306c088b Taisho era
meter cd0c6440ea7f367b452d57af92497b09 Showa
fe0f7a3aed05d7cf456db44ac8c0bf13 Heisei
b415f8af613ee374b5678d603d758821 Reiwa (Note that it is not displayed in old browsers)
44a65ef80740f88f958130a03c799e7c Pico
c13be83913a970495b706f3b2639ff64 Nano
7f66298c32ab10cfc1887cee9313b990 micro
7d4bd4e9bb7619264065194407dced82 mm
kg 30329f02a14ebb70e4c47171d9fc7b49 kilo
f9ded29f3f5b29fbdd7147ebba1f8901 mega
4e5d398fa8610c6e03985816b0e0781d Giga

Character code for macOS

The macOS keyboard uses a different keyboard icon than Windows and Linux.
If you want to create a procedure for macOS, use the following character codes.

display characters code explanation
control control
shift shift
caps lock caps lock
command commands
option options
0fc22081af562baf85890700d4d86055 delete (right)
7dc997fa21de67fb5a88c839b083906c delete (left)
return return

Emoji

Emojis that can be used on SNS can also be displayed as codes.
There are many types of emoticons, so please check the following sites.
You can use it by copying the code in the “HTML Entity” column.

summary

Introduced how to handle special characters in HTML.

  • Characters that may have an adverse effect when trying to be displayed on HTML are called “special characters”
  • Special characters have corresponding character codes called “escape strings”
  • By entering character code, it is displayed correctly in HTML

You don’t have to memorize the character code, but if you need to display characters that cause problems if you use them as they are, it’s a good idea to be able to search for the corresponding character code.

RELATED ARTICLES

Leave a reply

Please enter your comment!
Please enter your name here

Recent Posts

Most Popular

Recent Comments