Welcome to the foundational stone of the internet! HTML, or HyperText Markup Language, is the standard markup language for documents designed to be displayed in a web browser. It defines the structure and content of web pages. Think of it as the skeleton of your website.
Key Takeaway: HTML uses tags to mark up content, telling the browser how to display it.
HTML elements are the building blocks of HTML pages. An HTML element is defined by a start tag. Some elements have a content inside, and some are empty. An element usually consists of a start tag and an end tag. The content goes between the start and end tags.
The basic syntax for an HTML tag is:
<tagname>Content goes here</tagname>
<tagname>
is the name of the tag, enclosed in angle brackets.Content goes here
is the content that will be displayed.</tagname>
is the closing tag, which includes a forward slash before the tag name.Some tags are self-closing (void elements) and don't require an end tag, like <img>
or <br>
.
<!DOCTYPE html>
: Declares the document type and version of HTML.<html>
: The root element of an HTML page.<head>
: Contains meta-information about the HTML document (like title, character set).<title>
: Sets the title for the browser tab or window.<body>
: Contains the visible page content.<h1>
to <h6>
: Define headings, with <h1>
being the largest and most important.<p>
: Defines a paragraph.<a>
: Defines a hyperlink.<img>
: Embeds an image.<ul>
: Defines an unordered list (bullet points).<ol>
: Defines an ordered list (numbered list).<li>
: Defines a list item.<br>
: Inserts a single line break.<hr>
: Inserts a horizontal rule.<div>
: A generic container for flow content. Often used for styling or grouping elements.<span>
: A generic inline container.Attributes provide additional information about HTML elements. They are always specified in the start tag and usually come in name/value pairs like: name="value"
.
The <a>
tag commonly uses the href
attribute to specify the URL of the page the link goes to:
<a href="https://www.example.com">Visit Example.com</a>
href
is the attribute name."https://www.example.com"
is the attribute value.The <img>
tag uses src
for the image source and alt
for alternative text:
<img src="image.jpg" alt="A descriptive image">
Here's a basic example of an HTML page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Web Page</title>
<link rel="stylesheet" href="style.css"> <!-- Link to an external CSS file -->
</head>
<body>
<header>
<h1>Welcome to My Website!</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
</header>
<main>
<article>
<h2>An Interesting Article</h2>
<p>This is the first paragraph of my article. It's exciting to learn HTML!</p>
<img src="article-image.png" alt="An illustrative image">
<p>Here is another paragraph with a <strong>bold</strong> word and an <em>emphasized</em> one.</p>
</article>
</main>
<footer>
<p>© 2023 My Website. All rights reserved.</p>
</footer>
</body>
</html>
This structure is fundamental. As you progress, you'll learn about semantic HTML5 elements like <header>
, <nav>
, <main>
, <article>
, <section>
, and <footer>
, which provide more meaning to your content and improve accessibility and SEO.
HTML provides the structure. To make your web pages visually appealing, you'll need to learn CSS (Cascading Style Sheets). And for interactivity, you'll explore JavaScript.
Keep practicing, and don't hesitate to experiment with different tags and attributes. Happy coding!