A reference tool for learning and understanding the basic structure and elements of HTML.
- Basic Structure of an HTML Document
- HTML Elements
- Common HTML Elements with Examples
- Nesting and Indentation
- HTML Elements with Attributes
- Class and ID Attributes
HTML documents have the following basic structure:
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<p>My first paragraph</p>
</body>
</html>
An HTML element consists of:
- Opening Tag
- Content
- Closing Tag
<p>This is a paragraph</p>
Here are some common HTML elements with code examples and their output.
<p></p>
<p>This is a paragraph.</p>
<h1></h1>
<h3></h3>
<h6></h6>
<h1>Heading level 1</h1>
...
<h6>Heading level 6</h6>
<ol>
<li>George Washington</li>
<li>John Adams</li>
</ol>
<ul>
<li>George Washington</li>
<li>John Adams</li>
</ul>
<br>
<br>
<button></button>
<button>Click Me</button>
<div></div>
<div>This is a div</div>
<input>
<input>
In coding, nesting is when you put one tag completely inside another tag's content. Indentation helps you organize your code and makes it more readable.
<div>
<h1>Weekday</h1>
<p>Monday</p>
</div>
An attribute adds extra information to an HTML element.
<img src="https://imgur/cats.png">
<img alt="dog running" src="https://dogs.com/image.jpg" class="dog-pic">
<a href="https://www.google.com"> This is a link to Google</a>
<a href="https://www.youtube.com" target="_blank">YouTube popout</a>
<link href="https://fonts.googleapis.com/css2?family=Pacifico&display=swap" rel="stylesheet">
h1 { font-family: 'Pacifico', serif; }
<input placeholder="type here">
Details about assigning and selecting classes and IDs.
/* CSS class and id examples */
.my-class { text-align: right; }
#my-id { color: blue; }