30

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>
GEOCHET
  • 21,119
  • 15
  • 74
  • 98
venkatachalam
  • 102,353
  • 31
  • 72
  • 77

9 Answers9

76

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:

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.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720
  • You should alter the order: 1. HTTP header field, 2. XML declaration, 3. HTML META element. See http://www.w3.org/TR/html401/charset.html#h-5.2.2 and http://www.w3.org/TR/xml/#charencoding – Gumbo Jun 13 '09 at 13:05
  • 1
    UTF-8 is actually quite common in Germany now and can make all the difference when using German text. If ISO/IEC 8859-15, doesn't work you should definitely try UTF-8 as the next option. – Phill Healey Jan 20 '15 at 09:48
  • 1
    @PhillHealey 6 years later again, I'd say UTF-8 should now normally be the first thing to use. – Michael Borgwardt Feb 09 '22 at 10:00
  • @MichaelBorgwardt 11 hours later... Yes, I agree. ;-) – Phill Healey Feb 09 '22 at 21:20
36

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Karsten
  • 14,572
  • 5
  • 30
  • 35
  • I have already added in My head tag,Still i got the hidden character – venkatachalam Jan 08 '09 at 09:47
  • then your document is probably not in fact saved in UTF-8 – Michael Borgwardt Jan 08 '09 at 10:00
  • You need the proper header to be sent from the webserver. The META tag won't be enough – Gareth Jan 08 '09 at 10:37
  • Explanation: originally, it was intended that the webserver would parse the file and set its headers according to the tags, but webservers generally don't, and it's not specified how the browser should behave if they disagree. – Michael Borgwardt Jan 08 '09 at 13:03
  • @brazzy: it is specified in detail: http://www.w3.org/TR/REC-html40/charset.html#spec-char-encoding and there are a few FAQ/QA articles on W3C website about this. – Kornel Jan 08 '09 at 13:12
11

Try the solution in blog post German characters encoding issue (2012-05-10):

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
tulasidhar
  • 119
  • 1
  • 2
8

Have you tried &uuml; (ü) and &Uuml; (Ü)?

You can find how to type other letters here.

Göran Lilja
  • 625
  • 2
  • 5
  • 17
3

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

and when saving the file, for example in notepad, choose the save as to be UTF-8 and not just .txt.

This should render the characters ok.

Kieran
  • 31
  • 1
3

you may try utf8_encode() or utf8_decode() functions.Check if any of these works.

For example <?php echo utf8_encode('ausgefüllt'); ?>

Hope it will work.

Hriju
  • 728
  • 1
  • 16
  • 27
2

Sounds like a character encoding issue, in that the file is saved as a different character encoding to what the webserver is saying it is.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
2

I don't like the use of HTML entities (like %uuml;), they are only needed when there is something wrong with your characterset.

In short:

The RIGHT way is to fix your characterset.

The EASY way is to just use entities. You may not ever see any problems with this.

Tracking down characterset error can be very difficult. If you give us an URL where we can see the problem, we can probably give you a good hint where to look.

myplacedk
  • 1,574
  • 2
  • 14
  • 19
1

enter image description here

save as your file with UTF8, and use this META:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
Eyni Kave
  • 1,113
  • 13
  • 23