Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I properly display German characters in HTML?

My pages contain German characters and I have typed the text in between the HTML tag, but the browser views some characters differently. Do I need to include anything in HTML to properly display German characters?

<label> ausgefüllt </label> 
like image 566
venkatachalam Avatar asked Jan 08 '09 09:01

venkatachalam


People also ask

Can UTF 8 handle German characters?

As for what encoding to use, Germans often use ISO/IEC 8859-15, but UTF-8 is increasingly becoming the norm, and can handle any kind of non-ASCII characters at the same time. UTF-8 is actually quite common in Germany now and can make all the difference when using German text.

How do you type special characters in German?

There is an easy way to write the German characters ä ö ü and ß on a non-German keyboard. Press NUM on the number pad of your keyboard to activate the NUM-lock. Then press ALT and keep it pressed while you type the code 132 on the number pad. 132 is the code for the letter ä, the a umlaut.

Does German have special characters?

German has four special letters; three are vowels accented with an umlaut (⟨ä, ö, ü⟩) and one is a ligature of ⟨s⟩ and ⟨z⟩ (⟨ß⟩; called Eszett "ess-zed/zee" or scharfes S "sharp s"), all of which are officially considered distinct letters of the alphabet, and have their own names separate from the letters they are ...


2 Answers

It seems you need some basic explanations about something that unfortunately even most programmers don't understand properly.

Files like your HTML page are saved and transmitted over the Internet as a sequence of bytes, but you want them displayed as characters. In order to translate bytes into characters, you need a set of rules called a character encoding. Unfortunately, there are many different character encodings that have historically emerged to handle different languages. Most of them are based on the American ASCII encoding, but as soon as you have characters outside of ASCII such as German umlauts, you need to be very careful about which encoding you use.

The source of your problem is that in order to correctly decode an HTML file, the browser needs to know which encoding to use. You can tell it so in several ways:

  • The "Content-Type" HTTP header
  • The HTML META tag
  • The XML encoding attribute if you use XHTML

So you need to pick one encoding, save the HTML file using that encoding, and make sure that you declare that encoding in at least one of the ways listed above (and if you use more than one make damn sure they agree). As for what encoding to use, Germans often use ISO/IEC 8859-15, but UTF-8 is increasingly becoming the norm, and can handle any kind of non-ASCII characters at the same time.

like image 121
Michael Borgwardt Avatar answered Oct 08 '22 21:10

Michael Borgwardt


UTF-8 is your friend.

Try

<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8"> 

and check which encoding your webserver sends in the header.

If you use PHP, you can send your own headers in this way (you have to put this before any other output):

<?php header('Content-Type: text/html; charset=utf-8'); ?> 

Also doublecheck that you saved your document in UTF-8.

like image 33
Karsten Avatar answered Oct 08 '22 21:10

Karsten