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.
Syntax ⧉ Copy < html lang = "language-code" > ... </ html > Example ⧉ Copy < html lang = "en" dir = "ltr" >
</ 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.
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.
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