In this short tutorial we introduce you to HTML fundamentals. This is good enough to get you started but eventually you will need an advanced course that we provide on our home site. This is a long page so let’s get started.
HTML: HyperText Markup Language, aka the Blueprint for Awesome Websites
Hold your horses, HTML newbies! Before you start constructing digital masterpieces, let’s decode the mysterious acronym and uncover its true nature.
HTML stands for HyperText Markup Language. Sounds fancy, right? But don’t worry, it’s not as complicated as it sounds. Here’s the breakdown:
HyperText: Imagine text that’s hopped up on caffeine and ready to bounce around the internet. Hypertext links content together, allowing you to jump seamlessly from one page to another with a simple click. It’s like a choose-your-own-adventure book for the web!
Markup Language: Think of HTML as the architect’s blueprint for your webpage. It uses a system of tags (like little construction signs) to tell the browser what to display and how to structure it. οΈ
So, is HTML a programming language? Not quite! It doesn’t involve complex logic or calculations like those code wizards in Python or JavaScript. Instead, it focuses on defining the content and structure of webpages β it’s the skeleton that holds everything together.
Think of it this way:
In essence: HTML is the silent hero of the web, working behind the scenes to make sure everything looks and feels organized. It’s the Marie Kondo of the internet, ensuring every element has its rightful place.
Ready to dive into this world of tags and structure? Buckle up, because we’re about to build some epic webpages together!
The Secret Textual Life of Webpages
Think HTML files are some kind of super-secret, high-tech code? Think again! They’re actually just plain ol’ text files, like the ones you might scribble in notepad or create with a fancy word processor.
But here’s the twist:
So, how do you edit these text-based wonders?
Here’s the scoop:
Now, here’s the cool part:
So, grab your trusty text editor, unleash your inner wordsmith, and start crafting those HTML masterpieces! The web is your canvas, and the possibilities are endless!
Welcome to the wonderful world of HTML, where code transforms into stunning webpages! Before we dive headfirst into building our digital masterpieces, let’s crack the code and understand the fundamental building blocks: HTML elements. Think of them as the tiny lego bricks that, when put together, create the vibrant landscapes of the internet.
HTML is all about building structure, and it achieves this through a clever system of nested tags. Think of them as those Russian dolls that fit snugly inside each other, creating a hierarchy of elements.
Here’s the anatomy of a tag:
<p>
for a paragraph, <h1>
for a heading, or <img>
for an image.<img src="cute-cat.jpg" alt="Adorable kitten">
.</p>
, </h1>
, </img>
.Here’s an example of a complex HTML tag with children, showing off their nesting prowess:
<article>
<h2>Welcome to My Awesome Website!</h2>
<p>This is a paragraph full of exciting content.</p>
<img src="party-parrot.gif" alt="Party parrot celebrating HTML skills">
</article>
In this example:
<article>
tag is the parent, containing all the other elements within its cozy embrace.<h2>
, <p>
, and <img>
tags are its children, each contributing their unique content to the overall structure.Key things to remember about tags:
<h1>
is different from <H1>
. Treat those tags like they’re royalty β always use lowercase for their names.So, think of HTML tags as the LEGO bricks of the web. By mastering their structure and nesting, you’ll be building awesome webpages in no time!
Relax, you don’t need to memorize an encyclopedia of HTML tags to create awesome webpages. While HTML boasts a colorful cast of characters, you’ll find that a core group of around 50 commonly used tags will cover most of your web-building needs. Let’s meet some of the key players:
Structural Superstars:
<html>
: The grandmaster of the page, embracing all other elements within its HTML hug.<head>
: The brains of the operation, housing important information for search engines and browsers.<body>
: The visual heart of the page, where all your content and styling magic will unfold.Textual Titans:
<h1>
to <h6>
: Headings that shout out your content’s structure, from the loudest <h1>
to the more subdued <h6>
.<p>
: The humble paragraph, home to your flowing text and captivating stories.Visual Virtuosos:
<img>
: The image maven, showcasing pictures, illustrations, and even dancing GIFs.<video>
: The movie maestro, bringing life to your pages with embedded videos.Linkage Legends:
<a>
: The anchor of the web, creating clickable links that transport users to new destinations.List Leaders:
<ul>
: The unordered list, perfect for bulleted items that need no particular order.<ol>
: The ordered list, ideal for numbered steps or ranking your favorite pizza toppings.Table Titans:
<table>
: The master of organization, presenting data in neat rows and columns.<tr>
: The table row, housing a single line of information within the table.<td>
: The table data cell, holding individual pieces of content within a row.And Many More:
<form>
, <input>
, and <button>
tags.<header>
, <nav>
, <main>
, <article>
, and <footer>
tags.Don’t worry: HTML newbies! We’ll explore each of these tags in detail later, revealing their secrets and unleashing their awesome power. Just remember, you don’t need to learn them all at once. Start with the basics, build your confidence, and expand your HTML vocabulary as you create more web masterpieces!
Let’s revisit some of most important elements in HTML. Any HTML file should contain some of these fundamental elements alongside with other nested elements that form the layout and the content of a static HTML page.
Understanding Element Categories:
Main Content Categories:
Metadata Content:
<title>
, <meta>
, <link>
, <style>
, <script>
Flow Content:
<h1>
to <h6>
, <p>
, <div>
, <img>
, <ul>
, <ol>
, <table>
, <form>
Sectioning Content:
<section>
, <article>
, <nav>
, <aside>
, <header>
, <footer>
Heading Content:
<h1>
to <h6>
Phrasing Content:
<span>
, <em>
, <strong>
, <a>
, <br>
, <img>
Embedded Content:
<img>
, <video>
, <audio>
, <iframe>
, <embed>
Interactive Content:
<button>
, <input>
, <select>
, <textarea>
Additional Categories:
<script>
)<table>
, <tr>
, <td>
)Key Points:
Remember:
To understand better the elements we can look of two types of elements:
Inline Elements:
<span>
, <a>
, <strong>
, <em>
, <img>
, <br>
, <i>
, <b>
, <code>
, <sub>
, <sup>
Block Elements:
<p>
, <h1>
to <h6>
, <div>
, <ul>
, <ol>
, <li>
, <table>
, <form>
, <header>
, <nav>
, <article>
, <section>
, <aside>
, <footer>
Key Differences:
Visualizing It:
Choosing the Right Element:
Additional Notes:
Imagine you’re about to enter a secret club, but first you need to whisper the password to the bouncer. In the world of HTML, that password is the <!DOCTYPE>
declaration. It’s a special code that tells the browser, “Hey, I’m an HTML5 page, and I’m ready to party!”
Here’s how it works:
<!DOCTYPE html>
Think of it like this:
<!DOCTYPE>
declaration is like a quick language lesson for the browser, ensuring everyone’s on the same page (pun intended).So, always remember to include this declaration at the very beginning of your HTML files. It’s a small but essential step that makes sure your webpages start off on the right foot (or should we say, the right click?).
Pro tip:
<!DOCTYPE>
declarations, you can stick with the simple <!DOCTYPE html>
for most modern HTML5 projects.Here’s the scoop on the HTML root element, the grand orchestrator of your web pages:
1. What It Is:
<html>
element is the ultimate parent of all other elements within an HTML document.2. Syntax:
<!DOCTYPE html>
<html>
</html>
3. Attributes:
id
: Assigns a unique identifier for styling or scripting purposes.class
: Assigns one or more classes for styling or grouping elements.style
: Adds inline styling directly to the element.manifest
: Specifies the URL of a web app manifest file (for web applications).4. Key Points:
<html>
element as its root.<head>
(containing metadata) and <body>
(containing the visible content).5. Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Amazing Page</title>
</head>
<body>
</body>
</html>
Remember, the <html>
element is the foundation upon which your entire web page is built. It’s the silent director, ensuring all the elements play their parts in harmony to create a cohesive and engaging digital experience!
The <head>
element is like the backstage crew of your HTML page. It doesn’t show up on the stage (aka, the browser window), but it works tirelessly behind the scenes to set the scene and prepare for a stellar performance.
Here’s a rundown of its most common residents:
1. Title Tag (<title>
):
<title>My Awesome Website</title>
2. Meta Tags (<meta>
):
description
: A brief summary of your page’s content.keywords
: Relevant keywords for search engines (less important nowadays).author
: The page’s author.viewport
: Instructions for how to display the page on different devices.3. Charset (<meta charset>
):
<meta charset="UTF-8">
4. Canonical Link (<link rel="canonical">
):
5. Styling Links (<link rel="stylesheet">
):
6. Favicon (<link rel="icon">
):
7. JavaScript Links (<script>
):
Remember, the <head>
element usually resides within the <html>
element at the very top of your HTML document. It’s where you set the stage for your page’s success, even if it prefers to stay out of the spotlight!
It’s the star of the show, the bustling marketplace, the vibrant canvas where your web page truly comes alive!
Here’s the lowdown on this essential element:
1. What It Is:
<body>
element is the workhorse of your HTML document.2. Content:
<body>
element:
<h1>
to <h6>
)<p>
)<img>
)<a>
)<ul>
and <ol>
)<table>
)3. Attributes:
<body>
can have some helpful attributes:
onload
: Runs JavaScript code once the page finishes loading.onunload
: Runs JavaScript code when the user leaves the page.bgcolor
: Sets the background color of the page (deprecated, use CSS instead).text
: Sets the default text color of the body (deprecated, use CSS instead).4. Examples:
<body>
<h1>Welcome to My Awesome Website!</h1>
<p>This is a paragraph full of exciting content.</p>
<img src="cute-cat.jpg" alt="Adorable kitten">
</body>
5. Key Points:
<body>
element in an HTML document.<html>
element.<body>
element.Semantic HTML, is a way of writing code that makes your web pages more meaningful and accessible. Imagine a book without chapters, headings, or paragraphsβjust a jumble of words. It would be hard to read, right?
Semantic HTML does for web pages what chapters and headings do for books. It organizes content into clear sections, giving each part a specific meaning.
Think of it like this:
Here’s how it works:
<div>
and <span>
, you use tags that describe the content’s role, like:
<header>
for the header section<nav>
for navigation links<main>
for the main content<article>
for individual articles<aside>
for sidebars or related content<footer>
for the footer sectionWhy does this matter?
1. Accessibility:
2. Better Organization:
3. SEO Boost:
4. Future-Proofing:
Remember:
By using semantic HTML, you create web pages that are not only visually appealing but also meaningful, accessible, and well-organized for both humans and machines!
Here’s a comprehensive example of HTML5 syntax that highlights the <head>
, <footer>
, and <aside>
elements, complete with comments and notes for clarity:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"> <title>My Amazing Website</title> <link rel="stylesheet" href="style.css"> </head>
<body>
<header>
<h1>Welcome to My Awesome Website!</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<article>
<h2>Main Article Heading</h2>
<p>This is the main article content.</p>
</article>
<aside>
<h3>Sidebar Widget</h3>
<p>This is a sidebar widget.</p>
</aside>
</main>
<footer>
<p>© 2024 Your Name</p>
</footer>
</body>
</html>
Key Points:
<head>
: Houses metadata and information about the page, not visible to visitors.<footer>
: Defines the bottom section of the page, often containing copyright, credits, and navigation links.<aside>
: Represents a portion of content tangentially related to the main content, often used for sidebars or notes.header
, main
, and footer
to convey meaning and improve accessibility.Remember:
<body>
to make your page visible to visitors.Both section
and article
are semantic elements in HTML5, meaning they convey the meaning and purpose of the content they contain. However, they have distinct differences:
Section:
Article:
Here’s an analogy:
<section>
. Within each section, individual articles (e.g., a specific news story, a movie review, a game recap) are <article>
.Choosing between <section>
and <article>
:
<section>
when grouping related content that forms part of a larger whole and isn’t necessarily standalone.<article>
when showcasing self-contained, independent pieces of content that can be understood on their own.By using the right element, you improve the:
Remember, the key is to choose the element that best reflects the meaning and purpose of your content!
Here’s the scoop on the versatile <div>
element, ready to divide and conquer your web pages:
What It Is:
<header>
or <article>
.Common Use Cases:
Key Points:
<div>
elements for complex layouts.Example:
<div class="header">
<h1>Welcome to My Website!</h1>
</div>
<div class="main-content">
<p>This is the main content area.</p>
</div>
<div class="sidebar">
<h3>Sidebar Links</h3>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
</ul>
</div>
Best Practices:
<div>
primarily for layout and styling when no more suitable element exists.<div>
elements for visual presentation and control layout.Remember, <div>
is a powerful tool for shaping your web pages, but use it with discretion and prioritize semantic elements when they accurately reflect the content’s meaning!
Here’s a breakdown of attributes in HTML, ready to add personality and superpowers to your elements:
What They Are:
<element attribute1="value1" attribute2="value2">
Common Attributes (Global Attributes):
id
: Assigns a unique identifier to an element for styling, targeting, or scripting. (Example: <p id="main-paragraph">
)class
: Assigns one or more classes to an element for styling or grouping. (Example: <div class="container">
)style
: Adds inline styles directly to the element. (Example: <h1 style="color: red;">
)title
: Provides additional information about an element, often displayed as a tooltip. (Example: <img src="image.jpg" title="Description of the image">
)Specific Attributes:
src
for images (<img>
) to specify the image source URL.href
for links (<a>
) to specify the link destination URL.alt
for images (<img>
) to provide alternative text for accessibility and SEO.width
and height
for images (<img>
) to control their dimensions.autoplay
and controls
for videos (<video>
) to manage playback behavior.placeholder
for input fields (<input>
) to display a hint text.Key Points:
Example:
<img src="my-photo.jpg" alt="A photo of me smiling" width="300" height="200">
In this example, the <img>
element has four attributes: src
, alt
, width
, and height
, each providing specific information about the image.
<a>
ReferenceHere’s a comprehensive explanation of URLs, their purpose, anatomy, and how to create links using the <a>
element in HTML:
URLs: Your Digital Addresses
Anatomy of a URL:
protocol://hostname/path/to/resource?query-parameters#fragment
http
, https
, ftp
)www.example.com
)/articles/my-article.html
)?search=keyword
)#section2
)Example:
https://www.nasa.gov/image-feature/nasa-scientists-uncover-surprising-results-about-ocean-worlds-beyond-earth
Creating a Link in HTML:
<a>
Element: The anchor element (<a>
) creates hyperlinks to other web pages or resources.href
Attribute: Specifies the destination URL of the link.HTML Example:
<a href="https://www.nasa.gov/image-feature/nasa-scientists-uncover-surprising-results-about-ocean-worlds-beyond-earth">
Explore Ocean Worlds with NASA
</a>
Special Attributes for the <a>
Element:
target
: Determines how the linked resource opens (e.g., _blank
for a new window).rel
: Specifies the relationship between the current page and the linked resource (e.g., noopener
for security).title
: Provides a tooltip text that appears when hovering over the link.Key Points:
<a>
Anchor IDHere’s an explanation of anchors and references to anchors, along with a clear example:
Anchors: Marking Your Spot
id
attribute to assign unique identifiers to elements.Creating an Anchor:
id
:
<h2 id="my-anchor">This is a section heading</h2>
Referencing an Anchor:
href
attribute with a hash (#
) followed by the anchor’s id
:
<a href="#my-anchor">Jump to Section Heading</a>
Example:
<!DOCTYPE html>
<html>
<body>
<h1>Welcome to my page!</h1>
<p>Some introductory content here.</p>
<a href="#important-section">Click here to jump to the important section</a>
<h2 id="important-section">This is the important section</h2>
<p>This is the content within the important section.</p>
</body>
</html>
How It Works:
h2
element with the id
of “important-section”.Key Points:
id
values for clarity.id
values within a page to avoid conflicts.Additional Notes:
id
(e.g., href="https://example.com/other-page#anchor-id"
).<hr>
ElementHere’s an explanation of the <hr>
element and self-closing elements in HTML:
The <hr>
Element:
Example:
<p>This is the first section of content.</p>
<hr>
<p>This is the second section of content, visually separated from the first.</p>
Self-Closing Elements:
/
) before the closing angle bracket: <element_name />
<img src="image.jpg" alt="Description" />
<br />
(line break)<hr />
<input type="text" name="username" />
<meta name="description" content="Page description" />
<link rel="stylesheet" href="style.css" />
Key Points:
Additional Notes:
<hr>
is self-closing in HTML5, it’s acceptable to write it as <hr>
or <hr/>
for compatibility with older browsers.Here’s an explanation of custom attributes in HTML5, unlocking extra data storage and functionality:
What are Custom Attributes?
Syntax:
data-
, followed by a custom name (lowercase and hyphenated): <element data-custom-attribute="value">
Examples:
<div data-product-id="12345" data-price="$9.99">Product Details</div>
<button data-toggle="modal" data-target="#myModal">Open Modal</button>
<img src="image.jpg" data-caption="Beautiful Sunset" data-alt="Sunset on the beach">
Common Uses:
Key Points:
Remember:
Here’s an explanation of the HTML table element and its subelements, along with an example and its Markdown rendering:
HTML Table Element (<table>
):
Subelements:
<thead>
: Encloses the table header, typically containing column headings.<tbody>
: Encloses the table body, containing the main data rows.<tfoot>
: Encloses the table footer, often used for summary information or additional notes.<tr>
: Defines a table row, containing one or more cells.<th>
: Defines a table header cell (usually bold and centered).<td>
: Defines a table data cell.Example HTML:
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>30</td>
<td>New York</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>25</td>
<td>London</td>
</tr>
</tbody>
</table>
Rendered as Markdown Table:
Name | Age | City |
---|---|---|
John Doe | 30 | New York |
Jane Smith | 25 | London |
Key Points:
<caption>
to provide a table title or summary.scope
attributes for header cells to clarify relationships in complex tables.colspan
and rowspan
attributes for spanning cells across multiple rows or columns.Remember:
Lists organize items in a clear and structured way, making content easier to read and navigate.
Types of Lists:
<ul>
):
<ol>
):
Structure:
<ul>
or <ol>
).<li>
): Enclose individual items within the list.</ul>
or </ol>
).Example:
<ul>
<li>Grocery list:</li>
<li>Milk</li>
<li>Eggs</li>
<li>Bread</li>
</ul>
<ol>
<li>Steps to make a cake:</li>
<li>Preheat the oven.</li>
<li>Mix the ingredients.</li>
<li>Bake the cake.</li>
</ol>
Key Points:
<dl>
(definition list) for terms and definitions.Best Practices:
Remember:
Here are some interactive content elements that align with your interest in items with details and dropdowns, along with a few others that expand the scope:
Elements for Expanding/Collapsing Content:
<details>
and <summary>
):
Dropdowns and Menus:
<select>
):
<ul>
or <div>
with CSS/JavaScript):
Other Interactive Elements:
Remember:
This introduction to HTML is designed to provide a foundational understanding of key concepts and elements. It’s not intended as a comprehensive replacement for official reference manuals and specifications.
For in-depth exploration and detailed information, please refer to the following resources:
W3C HTML Validator:
How to Use It:
Remember:
You god this. Good luck! π
“The Web is the first thing that is truly global and that links cultures like nothing before.” - Tim Berners-Lee, inventor of the World Wide Web (WWW)