This is a handy collection of common HTML code snippets you can quickly copy and paste into your web pages. These examples cover typical tasks when building or editing a website — such as inserting images, creating links, building lists, tables, forms, and embedding videos.
<body>
section (unless otherwise noted).These snippets are designed for quick prototyping and learning. As you get more comfortable, you can combine and customize them to build more advanced layouts and features.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Title</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
<img src="path/to/image.jpg" alt="Description of image">
<a href="https://example.com">Visit Example</a>
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
<table border="1">
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
</tbody>
</table>
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<input type="submit" value="Submit">
</form>
<iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID"
frameborder="0" allowfullscreen></iframe>
<div style="background-color: lightblue; padding: 10px;">
Styled box
</div>
This is a collection of ready-to-use HTML snippets specifically for the <head>
section of an HTML document. The <head>
contains important information about your web page that helps browsers, search engines, and devices understand how to render and display your content.
You can copy and paste these snippets directly into your <head>
section depending on what you need:
Locate the <head>
section at the top of the file:
<head>
<!-- paste snippets here -->
</head>
<head>
, depending on what features or styles you want to include.<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
console.log('Hello from JavaScript');
</script>
<link rel="stylesheet" href="styles.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
}
</style>
<head>
)<script src="script.js"></script>
defer
(recommended for head)<script src="script.js" defer></script>
defer
ensures the script runs after the HTML is fully parsed.
<script>
console.log('Page Loaded');
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="This is a sample website description for SEO purposes.">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="preload" href="styles.css" as="style">
<link rel="preload" href="fonts/Roboto.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="canonical" href="https://example.com/page-url">