I'm getting an HTML validation error for the following line, I'm not sure where I should specify my charset if I don't do it within the meta tag.
Line 5, Column 70: Attribute charset not allowed on element meta at this point.
<meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
This is because you put it in a Content-type meta tag, this is not allowed.
simply make a seperate meta tag, e.g.
<meta charset="utf-8" />
this should validate for you.
Yes. You should use as this is recommended in html5 and it is a new recommendation.
Below is a simple html5 layout:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
Content of the document......
</body>
</html>
Related
Can anyone explain the difference between the different html options show in the vscode screenshot below? When to use each one. Thanks!
For me, html and html:xml only generate the opening and closing html tags.
html generates <html></html>
html:xml generates <html xmlns="http://www.w3.org/1999/xhtml"></html>
But html:5 generates a basic boilerplate for any html5 compatible html file. It contains some basic stuff like, doctype, head, body, title tags etc.
html: create only <html></html> tag
html:5 : create a basic html 5 template as below
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
html:xml : Usually a <!DOCTYPE> declaration is used to distinguish between versions of HTMLish languages (in this case, HTML or XHTML). More detail about it
I am curious about the relationship between DOCTYPE and charset in an HTML 5 file.
Using the default HTML template in VSCode produces the following markup:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<script src="main.js"></script>
</head>
<body>
</body>
</html>
My question is, do we need both DOCTYPE and charset?
If the doctype is set to html (which refers to HTML 5), and we know that utf-8 is the default charset for HTML 5, do we have to specify the charset using the meta tag or does the browser know?
My question is, do we need both DOCTYPE and charset?
Yes
If the doctype is set to html (which refers to HTML 5), and we know that utf-8 is the default charset for that doctype
It isn't. Browsers perform complex sniffing to determine the character encoding. Specifying it explicitly is more reliable.
It is a good rule to prepare your website for most browsers and platforms.
The use of both will garantee that most technologies can read all they need to represente your site.
So yes... rule of thumb.... always add default preferences in your code, just in case.
Best regards.
The <!DOCTYPE html> declaration is used to inform a website visitor's browser that the document being rendered is an HTML document.
<!DOCTYPE html> is doctype of html 5.
#charset specifies the character encoding used in the style sheet, and <meta charset="utf-8" /> specifies the encoding for the HTML document
I feel really stupid, but I can't for the life of me find my title or meta tags in my source code. It just starts out
<!DOCTYPE html>
<head>
.....
</head>
<body>
...
and then continues like that. I know my title is set, because it's displaying in my tab. This link (https://help.yahoo.com/kb/yahoo-web-hosting/SLN18260.html?impressions=true) tells me the meta tags should be right under the title. So where is the title??? I just want to make sure my meta tags are printing as expected.
UPDATE:
Weird, I just found them like halfway down the page, way outside my <head>. I don't know what they're doing there, but at least I found them.
This is the procedure,
<!DOCTYPE HTML>
<html>
<head>
<title>...</title>
<meta charset="UTF-8">
<meta name="keywords" content=".." /> //if needed
<meta name="description" content=".." /> //if needed
</head>
<body>
.....
</body>
</html>
The <title></title> should be inside the <head></head> block.
Code does not automatically generate tags. Thus, to create a title and meta tag, just initiate them below the head (following convention):
<!DOCTYPE html>
<head>
<title>My Website</title>
<meta charset="UTF-8">
</head>
<body>
</body>
a proper HTML structure should be like..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>My title</TITLE>
</HEAD>
<BODY>
......
</BODY>
</HTML>
HERE is the reference to get more ideas about HTML.
I want to display a special caracter but when i used <h2></h2> this caracter does not appear on the web-site page.
<h2>Aéroport Tunis Carthage </h2>
on the web-site the text is: Arport Tunis Carthage.
<h2>Aéroport Tunis Carthage</h2> will do it.
Handy info on encoding can be found here and info on html character entities here.
There are two ways for displaying special characters in HTML:
1) Using HTML entities. For example:
Aéroport
2) Encoding the source HTML file appropriately (e.g. using UTF-8) and then indicating such encoding in the HTML head:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h2>Aéroport Tunis Carthage </h2>
</body>
</html>
Of course, you have to use a text editor capable of writing files in the desired encoding. Otherwise you should indicate in the <head> the encoding used by the editor.
Try adding this to your meta tags:
HTML4:
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
HTML5:
<meta charset="UTF-8">
Source:
http://www.w3schools.com/tags/att_meta_http_equiv.asp
EXAMPLE:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Meta Tag -->
<meta charset="UTF-8"> <!-- HTML5 -->
<title> Your title here </title>
</head>
IN HTML5 validator, http://validator.w3.org/
When I tested my page content
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Sports News</title>
<meta name="blogcatalog" content="9BC8949410"/>
</head>
<body class="home">
This is content here.
</body>
</html>
I found an error in line <meta name="blogcatalog" content="9BC8949410"/> .
Line 9, Column 49: Bad value blogcatalog for attribute name on element meta: Keyword blogcatalog is not registered.
If anybody has an idea about it? Is there any replacement of this keyword ?