HTML基本格式

 

1.現代的HTML5其網頁基本格式已簡化如下
<!DOCTYPE html>
<html>
    <body>
    ...略
    </body>
</html>
主要為開頭宣告為HTML文件的<!DOCTYPE html>與<html>內含<body>階層

 

2.<html>element裡面還可以放<head>element
<!DOCTYPE html>
<html>
<head>
    ...略
</head>
<body>
    <h1>My First Heading</h1>
    <p>My first paragraph.</p>
</body>
</html>
 
3.而<head>裡可以放<title>
<!DOCTYPE html>
<html>
<head>
    <title>Title of the document</title>
</head>
<body>
    The content of the document......
</body>
</html>

 

4.<head>裡可以放<link>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
    <h1>My First Heading</h1>
    <p>My first paragraph.</p>
</body>
</html>

 

5.<head>裡可以放<style>
<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
        body {
            background-color: yellow;
        }
        p {
            color: blue;
        }
    </style>
</head>
<body>
    <h1>My First Heading</h1>
    <p>My first paragraph.</p>
</body>
</html>

 

6.<head>裡可以放<meta>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    <h1>My First Heading</h1>
    <p>My first paragraph.</p>
</body>
</html>