syntax Copy
<!DOCTYPE html>example Copy
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8" >
<title>My Page</title>
</head>
<body>
<h1>Welcome</h1>
</body>
</html>Note Always place this as the very first line. Without it, browsers fall into quirks mode and render inconsistently.
start html html boilerplate new page html template
syntax Copy
<html lang="language-code" > ... </html>example Copy
<html lang="en" dir="ltr" >
<!-- entire document goes here
</html>Note The lang attribute is critical for screen readers and search engines. Use BCP 47 codes like "en", "fr", "es", "zh-Hans".
set language html root page language accessibility language
<head> Metadata Container syntax Copy
<head> ... </head>example Copy
<head>
<meta charset="UTF-8" >
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<title>Product Dashboard</title>
<link rel="stylesheet" href="styles.css" >
</head>Note The head element holds metadata, links to stylesheets, and scripts. Nothing inside head renders visually on the page.
html head add metadata link stylesheet page setup
syntax Copy
<meta charset="UTF-8" >example Copy
<head>
<meta charset="UTF-8" >
</head>Note Must appear within the first 1024 bytes of the document. UTF-8 handles virtually all global characters and emoji.
character encoding utf-8 special characters emoji support
syntax Copy
<meta name="viewport" content="width=device-width, initial-scale=1.0" >example Copy
<meta name="viewport" content="width=device-width, initial-scale=1.0" >Note Without this, mobile browsers render at a desktop width and then shrink the result. Essential for every responsive site.
responsive mobile friendly viewport mobile scaling
syntax Copy
<body> ... </body>example Copy
<body>
<header>Site Header</header>
<main>Primary Content</main>
<footer>Site Footer</footer>
</body>Note Only one body element per document. All visible page content lives here.
page body visible content html body
syntax Copy
<link rel="stylesheet" href="path/to/file.css" >example Copy
<link rel="stylesheet" href="/css/main.css" >
<link rel="stylesheet" href="https://fonts.example.com/sans.css" crossorigin>Note Stylesheets in the head block rendering until they load. For non-critical CSS, consider loading asynchronously.
add css link css file external stylesheet include css
syntax Copy
<script src="file.js" defer></script>
<script type ="module" src="app.js" ></script>example Copy
<script src="analytics.js" defer></script>
<script type ="module" src="app.js" ></script>Note Use defer for classic scripts so they run after HTML parsing completes. Module scripts are deferred by default. Avoid placing scripts in the head without defer or async.
add javascript include script defer script module script